Recreate event listener functions on preventSwipe change#31
Open
benkaiser wants to merge 2 commits into
Open
Conversation
benkaiser
commented
Dec 16, 2020
| element.current.removeEventListener(('mouseup'), mouseUp) | ||
| element.current.removeEventListener(('mouseleave'), mouseLeave) | ||
| } | ||
| }, [preventSwipe]) |
Author
There was a problem hiding this comment.
@3DJakob should we add all of the props to this dependency list so they reference the latest handleSwipeReleased in the event listeners? I think this bug extends to the other props but I'm only changing preventSwipe (hence why I noticed the issue)
benkaiser
commented
Dec 16, 2020
| let speed = { x: 0, y: 0 } | ||
| let lastLocation = { x: 0, y: 0, time: new Date().getTime() } | ||
| let mouseIsClicked = false | ||
| const [offset, setOffset] = React.useState({ x: null, y: null }) |
Author
There was a problem hiding this comment.
@3DJakob needed to move these to state, since they would get 'reset' every time useLayoutEffect was called. So if it got called on an element you were mid-way through dragging then the element would jump to the wrong position.
Author
There was a problem hiding this comment.
(I'm open to better options that don't require re-calling useLayoutEffect many times)
blesson3
added a commit
to nsleche/react-tinder-card
that referenced
this pull request
Apr 29, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To ensure that changing preventSwipe prop in subsequent renders behaves correctly, we need to re-generate the event listeners so they use the latest
handleSwipeReleasedcallback.