Hi, I have been struggling with some problem.
I have an idea of taking "block" and drag it to other place, but with possibility to undo this action and revert the action (confirmed on modal). Unfortunately block does not move until I force change on transform prop by changing state of some value.
Code for calling undo action
undoDragging = () => {
// This forces re-render and not denies queued animations.
this.setState(
({ verticalScrollOffset }) => ({
animating: true,
verticalScrollOffset: verticalScrollOffset ? 0 : 1,
}),
() => {
timing(this.Y, timingAnimationConfig(500, 0)).start();
timing(this.X, timingAnimationConfig(500, 0)).start();
},
);
};
<Animated.View
style={[
{
transform: [
{ translateY: verticalScrollOffset },
{ translateY: this.Y },
{ translateX: this.X },
],
},
]}
>
Unless I do not call this setState for changing verticalScrollOffset Block will never move.
Another problem is that block sometimes is going back in one direction or another :D and it's really annoying :D

P.S. Without changing verticalScrollOffset on setState block will never move. Of course moving block is implemented in PanGestureHandler
```js
this.panHandler = event([
{
nativeEvent: ({ translationX: x, translationY: y, state, absoluteX, absoluteY }) =>
animationBlock([
condition(eq(state, GestureState.ACTIVE), [
set(this.X, multiply(round(divide(add(x, this.offsetX), columnWidth)), columnWidth)),
set(this.Y, add(y, this.offsetY)),
]),
]),
},
]);
Hi, @dsznajder
I'll try to focus on this case. Could you please attach some compilable code? It would be quite easier for me to repro this case if I could simply copy and paste some snack.
@osdnk Yeah sure, I will try to prepare some more useful snippets :)
@osdnk Here you have snack demo: https://snack.expo.io/ByfLIepJ4
If you first setState here:
undoDragging = () => {
// This forces rerender and not denies queued animations.
this.setState(
({ verticalScrollOffset }) => ({ animating: true, verticalScrollOffset: verticalScrollOffset ? 0 : 1 }),
() => {
timing(this.opacity, timingAnimationConfig(250, 1)).start();
timing(this.Y, timingAnimationConfig(300, 0)).start(() => {
setTimeout(() => {
this.blockContainer.setNativeProps({ style: { borderLeftColor: "green" } });
this.setState({ animating: false });
}, 300);
});
timing(this.X, timingAnimationConfig(300, 0)).start();
},
);
};
The block stops animating back :) I hope this helps.
P.S. Android and iOS works differently, sometimes iOS works but Android don't.
@dsznajder
I'va handled to fix your case. I'm extremely thankful to you since your issue have realised me that maybe not everything in reanimated is very clear and understandable.
So firstly let you see the code: https://gist.github.com/osdnk/4a5b3d2237c4c4558c8d3280a50eb118
Maybe not everything is clear so I hasten to explain:
The first problem is this.panHandler function. To understand it properly please realised it's not a real function but set of animated values which are being updating. So if you call this method only onGestureEvent the state will always be active. Why is it a problem? If we update something in block which is result of the function, the whole block is being reevaluated and it might provide to unwanted effects (e.g. your timing animation was probably working withouts forcing update, but it was immediately overriding by setters from onGestureEvent 馃槄 ). So I merged onHandlerStateChange with onGestureEvent and it appears to work.
@osdnk Thank you very much, I can close this issue now as everything works perfectly.
I think it can be closed for now as it was not related to the package, but I maybe someone will need an explanation, will have an answer here.
Most helpful comment
@dsznajder
I'va handled to fix your case. I'm extremely thankful to you since your issue have realised me that maybe not everything in reanimated is very clear and understandable.
So firstly let you see the code: https://gist.github.com/osdnk/4a5b3d2237c4c4558c8d3280a50eb118
Maybe not everything is clear so I hasten to explain:
The first problem is
this.panHandlerfunction. To understand it properly please realised it's not a real function but set of animated values which are being updating. So if you call this method onlyonGestureEventthe state will always be active. Why is it a problem? If we update something inblockwhich is result of the function, the whole block is being reevaluated and it might provide to unwanted effects (e.g. your timing animation was probably working withouts forcing update, but it was immediately overriding by setters fromonGestureEvent馃槄 ). So I mergedonHandlerStateChangewithonGestureEventand it appears to work.