DEV Community

Cover image for Implementing Attractive Bottom Sheets in React Native with `react-native-bottom-sheet`
HidetoshiYanagisawa
HidetoshiYanagisawa

Posted on

Implementing Attractive Bottom Sheets in React Native with `react-native-bottom-sheet`

What is a Bottom Sheet?

A bottom sheet is a UI design pattern in mobile applications, representing a layer of content that slides up from the bottom of the screen. It serves as a method to provide additional information or actions to the user. Bottom sheets can be used for various purposes, such as menu options, navigation, or detailed information.

Features of React Native Bottom Sheet

react-native-bottom-sheet offers features like:

  • Modal presentation view, Bottom Sheet Modal.
  • Smooth gesture interactions and snapping animations.
  • Seamless keyboard handling for both iOS and Android.
  • Support for scrolling interactions in FlatList, SectionList, ScrollView, and View.
  • Compatibility with Expo.
  • Written in TypeScript.

Installation Guide

yarn add @gorhom/bottom-sheet@^4
Enter fullscreen mode Exit fullscreen mode

Dependencies:

yarn add react-native-reanimated react-native-gesture-handler
Enter fullscreen mode Exit fullscreen mode

For those using Expo:

expo install react-native-reanimated react-native-gesture-handler
Enter fullscreen mode Exit fullscreen mode

Basic Usage

Here's a basic example of implementing a bottom sheet:

import React from 'react';
import { View, Text, Button } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';

const App = () => {
  const bottomSheetRef = useRef(null);

  const handleOpenSheet = () => {
    bottomSheetRef.current.snapTo(1);
  };

  return (
    <View style={{ flex: 1 }}>
      <Button title="Open Bottom Sheet" onPress={handleOpenSheet} />
      <BottomSheet
        ref={bottomSheetRef}
        index={0}
        snapPoints={['25%', '50%', '75%']}
      >
        <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
          <Text>This is the content of the Bottom Sheet</Text>
        </View>
      </BottomSheet>
    </View>
  );
};

export default App;
Enter fullscreen mode Exit fullscreen mode

Conclusion

Using react-native-bottom-sheet, you can easily add attractive bottom sheets to your React Native applications. Leverage the rich features and straightforward implementation of this library to enhance user experience!


If you found this article helpful, please give it a thumbs up or leave a comment. Any questions or feedback are also welcome! 🚀



Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
jrjaro18 profile image
Rohan Jaiswal

useless wish i could have read this comment