Coder Social home page Coder Social logo

hieucoi96 / react-native-simple-bottom-sheet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stefanomartella/react-native-simple-bottom-sheet

0.0 0.0 0.0 947 KB

A simple react native bottom sheet component

License: MIT License

JavaScript 100.00%

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

react-native-simple-bottom-sheet

CodeFactor Codacy Badge GithubStart GithubLicense NpmVersion NpmMonthlyDownloads Donate

A simple react native bottom sheet component

Example 1 Example 2 Example 3

Table of Contents

Installation

npm i --save react-native-simple-bottom-sheet

Usage

import BottomSheet from 'react-native-simple-bottom-sheet';

function App() {
  return (
    <View style={{flex: 1}}>
      <View>Your content</View>
      <BottomSheet isOpen>
        // The component to render inside the panel
        <View />
      </BottomSheet>
    </View>
  );
}

By default the height of the panel tries to adapt to the content height till the sliderMaxHeight value is reached.
If you want the content to scroll inside the panel use ScrollView/FlatList like this:

function App() {
  return (
    <View style={{flex: 1}}>
      <View>Your content</View>
      <BottomSheet isOpen>
        {(onScrollEndDrag) => (
          <ScrollView onScrollEndDrag={onScrollEndDrag}>
            {[...Array(10)].map((_, index) => (
              <View key={`${index}`} style={styles.listItem}>
                <Text>{`List Item ${index + 1}`}</Text>
              </View>
            ))}
          </ScrollView>
        )}
      </BottomSheet>
    </View>
  );
}

This allows the panel to close when the user reaches the top of the scrollable content and drags the panel down again. Example:


scroll



By default when the panel is closed you can drag it up again thanks to the part of the panel that remains on the bottom side of the screen. If you want to completely hide it you can set the sliderMinHeight prop to 0 and use the togglePanel method to bring it up.

function App() {
  const panelRef = useRef(null);

  return (
    <View style={{flex: 1}}>
      <View>Your content</View>
      <TouchableOpacity onPress={() => panelRef.current.togglePanel()}>
        <Text>Toggle</Text>
      </TouchableOpacity>
      <BottomSheet ref={ref => panelRef.current = ref}>
        <Text style={{paddingVertical: 20}}>
          Some random content
        </Text>
      </BottomSheet>
    </View>
  );
}

toggle


Props

Prop Name Type Default Description
children func or node <View /> A component or a render function. Use toggleSlider function instead
isOpen boolean true Initial state of the panel; true to render it opened, false otherwise. Important: Do not try to open/close the panel througth this prop, see togglePanel method instead
sliderMinHeight number 50 Min height of the panel
sliderMaxHeight number Dimensions.get('window').height * 0.5 Max height of the panel
animation func Easing.quad The close/open animation of the panel
animationDuration number 200 How long the panel takes to open/close
onOpen function () => null Function to execute when the panel is opened
onClose function () => null Function to execute when the panel is closed
wrapperStyle object {} Custom style for the panel wrapper
outerContentStyle object {} Custom style for the outer content
innerContentStyle object {} Custom style for the inner content
lineContainerStyle object {} Custom style for the line container
lineStyle object {} Custom style for the line

Methods

Name Description
togglePanel Function to close/open the panel

License

MIT

Support

If you enjoyed this project โ€” or just feeling generous, consider buying me a beer. Cheers!

Author

Made by Stefano Martella

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

Contributors

hieucoi96 avatar stefanomartella 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.