Coder Social home page Coder Social logo

janak-nirmal / react-native-bottom-sheet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gorhom/react-native-bottom-sheet

0.0 1.0 0.0 9.33 MB

A performant interactive bottom sheet with fully configurable options ๐Ÿš€

License: MIT License

JavaScript 0.92% Java 4.46% TypeScript 89.73% C 0.07% Objective-C 2.15% Swift 0.04% Ruby 2.38% Handlebars 0.26%

react-native-bottom-sheet's Introduction

Bottom Sheet

npm npm npm

A performant interactive bottom sheet with fully configurable options ๐Ÿš€

Initially, this project was a cloned of react-native-scroll-bottom-sheet by @rgommezz โค๏ธ. However, it is been fully re-written to add extra functionalities and simplify the approach.


Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Props
  5. Methods
  6. Hooks
  7. Scrollables
  8. To Do
  9. FAQ
  10. Credits
  11. License

Features

  • ๐ŸŒŸ Modal presentation view, Bottom Sheet Modal.
  • Smooth interactions & snapping animations.
  • Support FlatList, SectionList, ScrollView & View scrolling interactions.
  • Support React Navigation Integration.
  • Compatible with Reanimated v1 & v2.
  • Compatible with Expo.
  • Written in TypeScript.

Installation

Version v1

Link to version 1 branch

This version is written with Reanimated v1

yarn add @gorhom/bottom-sheet
# or
npm install @gorhom/bottom-sheet

โš ๏ธ You need to install react-native-reanimated & react-native-gesture-handler and follow their installation instructions.

Version v2 ( Alpha )

Link to version 2 branch

this version is written with Reanimated v2, although this version is still in alpha phase, yet it provides all version 1 functionalities with the huge performance boost, thanks to Reanimated v2 โค๏ธ

yarn add @gorhom/[email protected]
# or
npm install @gorhom/[email protected]

โš ๏ธ You need to install react-native-reanimated v2 & react-native-gesture-handler and follow their installation instructions.

Usage

import React, { useCallback, useMemo, useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';

const App = () => {
  // hooks
  const bottomSheetRef = useRef<BottomSheet>(null);

  // variables
  const snapPoints = useMemo(() => ['25%', '50%', '90%'], []);

  // callbacks
  const handleSheetChanges = useCallback((index: number) => {
    console.log('handleSheetChanges', index);
  }, []);

  // renders
  return (
    <View style={styles.container}>
      <BottomSheet
        ref={bottomSheetRef}
        initialSnapIndex={1}
        snapPoints={snapPoints}
        onChange={handleSheetChanges}
      >
        {/* INSERT A SCROLLABLE HERE */}
      </BottomSheet>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
  },
});

export default App;

Props

initialSnapIndex

Initial snap index. You also could provide {-1} to initiate bottom sheet in closed state.

required: NO | type: number | default: 0

snapPoints

Points for the bottom sheet to snap to, points should be sorted from bottom to top. It accepts array of number, string or mix. String values should be a percentage.

required: YES | type: Array<string | number>
example: [100, '50%', '90%']

topInset

Top inset value helps to calculate percentage snap points values. usually comes from @react-navigation/stack hook useHeaderHeight or from react-native-safe-area-context hook useSafeArea.

required: NO | type: number | default: 0

enabled

To enable or disable user interaction with the sheet.

required: NO | type: boolean | default: true

animationDuration

Snapping animation duration.

required: NO | type: number | default: 500

animationEasing

Snapping animation easing function.

required: NO | type: Animated.EasingFunction | default: Easing.out(Easing.back(0.75))

animatedPosition

Animated value to be used as a callback for the position node internally.

required: NO | type: Animated.Value

animatedPositionIndex

Animated value to be used as a callback for the position index node internally.

required: NO | type: Animated.Value

handleComponent

Component to be placed as a sheet handle.

required: NO | type: React.FC<BottomSheetHandleProps>

backgroundComponent

Component to be placed as a background.

required: NO | type: React.FC

onChange

Callback when sheet position changed to a provided point.

required: NO | type: (index: number) => void

children

A scrollable node or normal view.

required: YES | type: () => React.ReactNode | React.ReactNode[] | React.ReactNode

Methods

snapTo

Snap to one of the provided points from snapPoints.

type: (index: number) => void

expand

Snap to the maximum provided point from snapPoints.

type: () => void

collapse

Snap to the minimum provided point from snapPoints.

type: () => void

close

Close the bottom sheet.

type: () => void

Hooks

useBottomSheet

The library provide useBottomSheet hook to provide the bottom sheet methods, anywhere inside the sheet content.

type: BottomSheetMethods

Scrollables

This library provides a pre-integrated views that utilise an internal functionalities with the bottom sheet to allow smooth interactions. These views i called them Scrollables and they are:

To Do

  • Add Reanimated v2 support.
  • Add tablets support.
  • Add Bounce support.

FAQ

How this library differ from reanimated-bottom-sheet or react-native-scroll-bottom-sheet?

This library was built to provide the most native-like experience and could fit any use-case that developers wants it to be.

While both libraries providing similar experience, but they still missing the following:

  • reanimated-bottom-sheet
    • Seamless gesture interaction between the sheet and the content.
  • react-native-scroll-bottom-sheet
    • Extracting scrollable content to allow developers customize the sheet content, like integrate React Navigation as the sheet content.

Both libraries are great! and I have used both of them at my work โค๏ธ

How can I integrate React Navigation?

here you go React Navigation Integration :)

Will this library support Reanimated v2?

Yes ๐ŸŽ‰

Built With โค๏ธ

Author

License

MIT

Liked the library? ๐Ÿ˜‡

Buy Me A Coffee


Mo Gorhom

react-native-bottom-sheet's People

Contributors

gorhom avatar remanation 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.