can-it-be-done-in-react-native icon indicating copy to clipboard operation
can-it-be-done-in-react-native copied to clipboard

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

Open msageryd opened this issue 2 years ago • 2 comments

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,
      );
    });

msageryd avatar Oct 05 '22 18:10 msageryd

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.

wcandillon avatar Oct 28 '22 08:10 wcandillon

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

msageryd avatar Oct 28 '22 08:10 msageryd