Skip to content

Conversation

ChrisGatzo
Copy link

Similarly to touchstarted we want to have the ability to apply a filter to touchmove events. This way we can programmatically allow developers to filter touchmove events instead of allowing all. This implementation is similar to touchstarted. This resolves #124.

@magicsunday
Copy link

@mbostock Could you please take a look at this? Its works for me too.

magicsunday added a commit to magicsunday/webtrees-fan-chart that referenced this pull request Feb 20, 2018
@valgussev
Copy link

PR looks great and fixes the issue. Are there any known downsides?

@jasonleibowitz
Copy link

I've been waiting on this. Let's get it merged in 🔥

@whoisjordangarcia
Copy link

amazing!

@jurecka
Copy link

jurecka commented Jun 13, 2018

Any plan to merging this fix to master? It would be better to fix touchended function too.
https://github.com/jurecka/d3-zoom/commit/e4ee7bfe18ea7c1a9c7877ed34dc504f601259af

@magicsunday
Copy link

@mbostock Any chance to get this merged sometimes?

@mariechatfield
Copy link

I'd love to see this PR merged! In the meantime, here's a workaround I've written in our app code that manually calls the filter method:

const D3_TOUCH_PATCH_EVENTS = [
  "touchmove.zoom",
  "touchend.zoom touchcancel.zoom"
];

const _patchD3ZoomTouchEvents = ({ filter, selection }) => {
  D3_TOUCH_PATCH_EVENTS.map((eventName) => {
    const originalHandler = selection.on(eventName);

    if (!originalHandler) {
      return;
    }

    selection.on(eventName, () => {
      // Prevent original d3-zoom handler from calling if this event
      // *should* be filtered out. This is a bug in d3-zoom!
      // See https://github.com/d3/d3-zoom/pull/125
      if (!filter()) {
        return;
      }

      originalHandler.apply(d3.event.currentTarget, arguments);
    });
  });
};

const filter = () => { /* filter logic here */ };
const handleZoom = () => { /* zoom logic here */ };

const selection = d3.select("#myCoolElement");

const zoom = d3
  .zoom()
  .filter(filter)
  .on("zoom", handleZoom);

selection.call(zoom);

_patchD3ZoomTouchEvents({ filter, selection });

@mbostock
Copy link
Member

Closing in favor of #169 as discussed in #124 (comment).

@mbostock mbostock closed this Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Touch move not triggering filter
8 participants