Skip to content

Conversation

benkaiser
Copy link

To ensure that changing preventSwipe prop in subsequent renders behaves correctly, we need to re-generate the event listeners so they use the latest handleSwipeReleased callback.

index.js Outdated
element.current.removeEventListener(('mouseup'), mouseUp)
element.current.removeEventListener(('mouseleave'), mouseLeave)
}
}, [preventSwipe])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)

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 })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm open to better options that don't require re-calling useLayoutEffect many times)

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

Successfully merging this pull request may close these issues.

1 participant