Giter Site home page Giter Site logo

numandev1 / react-native-reanimated-bottom-sheet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from osdnk/react-native-reanimated-bottom-sheet

0.0 1.0 0.0 42.25 MB

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

License: MIT License

JavaScript 36.19% TypeScript 63.81%

react-native-reanimated-bottom-sheet's Introduction

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

If you are using Expo, you are done.

If you don't use Expo, install and link react-native-gesture-handler and react-native-reanimated.

Usage

import BottomSheet from 'reanimated-bottom-sheet'

class Example extends React.Component {
  renderContent = () => (
    /* render */
  )

  renderHeader = () => (
    /* render */
  )

  render() {
    return (
      <View style={styles.container}>
        <BottomSheet
          snapPoints = {[450, 300, 0]}
          renderContent = {this.renderContent}
          renderHeader = {this.renderHeader}
        />
    </View>)
  }
}

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.
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
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.

react-native-reanimated-bottom-sheet's People

Contributors

osdnk avatar satya164 avatar brentvatne avatar dependabot[bot] avatar gorhom avatar roshangm1 avatar russ666 avatar davidgovea avatar codebutler avatar rodolfovilaca avatar jmacindoe avatar iamolegga avatar itsyogesh avatar timothystewart6 avatar sebqq avatar rgoldiez avatar 0duaht avatar eyesonly88 avatar jayu avatar hanford avatar franjorub avatar brtqkr avatar annihil avatar ahmaddehnavi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.