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.

Placing an element above a bottom sheet modal

See original GitHub issue

Bug

I’m trying to place a View with an absolute position at the bottom (bottom: 0) where the bottom sheet modals appear and regardless of the zIndex I give the View, I am unable to place it above the modal. The View does appear above a regular Bottom Sheet, but not a modal. Any idea why and how to do this?

Environment info

@gorhom/bottom-sheet”: “^2”, “react-native”: “https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz”, “react-native-reanimated”: “~1.13.0”, “react-native-gesture-handler”: “~1.8.0”,

Steps To Reproduce

Use the pseudo code I pasted

Describe what you expected to happen:

The red line (View) at the bottom should appear above the bottom sheet modal

Reproducible sample code

Pseudo code to illustrate:

<View>
  <BottomSheetModal
    ref={MyModalRef}
    name="MyModal"
    index={1}
    snapPoints={MyModalSnapPoints}
    topInset={topSafeArea}
    animatedPosition={animatedModalPosition}
    handleComponent={Handle}>
    ...
  </BottomSheetModal>
  <View style={{ position: 'absolute', left: 0, right: 0, bottom: 0, zIndex: 10000000000, }}>
    <View style={{ width: '100%', height: 5, backgroundColor: 'red' }} />
  </View>
</View>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
kickbkcommented, Jan 21, 2021

Mo, after playing around with this for quite a while, I came up with a pretty convenient way to address positioning requirements with your repo and react navigation. I ended up wrapping each screen in a navigator with a withModalProvider. Since it expects a functional component with no props, I had to move the navigation and route props inside the screen components (see links). Then I was able to wrap the screen component.

Note: wrapping the screens should be handled outside the navigator or it will recreate a component every time and return errors. An example of the correct way to do this:

const WrappedAccountScreen = withModalProvider(AccountScreen);

export default function AccountNavigator() {
  return (
    <AccountStack.Navigator>
      <AccountStack.Screen
        name="Account"
        component={WrappedAccountScreen} // << Do not place withModalProvider(AccountScreen) here directly.
      />
    ...

Now placing components, such as a loader, at bottom: 0 would place them right above the nav bar. This is also convenient when placing the bottom sheet for multiple screens, so no need to include them in every screen, just in the provider module.

I wanted to share this solution for anyone looking to do the same.

2reactions
gorhomcommented, Jan 19, 2021

you can add that layer to the BottomSheetHandle and limit the snapPoints to show only the handle while its loading

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and styling a modal bottom sheet in React Native
In this tutorial, we'll create a basic application with a modal bottom sheet feature. We'll set up the app, fetch data, and style...
Read more >
Props | React Native Bottom Sheet - GitHub Pages
Bottom Sheet configurable props. ... Defines how violently sheet has to be stopped while over dragging. ... Callback when the sheet position changed....
Read more >
Modal Bottom Sheets - Material Design
Modal bottom sheets render a shadow on the content below them to indicate that they are modal. If the content outside of the...
Read more >
How to use BottomSheet inside model - react native
I am using reanimated-bottom-sheet and react native modal. But when I use BottomSheet inside Modal gesture not work and can't close BottomSheet ......
Read more >
Jetpack Compose bottom sheet over Android ... - ProAndroidDev
Jetpack compose provides two components that can handle bottom sheet modal behavior, and as we mentioned earlier we will use ModalBottomSheetLayout for our...
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