🌜
🌞
reanimated-bottom-sheet

reanimated-bottom-sheet

v1.0.0-alpha.22

Bottom sheet component

npm install reanimated-bottom-sheet

README

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!

reanimated bottom sheet reanimated bottom sheet reanimated bottom sheet reanimated bottom sheet

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.

Release Notes

1.0.0-alpha.22
By Michał Osadnik • Published on August 14, 2020

1.0.0-alpha.22 (2020-08-14)

Reverts

  • get rid of GestureHandlerRootView (99cc5b0)
1.0.0-alpha.21
By Michał Osadnik • Published on August 13, 2020

1.0.0-alpha.21 (2020-08-13)

Bug Fixes

Features

1.0.0-alpha.20
By Michał Osadnik • Published on April 26, 2020

1.0.0-alpha.20 (2020-04-26)

Bug Fixes

  • snapTo responding only after calling twice (#206) (6df8a03)
1.0.0-alpha.19
By Michał Osadnik • Published on February 14, 2020

1.0.0-alpha.19 (2020-02-14)

Bug Fixes

  • add initialized check (9d97690)
  • header snapTo tap fix on Android (#150) (1ab91b8)
  • height changes not evaluated (#132) (182f75c)
  • reset velocity after transition (fixes apple music example) (737af7a)
  • update example for latest expo (#131) (101e634)

Features

  • enabledBottomInitialAnimation prop added (#148) (3fb9242)
1.0.0-alpha.18
By Michał Osadnik • Published on November 26, 2019
  • fix: borderRadius (318917f)
1.0.0-alpha.17
By Michał Osadnik • Published on November 26, 2019
  • feat: add borderRadius (b2a14ce)
1.0.0-alpha.16
By Michał Osadnik • Published on November 6, 2019
  • fix: snapTo inside sheet content android (#119) (50cc01d)
  • chore: bump lodash from 4.17.11 to 4.17.15 in /Example (#114) (08e3d43)
1.0.0-alpha.15
By Michał Osadnik • Published on October 23, 2019
  • chore: bump release-i (a6b489b)
  • chore: bump js-yaml from 3.13.0 to 3.13.1 (#55) (d17414c)
  • docs: rename renderInner from README (#112) (c4ccc85)
  • feat: add bottom clamp option (#108) (78508cc)
  • docs: enabledContentTapInteraction doc addition (#109) (ca3a1a8)
  • fix: typescript to ignore example folder (#96) (5446288)
  • docs: new gesture control props to README.md (#94) (8ae6910)
1.0.0-alpha.14
By Michał Osadnik • Published on September 9, 2019

Bug Fixes

Features

  • add enabledContentTapInteraction prop (#85) (38a68f4)
  • add support for onOpenStart, onOpenEnd, onCloseStart and onCloseEnd (#83) (e4c84a3)
1.0.0-alpha.13
By Michał Osadnik • Published on June 28, 2019

Bug Fixes

  • make simultaneousHandlers optional (#67) (d0d57c2)

General

License
MIT
Typescript Types
Built-in
Tree-shakeable
Yes

Popularity

GitHub Stargazers
3,163
Community Interest
3,254
Number of Forks
322

Maintenance

Commits
11/2110/2201
Last Commit
Aug 14, 2020
Open Issues
176
Closed Issues
118
Open Pull Requests
32
Closed Pull Requests
9

Versions

Versions Released
11/2110/2201
Latest Version Released
Aug 14, 2020
Current Tags
latest1.0.0-alpha.22

Contributors

osdnk
osdnk
Commits: 51
satya164
satya164
Commits: 8
brentvatne
brentvatne
Commits: 4
codebutler
codebutler
Commits: 2
lucasklimek
lucasklimek
Commits: 2
russ666
russ666
Commits: 2
gorhom
gorhom
Commits: 2
jtomaszewski
jtomaszewski
Commits: 2
davidgovea
davidgovea
Commits: 2
dsznajder
dsznajder
Commits: 2
sebqq
sebqq
Commits: 1
hosseinmd
hosseinmd
Commits: 1
jmacindoe
jmacindoe
Commits: 1
timothystewart6
timothystewart6
Commits: 1
Annihil
Annihil
Commits: 1