Code Monkey home page Code Monkey logo

react-native-bottom-sheet's Introduction

React Native Bottom Sheet πŸ’–

GitHub GitHub Workflow Status (with event) runs with expo GitHub code size in bytes npm bundle size (scoped) npm downloads

The smart 😎, tiny πŸ“¦, and flexible πŸŽ— bottom sheet your app craves πŸš€

Preview for Android & iOS

Web Preview

✨Features

  • πŸ“¦ Very tiny and lightweight
  • 0️⃣ No dependency (yeah!, just plug and play 😎)
  • ✨ Modal and standard (non-modal) bottom sheet support
  • ⌨ Smart & automatic keyboard and orientation handling for iOS & Android
  • πŸ’ͺ Imperative calls
  • πŸ“œ Supports FlatList, SectionList, ScrollView & View scrolling interactions
  • πŸ“Ÿ Handles layout & orientation changes smartly
  • πŸ’― Compatible with Expo
  • πŸ”§ Flexible config
  • πŸš€ Supports props live update
  • 🎞 Configurable animation
  • 🎨 Follows Material Design principles
  • 🌐 Runs on the web
  • βœ… Written in TypeScript

πŸ’» Installation

npm install @devvie/bottom-sheet

or

yarn add @devvie/bottom-sheet

πŸ“± Minimal Usage

Opening and closing the bottom sheet is done imperatively, so just pass a ref to the bottom sheet and call the open or close methods via the ref instance to open and close the bottom sheet respectively.

Examples

Typescript

import React, { useRef } from 'react';
import BottomSheet, { BottomSheetMethods } from '@devvie/bottom-sheet';
import { Button, View } from 'react-native';

const App = () => {
  const sheetRef = useRef<BottomSheetMethods>(null);
  return (
    <View>
      <Button title="Open" onPress={() => sheetRef.current?.open()} />
      <BottomSheet ref={sheetRef}>
        <Text>
          The smart 😎, tiny πŸ“¦, and flexible πŸŽ— bottom sheet your app craves πŸš€
        </Text>
      </BottomSheet>
    </View>
  );
};

export default App;

Javascript

import React, { useRef } from 'react';
import BottomSheet, { BottomSheetMethods } from '@devvie/bottom-sheet';
import { Button, View } from 'react-native';

const App = () => {
  const sheetRef = useRef(null);
  return (
    <View>
      <Button title="Open" onPress={() => sheetRef.current?.open()} />
      <BottomSheet ref={sheetRef}>
        <Text>
          The smart 😎, tiny πŸ“¦, and flexible πŸŽ— bottom sheet your app craves πŸš€
        </Text>
      </BottomSheet>
    </View>
  );
};

⚠ Warning

The bottom sheet component uses and handles pan gestures internally, so to avoid scroll/pan misbehavior with its container, DO NOT put it inside a container that supports panning e.g ScrollView. You can always put it just next to the ScrollView and use React Fragment or a View to wrap them and everything should be okay.

❌ Don't do this

<ScrollView>
  <BottomSheet>...</BottomSheet>
</ScrollView>

βœ… Do this

<>
  <ScrollView>...</ScrollView>

  <BottomSheet>...</BottomSheet>
</>

πŸ›  Props

The bottom sheet is highly configurable via props. All props works for both Android and iOS except those prefixed with android_ and ios_, which works for only Android and iOS respectively.

Property Type Default Description Required
android_backdropMaskRippleColor string | OpaqueColorValue Color of the ripple effect when backdrop mask is pressed (Android Only). No
android_closeOnBackPress boolean true Determines whether the sheet will close when the device back button is pressed (Android Only). No
animationType 'slide' | 'spring' | 'fade' | ANIMATIONS 'slide' Animation to use when opening and closing the bottom sheet. No
backdropMaskColor string | OpaqueColorValue '#00000052' Color of the scrim or backdrop mask. No
children ViewProps['children'] | React.FunctionComponent<{_animatedHeight: Animated.Value}> null Contents of the bottom sheet. Yes
closeDuration number 500 Duration for sheet closing animation. No
closeOnBackdropPress boolean true Determines whether the bottom sheet will close when the scrim or backdrop mask is pressed. No
closeOnDragDown boolean true Determines whether the bottom sheet will close when dragged down. No
containerHeight ViewStyle['height'] DEVICE SCREEN HEIGHT Height of the bottom sheet's overall container. No
customBackdropComponent React.FunctionComponent<{_animatedHeight: Animated.Value}> null Custom component for sheet's scrim or backdrop mask. No
customBackdropPosition "top" | "behind" 'behind' Determines the position of the custom scrim or backdrop component. 'behind' puts it behind the keyboard and `'top'`` puts it atop the keyboard. No
customDragHandleComponent React.FC<{_animatedHeight: Animated.Value}> Custom drag handle component to replace the default bottom sheet's drag handle. No
customEasingFunction AnimationEasingFunction ANIMATIONS.SLIDE Custom easing function for driving sheet's animation. No
disableBodyPanning boolean false Prevents the bottom sheet from being dragged/panned down on its body. No
disableDragHandlePanning boolean false Prevents the bottom sheet from being panned down by dragging its drag handle. No
dragHandleStyle ViewStyle Extra styles to apply to the drag handle. No
height number | string '50%' Height of the bottom sheet when opened. Relative to containerHeight prop No
hideDragHandle boolean false When true, hides the sheet's drag handle. No
modal boolean true Determines whether the sheet is a modal. A modal sheet has a scrim or backdrop mask, while a standard (non-modal) sheet doesn't. No
openDuration number 500 Duration for sheet opening animation. No
style Omit<ViewStyle, 'height' | 'minHeight' | 'maxHeight' | 'transform:[{translateY}]'> Extra styles to apply to the bottom sheet. No

Examples

Flexibility is a focus for this bottom sheet, these few examples shows certain behaviors of the bottom sheet and what can be achieved by tweaking its props.

1️⃣ Smart response to keyboard pop ups and orientation changes (automatic behavior)

Android iOS
Preview for keyboard handling (Android) Preview for keyboard handling (iOS)

2️⃣ Handles deeply nested list and scroll views interactions (automatic beavior)

Android iOS
Preview for scroll handling (Android) Preview for scroll handling (iOS)

3️⃣ Auto adjusts layout when height and containerHeight props change (automatic behavior)

4️⃣ Extend sheet height when its content is scrolled

5️⃣ Use as SnackBar

6️⃣ Custom Drag Handle Animation Interpolation

7️⃣ Custom Scrim/Backdrop Mask

More Examples and code samples comign soon...

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

see LICENSE


</> with πŸ’– by Devvie ✌

react-native-bottom-sheet's People

Contributors

stanleyugwu avatar sourfanta 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.