Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not rebind when domTarget changes #17

Open
Sovai opened this issue Jun 9, 2022 · 4 comments
Open

does not rebind when domTarget changes #17

Sovai opened this issue Jun 9, 2022 · 4 comments

Comments

@Sovai
Copy link

Sovai commented Jun 9, 2022

I use if/else on the domTarget and when it toggled, the gesture event stopped working. Is there a way to make it reactive? I try to call useGesture() again in watcher but it still does not solve my issue

@lnvglr
Copy link

lnvglr commented Dec 6, 2022

I have the same problem, is there any progress on this?

@slavarazum
Copy link

An error occurs when a component is mounted after the component initialization:

Error: domTarget must be defined

Using with onMounted() hook doesn't help.

onMounted(() => {
    useDrag(dragHandler, {
      domTarget: dragEl,
    });
});

@chenweifang4
Copy link

You may need to rebind when the component is visible, the following code works fine on my side.

const { motionProperties } = useMotionProperties(container, {
  scale: 1,
  rotateX: 0,
  rotateY: 0,
  rotateZ: 0,
  x: 0,
  y: 0,
});

const { set, stop } = useSpring(motionProperties as Partial<PermissiveMotionProperties>);

const dragHandler = (options: CommonGestureState) => {
  const [x, y] = options.offset;
  if (x === 0 && y === 0) {
    return;
  }
  set({
    x,
    y,
  });
};

watch(
  () => is_visible,
  () => {
    nextTick(() => {
      const { bind, clean } = useDrag(dragHandler, {
        domTarget: container,
      });
      if (is_visible.value) {
        bind();
      } else {
        clean();
        stop();
      }
    });
  },
  {
    deep: true,
  }
);

@mcmimik
Copy link

mcmimik commented Mar 14, 2024

This issue seems to be quite prevalent and, unfortunately, it significantly blocks using the library in real life.

For those considering contributing with a PR, the problematic area can be found here: Controller.ts.

As a point of reference, Floating UI addresses a similar challenge gracefully using watchers. You can see their approach here: Floating UI :: useFloating, where they utilize:

watch([referenceElement, floatingElement], attach, {flush: 'sync'});

Hope, this might offer some inspiration for a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants