react-native-scroll-bottom-sheet
react-native-scroll-bottom-sheet copied to clipboard
snapTo() not working with RN 0.63
Current Behavior
I just upgraded my project from RN 0.62.2 to 0.63 and I noticed the snapTo function appears to not be working. The code below worked fine on 0.62.2 (and the console.log shows up in 0.63, so the useEffect() is running..)
const bottomSheetRef = useRef();
// Close the bottom sheet
useEffect(() => {
if (!bottomSheetIsOpen) {
console.log('closing BS!');
bottomSheetRef.current.snapTo(1);
}
}, [bottomSheetIsOpen]);
Expected Behavior
The bottom sheet should snap to provided index
Your Environment
package | version |
---|---|
react-native-scroll-bottom-sheet | 0.6.2 |
react-native | 0.63.0 |
react-native-gesture-handler | 1.6.1 |
react-native-reanimated | 1.9.0 |
I got it working by wrapping it into a small timeout
I think the issue is not the snapTo
itself, but rather something to do with component being re-rendered. If you called snapTo
from some button directly (and not listening to state changes, which cause re-render), it would work.