Cannot programmatically `dismiss` BottomSheetModal as it keeps reopening
See original GitHub issueBug
Hi, first of all, thanks for the great lib!
I’m trying to upgrade the lib from 1.4.1 to 2.0.3, and having trouble. It works well for the most part, except when I try to call ref.current?.dismiss()
to programmatically dismiss the modal.
I’ve made a simple custom hook and am using it.
import { useRef, useCallback } from 'react';
import { BottomSheetModal } from '@gorhom/bottom-sheet';
export function useBottomSheetRef() {
const ref = useRef<BottomSheetModal>(null);
const handlePresent = useCallback(() => {
ref.current?.present();
}, []);
const handleDismiss = useCallback(() => {
ref.current?.dismiss();
}, []);
return [ref, handlePresent, handleDismiss] as const;
}
If I pass the ref
to bottom sheet try to dismiss the modal by either clicking the backdrop or scrolling the handle down, it works as expected. However, when I call handleDismiss
, It seems like the modal immediately re-opens. For below example, I’m calling handleDismiss
on item press:
I’ve already made sure that handlePresent
is not being called somewhere else. I think I’m not doing anything fancy here so it’s bit hard to provide anymore useful info, but If there’s anything you need, please let me know!
Environment info
Library | Version |
---|---|
@gorhom/bottom-sheet | 2.0.3 |
react-native | 0.63.3 |
react-native-reanimated | 1.13.1 |
react-native-gesture-handler | 1.8.0 |
Steps To Reproduce
- present a modal
- try calling
ref.current?.dismiss()
Describe what you expected to happen:
- modal closes without re-opening
Reproducible sample code
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top GitHub Comments
I facing the same issue 😃 try to put
handleDismiss()
in setTimeout callback and will work well with you, something like thissetTimeout(() => handleDismiss(), 0);
@gorhom that’s what I told u in Discord 😉
I’ve created a new issue with repro ( #204 )