[v4] BottomSheetModal in react navigation modal

See original GitHub issue

Bug

The sheet is placed behind the @react-navigation/native modal.

Environment info

Library Version
@gorhom/bottom-sheet 4.1.5
react-native 0.67.2
react-native-reanimated 2.3.1
react-native-gesture-handler 2.2.0

Steps To Reproduce

  1. Create a NativeStack
  2. Place the BottomSheetModalProvider like this:
<NavigationContainer>
  <BottomSheetModalProvider>
    <StackNavigator />
  </BottomSheetModalProvider>
</NavigationContainer>
  1. Use the <BottomSheetModal> in a screen with presentation: "modal".

Describe what you expected to happen:

The sheet is placed behind the modal. I expect the sheet to be in front of the modal that hosts the sheet. I’ve also tried wrapping the modal-component with the provider, but then I get 'BottomSheetModalInternalContext' cannot be null!.

Reproducible sample code

The snack template throws an error: Cannot convert undefined or null to object

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:15

github_iconTop GitHub Comments

4reactions
wbercxcommented, Aug 9, 2022

Adding a <PortalProvider> to the root of my app seemed to interfere with the <BottomSheetModalProvider> that was already there (which already uses PortalProvider under the hood). Only every other bottom sheet I opened would become visible.

I got mine working simply by wrapping my react-navigation modal screen’s contents in a <BottomSheetModalProvider>:

function AppStack() {
    return (
        <NativeStack.Navigator>
            {/* ... */}
            <NativeStack.Group screenOptions={{ presentation: 'modal' }}>
                <NativeStack.Screen 
                    name="MyScreenThatNeedsToBeAbleToOpenABottomSheetModal" 
                    component={MyScreenThatNeedsToBeAbleToOpenABottomSheetModal} 
                />
            </NativeStack.Group>
        </NativeStack.Navigator>
    )
}

function MyScreenThatNeedsToBeAbleToOpenABottomSheetModal() {
    return (
        <BottomSheetModalProvider>
            {/* Screen content here, and one of these children can now open a BottomSheetModal */}
        </BottomSheetModalProvider>
    )
}
4reactions
Livijncommented, Feb 7, 2022

I don’t want to drop the benefits of using the native stack for this purpose. Thanks though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Navigation Integration | React Native Bottom Sheet
React Navigation Integration. One of the main goal of this library, is to allow user to fully integrate a stack navigator in the...
Read more >
Opening a modal - React Navigation
A modal displays content that temporarily blocks interactions with the main view. A modal is like a popup — it's not part of...
Read more >
gorhom/bottom-sheet - npm
Modal presentation view, Bottom Sheet Modal. Smooth gesture interactions & snapping animations. Seamless keyboard handling for iOS & Android.
Read more >
How to display a bottom sheet from React navigation ...
in const MainStack = createStackNavigator(); to open a Modal component. But it have a little bit lag, show a white background for about...
Read more >
How to create bottom sheet / modal like this one? (read first ...
After updating I get the following error: "react native version mismatch, JS version: 0.61.4, Native version: 0.59.8"I tried looking online for a solution...
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