Back to All Articles
Tutorial
React Native

Building a Custom Bottom Sheet from Scratch in React Native

A step-by-step guide to building a gesture-driven, snap-point bottom sheet — the same pattern used by Google Maps, Uber, and Apple Music.

A

Abhinav Birajdar

Creator

December 10, 20246 min read
Building a Custom Bottom Sheet from Scratch in React Native

What We're Building

A snap-point bottom sheet — the kind you see in Google Maps (collapsed, half-open, full-screen), Uber (ride details), and Apple Music (now playing). It:

  • Snaps to predefined positions
  • Responds to drag gestures
  • Springs to the nearest snap point on release
  • Handles keyboard avoidance automatically
  • Renders a backdrop with configurable opacity

Dependencies

bash
1# Using Reanimated 3 and Gesture Handler (both required)
2npx expo install react-native-reanimated react-native-gesture-handler

Or using the popular @gorhom/bottom-sheet library (recommended for production):

bash
1npx expo install @gorhom/bottom-sheet

Building from Scratch

Let's build a simplified but functional version to understand the internals.

jsx
1import { useCallback, useRef } from 'react';
2import { Dimensions, StyleSheet, View } from 'react-native';
3import Animated, {
4  useAnimatedStyle,
5  useSharedValue,
6  withSpring,
7  runOnJS,
8} from 'react-native-reanimated';
9import { Gesture, GestureDetector } from 'react-native-gesture-handler';
10
11const { height: SCREEN_HEIGHT } = Dimensions.get('window');
12
13const SNAP_POINTS = {
14  COLLAPSED: SCREEN_HEIGHT * 0.12,  // 12% visible
15  HALF: SCREEN_HEIGHT * 0.5,        // 50% visible
16  FULL: SCREEN_HEIGHT * 0.92,       // 92% visible
17};
18
19const SPRING_CONFIG = {
20  damping: 50,
21  mass: 0.8,
22  stiffness: 400,
23};
24
25export function BottomSheet({ children }) {
26  const translateY = useSharedValue(SCREEN_HEIGHT - SNAP_POINTS.COLLAPSED);
27  const context = useSharedValue({ y: 0 });
28
29  const snapTo = useCallback((snapPoint) => {
30    'worklet';
31    translateY.value = withSpring(SCREEN_HEIGHT - snapPoint, SPRING_CONFIG);
32  }, []);
33
34  const gesture = Gesture.Pan()
35    .onStart(() => {
36      context.value = { y: translateY.value };
37    })
38    .onUpdate((event) => {
39      // Clamp to prevent dragging above full or below collapsed
40      const newY = context.value.y + event.translationY;
41      translateY.value = Math.max(
42        SCREEN_HEIGHT - SNAP_POINTS.FULL,
43        Math.min(newY, SCREEN_HEIGHT - SNAP_POINTS.COLLAPSED)
44      );
45    })
46    .onEnd((event) => {
47      // Determine nearest snap point
48      const currentVisible = SCREEN_HEIGHT - translateY.value;
49      const velocity = event.velocityY;
50
51      if (velocity < -500 || currentVisible > SCREEN_HEIGHT * 0.65) {
52        snapTo(SNAP_POINTS.FULL);
53      } else if (velocity > 500 || currentVisible < SCREEN_HEIGHT * 0.3) {
54        snapTo(SNAP_POINTS.COLLAPSED);
55      } else {
56        snapTo(SNAP_POINTS.HALF);
57      }
58    });
59
60  const animatedStyle = useAnimatedStyle(() => ({
61    transform: [{ translateY: translateY.value }],
62  }));
63
64  return (
65    <GestureDetector gesture={gesture}>
66      <Animated.View style={[styles.sheet, animatedStyle]}>
67        {/* Drag handle */}
68        <View style={styles.handleContainer}>
69          <View style={styles.handle} />
70        </View>
71        {children}
72      </Animated.View>
73    </GestureDetector>
74  );
75}
76
77const styles = StyleSheet.create({
78  sheet: {
79    height: SCREEN_HEIGHT,
80    width: '100%',
81    backgroundColor: 'white',
82    position: 'absolute',
83    top: 0,
84    borderTopLeftRadius: 20,
85    borderTopRightRadius: 20,
86    shadowColor: '#000',
87    shadowOffset: { width: 0, height: -4 },
88    shadowOpacity: 0.12,
89    shadowRadius: 16,
90    elevation: 24,
91  },
92  handleContainer: {
93    alignItems: 'center',
94    paddingVertical: 12,
95  },
96  handle: {
97    width: 40,
98    height: 4,
99    backgroundColor: '#CBD5E1',
100    borderRadius: 2,
101  },
102});

Using @gorhom/bottom-sheet in Production

For a production app, use the battle-tested library which handles edge cases you'd spend weeks finding:

jsx
1import BottomSheet, { BottomSheetView } from '@gorhom/bottom-sheet';
2import { useRef, useMemo, useCallback } from 'react';
3
4export function MapScreen() {
5  const bottomSheetRef = useRef(null);
6  const snapPoints = useMemo(() => ['12%', '50%', '92%'], []);
7
8  const handleSheetChanges = useCallback((index) => {
9    console.log('Sheet position:', index);
10  }, []);
11
12  return (
13    <View style={styles.container}>
14      <MapView style={StyleSheet.absoluteFillObject} />
15
16      <BottomSheet
17        ref={bottomSheetRef}
18        index={1}
19        snapPoints={snapPoints}
20        onChange={handleSheetChanges}
21        enablePanDownToClose={false}
22        backgroundStyle={{ backgroundColor: '#FFFFFF' }}
23        handleIndicatorStyle={{ backgroundColor: '#CBD5E1' }}
24      >
25        <BottomSheetView style={styles.contentContainer}>
26          <SearchBar />
27          <PlacesList />
28        </BottomSheetView>
29      </BottomSheet>
30    </View>
31  );
32}

Keyboard Avoidance

The trickiest part of bottom sheets is handling the keyboard. Use BottomSheetTextInput instead of the standard TextInput:

jsx
1import { BottomSheetTextInput } from '@gorhom/bottom-sheet';
2
3// Inside your bottom sheet content:
4<BottomSheetTextInput
5  placeholder="Search places..."
6  style={styles.searchInput}
7  // This automatically adjusts the sheet when the keyboard appears
8/>

Performance Tips

  • Use useCallback and useMemo to avoid unnecessary re-renders
  • Run gesture handling and animations on the UI thread (Reanimated's worklets handle this)
  • Use keyboardBehavior="interactive" on BottomSheet for smoother keyboard handling
  • Avoid rendering heavy content in collapsed state — use lazy loading

Conclusion

A well-implemented bottom sheet elevates the whole experience of your app. The pattern is everywhere because it works: it's discoverable, space-efficient, and feels native on both iOS and Android. Whether you build from scratch (great for learning) or use @gorhom/bottom-sheet (great for shipping), the key is getting gesture physics and snap behavior right.