Temzasse / react-modal-sheet

Flexible bottom sheet component built with Framer Motion to provide buttery smooth UX while keeping accessibility in mind 🪐
https://temzasse.github.io/react-modal-sheet/
MIT License
828 stars 78 forks source link

How to get y value of sheet on drag #81

Closed bennettl closed 2 years ago

bennettl commented 2 years ago

Is it possible to invoke a function as the user drags the modal to get the y position of the sheet? Readme mentions using refs, but unclear on how to go about getting the latest values. I tried the following

const ref = useRef();

useEffect(() => {
// Use the latest y value
},[ref.current.y] ]

<Sheet ref={ref}> ... </Sheet>
Temzasse commented 2 years ago

The y value is a MotionValue and its value is updated outside of React so you need to subscribe to the value changes via y.onChange.