panzoom icon indicating copy to clipboard operation
panzoom copied to clipboard

onTouch to have behavior like beforeMouseDown

Open exrhizo opened this issue 4 years ago • 6 comments

Hi,

I am using beforeMouseDown bypass panzoom when dragging an element, I want to be able to have the same behavior in onTouch.

Currently:

function onMouseDown(e) {
  // if client does not want to handle this event - just ignore the call
  if (beforeMouseDown(e)) return;

Could something similar be done for onTouch?

function onTouch(e) {
    // let the override the touch behavior
    beforeTouch(e);

It is possible to have not just event propogation, but selective disabling of the gesture?

Thank you for the code, I'm forking something here to cover my use case :)

This seems related to: https://github.com/anvaka/panzoom/issues/12

The semantics of beforeMouseDown and beforeTouch are different, I can imagine that changing this could be breaking, otherwise I would create a pull request

exrhizo avatar May 14 '20 04:05 exrhizo

a huge +1

@exrhizo did you find a solution?

BernhardBaumrock avatar May 25 '23 08:05 BernhardBaumrock

Ha, I looked into the code and found a solution!

Simply add event listeners to the DOM element where you use PanZoom and trigger .pause() on your desired condition on touchstart and then .resume() PanZoom on touchend:

  let $page = document.getElementById("mp-sheet");

  $page.addEventListener("touchstart", (e) => {
    if (e.target.closest(".block")) PanZoom.pause();
  });
  $page.addEventListener("touchend", (e) => {
    PanZoom.resume();
  });

  PanZoom = panzoom($page, { ... });

BernhardBaumrock avatar May 25 '23 09:05 BernhardBaumrock

@BernhardBaumrock THANK YOU!!! I almost gave up on using this library because I couldn't figure out how to stop touch-based panning.

joodaloop avatar Nov 05 '23 13:11 joodaloop

Is there a way to modify this so it only pauses panning, but still allows zoom?

lindsayweb avatar Nov 16 '23 22:11 lindsayweb

@stealsocks is your case similar to what @lindsaywebstudio was asking? How did you do it?

anvaka avatar Nov 18 '23 04:11 anvaka

@anvaka Bernhard Baumrock's solution doesn't work well with Angular Cdk Drag and Drop https://github.com/anvaka/panzoom/issues/306

can you help?

a1rat91 avatar Mar 06 '24 16:03 a1rat91