• Stars
    star
    3,327
  • Rank 13,471 (Top 0.3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Highly configurable bottom sheet component made with react-native-reanimated and react-native-gesture-handler

Reanimated Bottom Sheet

Highly configurable component imitating native bottom sheet behavior, with fully native 60 FPS animations!

Built from scratch with react-native-gesture-handler and react-native-reanimated.

Usable with Expo with no extra native dependencies!

Installation

Open a Terminal in the project root and run:

yarn add reanimated-bottom-sheet

Or if you use npm:

npm install reanimated-bottom-sheet

Now we need to install react-native-gesture-handler and react-native-reanimated.

If you are using Expo, to ensure that you get the compatible versions of the libraries, run:

expo install react-native-gesture-handler react-native-reanimated

If you are not using Expo, run the following:

yarn add react-native-reanimated react-native-gesture-handler

Or if you use npm:

npm install react-native-reanimated react-native-gesture-handler

We're done! Now you can build and run the app on your device/simulator.

Usage

import * as React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import Animated from 'react-native-reanimated';
import BottomSheet from 'reanimated-bottom-sheet';

export default function App() {
  const renderContent = () => (
    <View
      style={{
        backgroundColor: 'white',
        padding: 16,
        height: 450,
      }}
    >
      <Text>Swipe down to close</Text>
    </View>
  );

  const sheetRef = React.useRef(null);

  return (
    <>
      <View
        style={{
          flex: 1,
          backgroundColor: 'papayawhip',
          alignItems: 'center',
          justifyContent: 'center',
        }}
      >
        <Button
          title="Open Bottom Sheet"
          onPress={() => sheetRef.current.snapTo(0)}
        />
      </View>
      <BottomSheet
        ref={sheetRef}
        snapPoints={[450, 300, 0]}
        borderRadius={10}
        renderContent={renderContent}
      />
    </>
  );
}

Props

name required default description
snapPoints yes E.g. [300, 200, 0]. Points for snapping of bottom sheet coomponent. They define distance from bottom of the screen. Might be number or percent (as string e.g. '20%') for points or percents of screen height from bottom. Note: Array values must be in descending order.
initialSnap no 0 Determines initial snap point of bottom sheet. The value is the index from snapPoints.
renderContent no Method for rendering scrollable content of bottom sheet.
renderHeader no Method for rendering non-scrollable header of bottom sheet.
enabledGestureInteraction no true Defines if bottom sheet could be scrollable by gesture.
enabledHeaderGestureInteraction no true Defines if bottom sheet header could be scrollable by gesture.
enabledContentGestureInteraction no true Defines if bottom sheet content could be scrollable by gesture.
enabledContentTapInteraction no true Defines whether bottom sheet content could be tapped. Note: If you use Touchable* components inside your renderContent, you'll have to switch this to false to make handlers like onPress work. (See this comment.)
enabledManualSnapping no true If false blocks snapping using snapTo method.
enabledBottomClamp no false If true block movement is clamped from bottom to minimal snapPoint.
enabledBottomInitialAnimation no false If true sheet will grows up from bottom to initial snapPoint.
enabledInnerScrolling no true Defines whether it's possible to scroll inner content of bottom sheet.
callbackNode no reanimated node which holds position of bottom sheet, where 0 it the highest snap point and 1 is the lowest.
contentPosition no reanimated node which holds position of bottom sheet's content (in dp)
headerPosition no reanimated node which holds position of bottom sheet's header (in dp)
overdragResistanceFactor no 0 `Defines how violently sheet has to stopped while overdragging. 0 means no overdrag
springConfig no { } Overrides config for spring animation
innerGestureHandlerRefs no Refs for gesture handlers used for building bottom sheet. The array consists fo three refs. The first for PanGH used for inner content scrolling. The second for PanGH used for header. The third for TapGH used for stopping scrolling the content.
simultaneousHandlers no Accepts a react ref object or an array of refs to handler components.
onOpenStart no Accepts a function to be called when the bottom sheet starts to open.
onOpenEnd no Accepts a function to be called when the bottom sheet is almost fully openned.
onCloseStart no Accepts a function to be called when the bottom sheet starts to close.
onCloseEnd no Accepts a function to be called when the bottom sheet is almost closing.
callbackThreshold no 0.01 Accepts a float value from 0 to 1 indicating the percentage (of the gesture movement) when the callbacks are gonna be called.
borderRadius no Border radius of content wrapper (excluding header)

Methods

snapTo(index)

Imperative method on for snapping to snap point in given index. E.g.

// Snap to the snap point at index 0 (e.g. 450 in [450, 300, 0])
this.bottomSheetRef.current.snapTo(0)

Here this.bottomSheetRef refers to the ref passed to the BottomSheet component.

Example

More complex examples can be found in the Example folder. To view the examples in the Expo app, open a Terminal and run:

yarn
yarn prepare
cd Example
yarn
expo start

The example app is also available on Expo.

Todo

It's not finished and some work has to be done yet.

  1. Play with magic config values
  2. Horizontal mode
  3. Deal with GH in inner scrollView
  4. Cleanup code (e.g. measuring of components)

Contributing

Publishing a release

We use release-it to automate our release. If you have publish access to the NPM package, run the following from the master branch to publish a new release:

yarn release

NOTE: You must have a GITHUB_TOKEN environment variable available. You can create a GitHub access token with the "repo" access here.

More Repositories

1

react-native-slack-bottom-sheet

React Native Binding for PanModal by SlackHQ
TypeScript
133
star
2

react-native-tab-view-viewpager-adapter

Helper that allows for utilizing React Native ViewPager in React Native Tab View
TypeScript
78
star
3

react-native-spline-interpolate

Spline interpolation for React Native animations
JavaScript
71
star
4

peek-and-pop

very WIP but that's how we lives
Objective-C
66
star
5

reanimated-bottom-sheet-navigator

React Navigation integration for Reanimated Bottom Sheet
TypeScript
61
star
6

sysopy

[JAK KRADNIESZ, DAJ GWIAZDKฤ˜] This special repo is made to provide solutions for SO course
C
46
star
7

jsi-module-example

Example of building JSI module from scratch with Fresh react native project
CMake
35
star
8

instagram-cropper

TypeScript
17
star
9

slack-pan-sheet-react-native-experiment

MOVED HERE: https://github.com/osdnk/react-native-slack-bottom-sheet/
Swift
13
star
10

react-native-jsi-meets-rust

Java
13
star
11

react-native-animated-props

WIP I HACK REACT NATIVE
11
star
12

react-native-scroll-view-imitate

wish to imitate scrollview behavior for implementing bottomsheet component as a next step
JavaScript
10
star
13

appjs-workshop

Enhancing user experience with high-performance Gestures & Animations
JavaScript
9
star
14

react-native-ultimate-list-playground-2

I stolen that app from @mrousavy (coz it has a beautiful setup) - 2
Java
9
star
15

send-love

https://twitter.com/mosdnk/status/1278139142132695040
TypeScript
5
star
16

osdnk.github.io

JavaScript
4
star
17

react-native-spline-interpolate-workspace

Third order spline interpolation declarative API for React Native
JavaScript
4
star
18

react-native-paper-bottom-sheet-POC

POC of bottom-sheet made with RNGH, reanimated and react-native-paper
JavaScript
3
star
19

reanimated-examples

Some react-native-reanimated examples
JavaScript
2
star
20

rntv-976

Objective-C
2
star
21

eslint-enforce-react-hooks

Just to ensure everyone understands how great are hooks
JavaScript
2
star
22

react-native-ultimate-list-playground

I stolen that app from @mrousavy (coz it has a beautiful setup)
C++
2
star
23

react-native-blur-reanimated-example

JavaScript
2
star
24

rainbow-list

Java
1
star
25

rainbow-backend

1
star
26

svg-moving

1
star
27

hapticly-iOS

supportive app to be compared with Hapticly
Swift
1
star
28

PBD

Python
1
star
29

raspberry-pi-open-cv

Python
1
star
30

hapticly

Haptic example for Android
Kotlin
1
star
31

react-native-haptics

Library for performing haptic feedback in React Native
Java
1
star
32

FSO6

JavaScript
1
star