Skip to content
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

Open
DavidStryfe opened this issue Mar 1, 2021 · 3 comments
Open

How can I change shouldReverse value at onDragRelease? #83

DavidStryfe opened this issue Mar 1, 2021 · 3 comments

Comments

@DavidStryfe
Copy link

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!

@OverStruck
Copy link

Please see:

#41 (comment)

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.

@DavidStryfe
Copy link
Author

Please see:

#41 (comment)

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!

@tungnguyenit0201
Copy link

tungnguyenit0201 commented Jun 30, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants