[v2] BottomSheetModal close function has inconsistent behavior when snap points array is hard coded
Bug
When snapPoints is provided to BottomSheetModal component as props with a constant close function will always close BottomSheetModal.
const snapPoints = [300, 500];
const MyWorkingComponent = () => {
return (
<BottomSheetModal
snapPoints={snapPoints}
ref={bottomSheetModalRef}
dismissOnPanDown={false}
backdropComponent={renderBackdrop}
>
<Button onPress={()=>{bottomSheetModalRef.current?.close()}} >Close Modal</Button>
</BottomSheetModal>
);
}
However when snapPoints is provided as an hard coded array, close function doesn’t work around 50% of the time.
const MyRandomComponent = () => {
return (
<BottomSheetModal
snapPoints={[300, 500]}
ref={bottomSheetModalRef}
dismissOnPanDown={false}
backdropComponent={renderBackdrop}
>
<Button onPress={()=>{bottomSheetModalRef.current?.close()}} >Close Modal</Button>
</BottomSheetModal>
);
}
Environment info
| Library | Version |
|---|---|
| @gorhom/bottom-sheet | ^2 |
| react-native | 0.65.0 |
| react-native-reanimated | 1.13.0 |
| react-native-gesture-handler | 1.10.3 |
Steps To Reproduce
- Create component with hard coded spanPoints
- Display component at application mount
- Try to close BottomSheetModal with close button.
- Kill app if bug doesn’t occur and try again (it will occur after 3 or 4 tries)
Describe what you expected to happen:
- BottomSheetModal closes each time I call close function.
Reproducible sample code
const MyRandomComponent = () => {
return (
<BottomSheetModal
snapPoints={[300, 500]}
ref={bottomSheetModalRef}
dismissOnPanDown={false}
backdropComponent={renderBackdrop}
>
<Button onPress={()=>{bottomSheetModalRef.current?.close()}} >Close Modal</Button>
</BottomSheetModal>
);
}
With BottomSheetModal
Use bottomSheetModalRef.current?.dismiss()
Instead of bottomSheetModalRef.current?.close()
This is working for me like a charm.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.