How can I change shouldReverse value at onDragRelease?
First of all, thank you very much for your library.
I'm developing an app of drag & drop exercises. So, when the answer is correct, the item should drop. But when it's wrong, it should go back to it's original position. I tried changing the value of shouldReverse in a state variable, but (for a correct answer) it goes back, change that shouldReverse value and then, at the second time, it would be dropped.
There is some way to do this? If it's correct => drop the item at that position If not => go back to the original position
Best regards!
Please see:
https://github.com/tongyy/react-native-draggable/issues/41#issuecomment-789320290
There's a bug with the prop onReverse. This prop should allow you to specify a callback function where you can set your own X and Y positions.
The link above has a quick fix for it.
Please see:
There's a bug with the prop
onReverse. This prop should allow you to specify a callback function where you can set your own X and Y positions.The link above has a quick fix for it.
Thank you for your answer.
I think my problem is different. I need to modify the shouldReverse variable BEFORE release. I mean, I check if the answer is correct, and then, I modify the shouldReverse to make the object stay there if it's correct, or reverse if it's wrong. The problem is that I modify it on with an state variable, and it calls the onReverse before I can modify the shouldReverse. And I can't pass this variable to should reverse, I don't know how to do it.
Regards!
function onPanResponderRelease on Draggable.tsx, you can add a callback function reversePosition() for onRelease(), and check if the answer is incorrect->call reversePosition() and vice versa
const onPanResponderRelease = React.useCallback(
(e, gestureState) => {
isDragging.current = false;
if (onDragRelease) {
onDragRelease(e, gestureState, getBounds());
onRelease(e, true, newPosition.current, reversePosition); // add callback function here
}
if (!shouldReverse) {
pan.current.flattenOffset();
} else {
reversePosition();
}
},
[onDragRelease, shouldReverse, onRelease, reversePosition, getBounds],
);