Giter Site home page Giter Site logo

cursedwizard / react-native-navigation-bottom-sheet Goto Github PK

View Code? Open in Web Editor NEW
52.0 3.0 4.0 29.67 MB

A performant customizable bottom sheet component made on top of wix react-native-navigation library.

License: MIT License

JavaScript 1.75% Java 8.99% TypeScript 82.42% Objective-C 5.69% Ruby 1.16%
react-native react-native-navigation ios android bottom-sheet bottomsheet modal sheet

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

📃 ​React Native Navigation Bottom Sheet Extension

A performant customizable bottom sheet component made on top of wix react-native-navigation library. The component is built using react-native-gesture-handler and react-native-reanimated. This solution uses showModal under the hood to display the bottom sheet. Default animations and hardware back button press are overridden and properly adjusted for seamless integration with react-native-navigation library.

To replicate the behavior of the bottom sheet as showcased in gifs above check out the example/ folder.

✨ Features

  • Smooth interactions & snapping animations
  • Customizable
  • Supports multiple snapping points
  • Seamless integration with react-native-navigation
  • Scrollable content

📦 Installation

Below I listed commands using yarn but you also can use npm to install the package.

yarn add react-native-navigation-bottom-sheet

You also need to install react-native-gesture-handler and react-native-reanimated dependecies. Since the latest release (1.3.0) the bottom sheet is compatible with both versions of react-native-reanimated library. If you are developing for Android and don't want to do any additional configuration besides installing the package, you might want to install version 1. For more info on installation of reanimated version 2 check out their official documentation.

Reanimated version 1:

yarn add react-native-gesture-handler [email protected]

Reanimated version 2 (latest version):

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

🚀 Usage

You should initialize RNNBottomSheet first by calling init() method.

Then you can open the bottom sheet using the openBottomSheet() method. This function accepts object with props described in the section below.

import React, { Component } from 'react'
import { Text, View, Button } from 'react-native';
import { RNNBottomSheet } from 'react-native-navigation-bottom-sheet';

RNNBottomSheet.init();

export default class App extends Component {
renderContent = () => (
    <View
      style={{
        backgroundColor: 'white',
        height: 350,
        flexDirection: 'row',
        alignItems: 'center',
        justifyContent: 'center',
        borderRadius: 16,
      }}
    >
      <Text>
        In order to close the modal, you can swipe it down, touch the area outside
        it or press the back button.
      </Text>
    </View>
  );


  render() {
    return (
        <View style={{
            flex: 1,
    		alignItems: 'center',
    		justifyContent: 'center',
    		backgroundColor: 'whitesmoke',
        }}>
          <Button
            onPress={() =>
              RNNBottomSheet.openBottomSheet({
                renderContent: this.renderContent,
                snapPoints: [0, '20%', '40%', '70%'],
                borderRadius: 16,
                onChange: (index: number) => console.log("Snapped to " + index),
              })
            }
            title="Show modal"
          />
        </View>
    );
  }
}

⚙️ Props

name required type description
snapPoints yes (number | string)[] Points for snapping of the bottom sheet component. They define distance from bottom of the screen. Might be number or percent (as string e.g. '20%'). Example: [0, 100, 500].
initialSnapIndex no number Index of a point the bottom sheet should snap to when the component mounts. Defaults to the last point specified in the snapPoints array.
renderContent no ReactNode Method for rendering scrollable content of the bottom sheet.
renderHeader no ReactNode Method for rendering non-scrollable header of the bottom sheet.
dismissWhenTouchOutside no boolean Should the bottom sheet be dismissed when touched outside. Default true.
enabledContentGestureInteraction no boolean Defines if the bottom sheet content could be scrollable by gesture. Default true.
fadeOpacity no number Opacity of the screen outside the bottom sheet. Default 0.7.
borderRadius no number Border radius of the bottom sheet. Note if you have header rendered, header should have border radius too.
backgroundColor no string Background color of the bottom sheet. Default '#fff'.
onChange no (index: number) => void Callback when the sheet position changed.
style no StyleProp Any valid style properties.
animationConfig no AnimationConfig Object consisting of several options defining behavior of animations. See the list of options below.

AnimationConfig options

option description
deceleration Deceleration rate of content scrolling or rate of decay. Accepts values from 0 to 1. Default 0.997.
stiffness The spring stiffness coefficient. Default 121.6
damping Defines how the spring’s motion should be damped due to the forces of friction. Default 50.
mass The mass of the object attached to the end of the spring. Default 0.3.
velocityFactor Scrolling velocity amplifier. Resulting velocity of the scroll is calculated as origianlVelocity * velocityFactor. Default 0.9.
restSpeedThreshold The speed at which the spring should be considered at rest in pixels per second. Default 0.3.
restDisplacementThreshold The threshold of displacement from rest below which the spring should be considered at rest. Default 0.3.

🔧 Methods

init()

A wrapper around Navigation.registerComponent() function. Name assigned to the component can be received later by calling getComponentName() method.

openBottomSheet(props)

Opens the bottom sheet and snaps it to the point either specified in props or to the top one otherwise. A wrapper function around Navigation.showModal(), that passes the props along with other options.

closeBottomSheet()

Closes the bottom sheet.

getComponentName()

Returns a name of the component that is used when calling registerComponent() method.

isOpened()

Returns a boolean indicating whether the bottom sheet is opened or not.

⚠️ Take into account

I developed and tested the component primarily on Android devices and even though, theoretically, it should also work on iOS, I can't test it and thus vouch that it will function the same way.

📋 Roadmap

The project is still in development and here's a list of features / fixes i am planning to address:

  • add decay animation for scrolling (29.08.2021)
  • add better support for FlatList and SectionList (for now there are only wrappers)
  • add more options for customization
  • add an option to automatically adjust bottom sheet height based on scrolling content
  • add an option to dynamically change opacity of the bottom sheet
  • add dedicated support for horizontal scrolling inside the bottom sheet
  • explore new ways to optimize animations and loading of the bottom sheet

Feel free to suggest your own ideas.

🐛 ​Something doesn't work?

Don't hesitate to file an issue about any kind of malfunction you experienced. You can also DM me by my email [email protected]

📖 License

MIT

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

Contributors

cursedwizard avatar rheutz91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-navigation-bottom-sheet's Issues

Example seems broken

Thanks for the work of this nice project.

After I clone the project, and run yarn and yarn start, the console output:

[Thu Aug 26 2021 10:11:57.497]  ERROR    Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check your code at renderApplication.js:45.
[Thu Aug 26 2021 10:11:57.498]  ERROR    Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

This error is located at:
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
[Thu Aug 26 2021 10:11:57.498]  ERROR    Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

This error is located at:
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)

And I find that the index.tsx is use App from the './src/App',but App.tsx doesn't making a named export or default export.

onClose event?

is there android hardware back button onClose event? I realy need it.

Anyone using this library on iOS in Production?

Hi there,
Is there anyone who's using this library on iOS in production?
Since the maintainer of this library has developed it on Android, it would be helpful if anyone can confirm this works fine on iOS too?

snapPoints for dynamic content

Do you have any ideas in case I want to show a non-scrollable content, such as a calendars with header below, and I don't know the exact height/percentage of this content area to set the snapPoints
IMG_3D65AF58EAF4-1

Navigation Bar is reset

I had changed the Navigation Bar color, then show bottom sheet, the navigation bar background color is reset

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.