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

How to use withDecay in the matrix version of GestureHandler in sticker-app #174

Open
msageryd opened this issue Oct 5, 2022 · 2 comments

Comments

@msageryd
Copy link

msageryd commented Oct 5, 2022

I'm trying to figure out how to use withDecay efter translating the picture element in sticker-app. Skia, reanimated and gesture-handler are really cool, but I feel like a newbie trying to grasp it.

This is my, clearly wrong attempt:

  const pan = Gesture.Pan()
    .onChange(e => {
      matrix.value = multiply4(
        Matrix4.translate(e.changeX, e.changeY, 0),
        matrix.value,
      );
    })
    .onEnd(({velocityX, velocityY}) => {
      matrix.value = multiply4(
        Matrix4.translate(
          withDecay({velocity: velocityX}),
          withDecay({velocity: velocityY}),
          0,
        ),
        matrix.value,
      );
    });
@wcandillon
Copy link
Owner

the problem here is the withDecay returns an animation value (it auto update). So the idea would be to do trX.value = withDecay(), same of y and then use useDerivedValue to get the total Matrix4. I hope this helps.

@msageryd
Copy link
Author

Thanks, that make sense.
I'll try it.

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

2 participants