Sitemap
Sambulo Senda

Sambulo Senda

Software Engineer | React Native

Step-by-Step Guide: Implementing a Bottom Sheet in Your React Native App

2 min readApr 16, 2023
Press enter or click to view image in full size

To create a React Native app that includes a bottom sheet, you’ll need to take a few steps. First, install Node.js, the React Native CLI, and Xcode. Then, use the command line to create a new React Native project by running the following command:

react-native init MyApp

This will create a project called MyApp in the current directory, which you can then open in your preferred code editor or Xcode.

Next, you’ll need to install the required dependencies. To do this, run the following command in your terminal window:

npm install @gorhom/bottom-sheet

This will install the necessary @gorhom/bottom-sheet package into your project.

Get Sambulo Senda’s stories in your inbox

Join Medium for free to get updates from this writer.

Once you have the dependencies installed, you can start implementing the bottom sheet in your React Native app. Begin by importing the BottomSheet component from the @gorhom/bottom-sheet package into your App.js file:

import { BottomSheet } from '@gorhom/bottom-sheet';

To use the component in your app, include the following code in the render method of your App component:

<BottomSheet
visible={this.state.visible}
onBackdropPress={() => this.setState({ visible: false })}
>
<View style={styles.content}>
<Text>This is the content of the bottom sheet!</Text>
</View>
</BottomSheet>

The visible prop controls the visibility of the bottom sheet, while onBackdropPress specifies the function to be called when the backdrop is pressed. You can customize the content of the bottom sheet by adding any components or content you want to display within the View component.

You can customize the bottom sheet further by passing different props to the component. For example, you can set a custom height for the bottom sheet by using the height prop:

<BottomSheet
visible={this.state.visible}
onBackdropPress={() => this.setState({ visible: false })}
height={400}
>
<View style={styles.content}>
<Text>This is the content of the bottom sheet!</Text>
</View>
</BottomSheet>

Or you can set a custom backdrop color using the backdropColor prop:

<BottomSheet
visible={this.state.visible}
onBackdropPress={() => this.setState({ visible: false })}
backdropColor="red"
>
<View style={styles.content}>
<Text>This is the content of the bottom sheet!</Text>
</View>
</BottomSheet>

Bottom sheets are a useful tool for adding interactivity to your app. They can be used to display contextual menus, forms, notifications, or interactive elements like sliders or checkboxes.

--

--