react-native-bottom-sheet: [v4] Bottom sheet is not dismissed if `dismiss` is called soon after `present`
Bug
The bottom-sheet is not dismissed when dismiss() is called soon after present(). This happens when these two are called in quick succession. The code in the example demonstrates the issue and here’s also a short video of that code in action.
https://github.com/user-attachments/assets/18991be9-47e5-4278-a900-2603d82605a9
Environment info
| Library | Version |
|---|---|
| @gorhom/bottom-sheet | 4.6.4 |
| react-native | 0.74.5 |
| react-native-reanimated | 3.10.1 |
| react-native-gesture-handler | 2.16.2 |
Steps To Reproduce
- Install app:
npm install - Run the app:
npx expo start - Press twice on the button in quick succession
- Observe the bottom sheet remain open, when it should be dismissed
Describe what you expected to happen:
- After double press, the sheet should be dismissed.
Reproducible sample code
import React, { useMemo, useState, useEffect } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { BottomSheetModal, BottomSheetModalProvider } from '@gorhom/bottom-sheet';
export default function App() {
const [isOpen, setIsOpen] = useState(false);
const ref = React.useRef<BottomSheetModal>(null);
const snapPoints = useMemo(() => ['25%', '50%'], []);
useEffect(() => {
if (isOpen) {
ref.current?.present();
} else {
ref.current?.dismiss();
}
}, [isOpen]);
const toggleSheet = () => {
setIsOpen(prevState => !prevState);
};
return (
<GestureHandlerRootView style={styles.container}>
<BottomSheetModalProvider>
<View style={styles.container}>
<Button
title={isOpen ? "Close Sheet" : "Open Sheet"}
onPress={toggleSheet}
/>
<BottomSheetModal
ref={ref}
index={1}
snapPoints={snapPoints}
enablePanDownToClose={true}
onDismiss={() => setIsOpen(false)}
>
<View style={styles.contentContainer}>
<Text>Bottom Sheet Modal Content</Text>
</View>
</BottomSheetModal>
</View>
</BottomSheetModalProvider>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 24,
backgroundColor: 'black',
},
contentContainer: {
flex: 1,
alignItems: 'center',
},
});
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 15 (4 by maintainers)
Commits related to this issue
- fix: updated animation sequencing to respect force closing by user (#1941) — committed to gorhom/react-native-bottom-sheet by gorhom 2 years ago
This problem seems to be exacerbated when you are in Reduce Motion mode. @gorhom Could you please be more specific about which version this will be fixed in, as it affects us? I can still reproduce it in v5.0.6
same problem here
@celian-riboulet may i know why are you mounting and unmounting the bottom sheet modals? this is causing an internal issue and might take me time to fix it.
You could resolve issue simply by remove this logic
https://github.com/user-attachments/assets/59c06f92-0507-423b-a5eb-6ba95a6ffb31
The initial reproducible example seems to be fixed (I tested in 5.1.0). But in fact when multiple bottom sheet modals are getting stacked / mounted / unmounted in quick succession, they get stacked together (cf: video)
https://github.com/user-attachments/assets/f49ecb63-1c26-45cf-be6b-9897513f801e
Here is the code from the video:
EDIT My mistake was to render the bottom sheet conditionally. Probably, that caused the dismiss to not work properly.
Also, I had another situation where a dismiss / dismissAll would not work when a faulty bottom sheet was rendered inside the bottom sheet that I wanted to dismiss.
– Dismiss / dismissAll also don’t work when a modal is opened within another modal. Example: The issue exists for all stack behaviours.
Example: