-
Notifications
You must be signed in to change notification settings - Fork 90
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 can I change shouldReverse value at onDragRelease? #83
Comments
Please see: There's a bug with the prop 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. 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],
); |
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!
The text was updated successfully, but these errors were encountered: