question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot programmatically `dismiss` BottomSheetModal as it keeps reopening

See original GitHub issue

Bug

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:

reopens

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

  1. present a modal
  2. try calling ref.current?.dismiss()

Describe what you expected to happen:

  1. modal closes without re-opening

Reproducible sample code

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
anastelycommented, Jan 14, 2021

I facing the same issue 😃 try to put handleDismiss() in setTimeout callback and will work well with you, something like this setTimeout(() => handleDismiss(), 0);

@gorhom that’s what I told u in Discord 😉

0reactions
heejongahncommented, Jan 16, 2021

I’ve created a new issue with repro ( #204 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Close modal bottom sheet programmatically in flutter
Following a code snippet for better understanding. The problem is that the ModalBottomSheet isn't closing when tapping on "Item 1" or "Item 2"....
Read more >
Sheets: bottom - Material Design
Modal bottom sheets are an alternative to inline menus or simple dialogs on mobile and provide room for additional items, longer descriptions, and...
Read more >
5 Examples of the new Ionic 6 Bottom Sheet Modal
Get the details on how to use the brand new Ionic Bottom Sheet component in this guest blog post from Simon Grimm.
Read more >
ion-modal: Ionic Mobile App Custom Modal API Component
ion-modal is a dialog that appears on top of mobile app content, and must be dismissed before interaction resumes. Learn more about custom...
Read more >
How to present a Bottom Sheet in iOS 15 with ... - Sarunw
As screen size keeps increasing year over year, this UI component becomes ... to dismiss to ensure the modal is always there at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found