diffClamp on v2
#1573
-
I'm translating a
and I'm using it inside the It works but I can't figure it out the way to store the diff and subtract it on the next const gestureHandler = useAnimatedGestureHandler<
PanGestureHandlerGestureEvent,
{ startY: number }
>({
onStart: (_, ctx) => {
ctx.startY = y.value;
},
onActive: (event, ctx) => {
// TODO diffClamp
const value = ctx.startY + event.translationY;
const clampedValue = clamp(value, -headerHeight, 0);
y.value = clampedValue;
},
}); |
Beta Was this translation helpful? Give feedback.
Answered by
neiker
Jan 1, 2021
Replies: 1 comment
-
I solved this by storing the previous value of translationY: const gestureHandler = useAnimatedGestureHandler<
PanGestureHandlerGestureEvent,
{ prevY: number }
>({
onStart: (_, ctx) => {
ctx.prevY = 0;
},
onActive: (event, ctx) => {
const diff = event.translationY - ctx.prevY;
y.value = clamp(
y.value + diff,
-headerHeight,
0
);
ctx.prevY = event.translationY;
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jakub-gonet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I solved this by storing the previous value of translationY: