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
791 stars 75 forks source link

How to get current active snap? #50

Closed nickbyte closed 1 year ago

nickbyte commented 2 years ago

I am trying to adjust the wrapping container height based on which is the active current point, onSnap, returns negative values. So hard to identify which is the active snap

Guiw5 commented 2 years ago

you have this handler on props

onSnap={snapIndex => console.log('> Current snap point index:', snapIndex) } is the index from snapPoints array

snapPoints={[600, 400, 100, 0]}
initialSnap={1}
Temzasse commented 2 years ago

@nickbyte can you provide a repro of this issue in CodeSandbox? Or did you figure it out?

Your problem might be related to you changing the container height which will probably mess with the snap point calculations within the library 🤔

slellampati commented 2 years ago

I have the same problem. It gives a valid snapoint index on load but after dragging, it always gives -1.

Guiw5 commented 2 years ago

@Temzasse I found the issue: I was using your example from https://github.com/Temzasse/react-modal-sheet/blob/master/example/components/SnapPoints.tsx but if you change the snapPoints all to percentages like: const snapPoints = [0.9, 0.6, 0.3, 0];

And just appear when dragging in responsive view codesandbox

AbBiz21 commented 1 year ago

I am having the same problem, I used the following props <Sheet snapPoints={[0.925, 0.53, 0.19]} initialSnap={2} onSnap={(snapIndex) => { console.log(snapIndex); }} .../>

but it is giving the actual snap index on load only. Otherwise, it returns -1. is there any way I can get the current snap index?

Temzasse commented 1 year ago

Thanks for reporting this 🙏🏻 This should be fixed in version 1.6.1 🙂