React Native Bottom Sheet

website·Indexed 33 days ago

https://gorhom.dev/react-native-bottom-sheet/

A library for creating bottom sheets in React Native, featuring integrated components like BottomSheetFlatList, BottomSheetScrollView, and BottomSheetTextInput. Supports multiple versions including v2 (Reanimated v1), v4 (Reanimated v2), and v5, with specialized functionality for Bottom Sheet Modals and keyboard handling.

Tokens
32.3K
Snippets
147
Records
217
Agent score
68%

What's inside React Native Bottom Sheet

  1. Overview of Bottom Sheet Modal in @gorhom/bottom-sheet

    The Bottom Sheet Modal is a wrapper/decorator built on top of the standard Bottom Sheet. It inherits all standard Bottom Sheet functionalities while adding specialized modal presentation capabilities, including support for stacked sheet modals (inspired by Apple Maps) and smooth mounting animations.
  2. Overview of @gorhom/bottom-sheet features

    The @gorhom/bottom-sheet library provides a performant interactive bottom sheet for React Native with the following capabilities:

    • Platform Support: Works with React Native Web and is written in TypeScript.
    • Sizing & Layout: Supports Dynamic Sizing and Modal presentation views.
    • Interactions: Smooth gesture interactions, snapping animations, and accessibility support.
    • Scrollable Integration: Supports FlatList, SectionList, ScrollView, View, and FlashList scrolling interactions, including pull-to-refresh.
    • System Integration: Seamless keyboard handling for iOS and Android, and integration with React Navigation.
    • Compatibility: Compatible with Reanimated v1, v2, and v3.
  3. Overview of Bottom Sheet Modal in react-native-bottom-sheet v4

    v4
    The Bottom Sheet Modal is a wrapper/decorator for the standard Bottom Sheet. It inherits all standard Bottom Sheet functionalities while adding specific modal presentation capabilities, including support for stacked sheet modals (inspired by Apple Maps) and smooth mounting animations.
  4. Overview of @gorhom/bottom-sheet v4 features

    v4

    The @gorhom/bottom-sheet library provides a performant interactive bottom sheet for React Native. Key features include:

    • Modal presentation via Bottom Sheet Modal.
    • Smooth gesture interactions and snapping animations.
    • Keyboard handling for both iOS and Android.
    • Pull-to-refresh support for scrollable components.
    • Integration with FlatList, SectionList, ScrollView, and View scrolling.
    • Integration with React Navigation.
    • Compatibility with Reanimated v2 and v3, and Expo.
    • Full TypeScript support and accessibility features.
  5. Overview of Bottom Sheet Modal

    v2
    The Bottom Sheet Modal is a wrapper/decorator built on top of the base Bottom Sheet. It inherits all standard Bottom Sheet functionalities while adding specific modal presentation capabilities, such as smooth interaction, mounting animations, and support for stacked sheet modals (inspired by Apple Maps).
  6. Use BottomSheetVirtualizedList for scrollable content in BottomSheet

    BottomSheetVirtualizedList is a pre-integrated React Native VirtualizedList designed to work with BottomSheet gestures. It inherits all standard VirtualizedListProps from react-native.
    import { BottomSheetVirtualizedList } from "@gorhom/bottom-sheet";
    
    <BottomSheetVirtualizedList
      data={data}
      keyExtractor={(i) => i}
      getItemCount={(data) => data.length}
      getItem={(data, index) => data[index]}
      renderItem={renderItem}
    />
  7. Capabilities of @gorhom/bottom-sheet v2

    v2

    The @gorhom/bottom-sheet v2 library provides a performant interactive bottom sheet with the following features:

    • Modal presentation via Bottom Sheet Modal.
    • Smooth gesture interactions and snapping animations.
    • Scrolling interaction support for FlatList, SectionList, ScrollView, and View.
    • Integration with React Navigation.
    • Compatibility with Expo and Reanimated v1.
    • Full TypeScript support and accessibility features.
  8. Use BottomSheetSectionList for sectioned lists in a BottomSheet

    The BottomSheetSectionList component is a pre-integrated version of the React Native SectionList designed to work with BottomSheet gestures. It inherits all standard SectionListProps from react-native.
    import BottomSheet, { BottomSheetSectionList } from "@gorhom/bottom-sheet";
    
    // ... inside component
    <BottomSheet snapPoints={['25%', '50%', '90%']}>
      <BottomSheetSectionList
        sections={sections}
        keyExtractor={(i) => i}
        renderSectionHeader={renderSectionHeader}
        renderItem={renderItem}
      />
    </BottomSheet>
  9. Use BottomSheetScrollView for scrollable content in BottomSheet

    The BottomSheetScrollView is a pre-integrated React Native ScrollView designed to work with BottomSheet gestures. It inherits all standard ScrollViewProps from react-native.
    import BottomSheet, { BottomSheetScrollView } from "@gorhom/bottom-sheet";
    
    const MyComponent = () => (
      <BottomSheet snapPoints={['25%', '50%', '90%']}>
        <BottomSheetScrollView contentContainerStyle={{ backgroundColor: 'white' }}>
          {/* Your scrollable content here */}
        </BottomSheetScrollView>
      </BottomSheet>
    );
  10. Use BottomSheetScrollView for scrollable content in a BottomSheet

    v4
    The BottomSheetScrollView is a pre-integrated React Native ScrollView designed to work with BottomSheet gestures. It inherits all standard ScrollViewProps from react-native.
    import BottomSheet, { BottomSheetScrollView } from "@gorhom/bottom-sheet";
    
    const App = () => {
      return (
        <BottomSheet snapPoints={["25%", "50%", "90%"]}>
          <BottomSheetScrollView contentContainerStyle={{ backgroundColor: 'white' }}>
            {/* Your scrollable content here */}
          </BottomSheetScrollView>
        </BottomSheet>
      );
    };
  11. Use BottomSheetFlashList for high-performance lists in BottomSheet

    The BottomSheetFlashList is a pre-integrated version of Shopify's FlashList designed to work with BottomSheet gestures. It inherits all FlashListProps from the standard FlashList library.

    Deprecation Notice: As of v5, BottomSheetFlashList is deprecated. It is recommended to use the useBottomSheetScrollableCreator hook for a simpler approach to integrating scrollable components.

    import BottomSheet, { BottomSheetFlashList } from "@gorhom/bottom-sheet";
    
    // ... inside component
    <BottomSheet ref={sheetRef} snapPoints={snapPoints}>
      <BottomSheetFlashList
        data={data}
        keyExtractor={(item) => item}
        renderItem={renderItem}
        estimatedItemSize={43.3}
      />
    </BottomSheet>
  12. Use BottomSheetTextInput for keyboard-aware inputs

    The BottomSheetTextInput component is a pre-integrated TextInput designed to communicate with the internal functionalities of the bottom sheet. This ensures that keyboard handling (such as shifting the sheet up when the keyboard appears) works correctly. It inherits all standard TextInputProps from react-native.
    import React, { useCallback, useMemo, useRef } from 'react';
    import { View, Text, StyleSheet } from 'react-native';
    import { GestureHandlerRootView } from 'react-native-gesture-handler';
    import BottomSheet, { BottomSheetView, BottomSheetTextInput } from '@gorhom/bottom-sheet';
    
    const App = () => {
      const bottomSheetRef = useRef<BottomSheet>(null);
      const snapPoints = useMemo(() => ['25%', '50%'], []);
    
      const handleSheetChanges = useCallback((index: number) => {
        console.log('handleSheetChanges', index);
      }, []);
    
      return (
        <GestureHandlerRootView style={styles.container}>
          <BottomSheet
            ref={bottomSheetRef}
            index={1}
            snapPoints={snapPoints}
            keyboardBehavior="fillParent"
            enableDynamicSizing={false}
            onChange={handleSheetChanges}
          >
            <BottomSheetTextInput style={styles.input} />
            <BottomSheetView style={styles.contentContainer}>
              <Text>Awesome 🎉</Text>
            </BottomSheetView>
          </BottomSheet>
        </GestureHandlerRootView>
      );
    };
    
    const styles = StyleSheet.create({
      container: { flex: 1, padding: 24, backgroundColor: 'grey' },
      contentContainer: { flex: 1, alignItems: 'center' },
      input: {
        marginTop: 8,
        marginBottom: 10,
        borderRadius: 10,
        fontSize: 16,
        lineHeight: 20,
        padding: 8,
        backgroundColor: 'rgba(151, 151, 151, 0.25)',
      },
    });
    
    export default App;