0.0.24 • Published 1 month ago

hugo-bottom-drawer v0.0.24

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

Hugo Bottom Drawer

A lightweight and highly performant bottom drawer for react native

Features

  • Extremely lightweight (~20 KB) and highly performant
  • Support for snapping (multi height bottom drawer)
  • Smooth Animations and Gestures
  • Completely Customisable
  • Automatic Keyboard Handling
  • useBottomDrawer hook to allow the bottom drawer child components to access bottom drawer methods
  • Written in Typescript

Installation

using npm

npm i hugo-bottom-drawer

using yarn

yarn add hugo-bottom-drawer

Usage

import React, {useRef} from 'react';
import {View, Text, StyleSheet, Button, SafeAreaView} from 'react-native';
import BottomDrawer, {
  BottomDrawerMethods,
} from 'hugo-bottom-drawer';

const App = () => {
  // ref
  const bottomDrawerRef = useRef<BottomDrawerMethods>(null);

  // renders
  return (
    <SafeAreaView style={styles.container}>
      <Button title="Open" onPress={() => bottomDrawerRef.current.open()} />
      <BottomDrawer ref={bottomDrawerRef} openOnMount>
        <View style={styles.contentContainer}>
          <Text>Awesome 🎉</Text>
        </View>
      </BottomDrawer>
    </SafeAreaView>
  );
};

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

export default App;

Available Props

NameTypeDefaultDescriptionRequired
gestureModehandle \| content \| nonehandleThis prop determines where to apply the gesturesNo
openDurationnumber450Animation duration when the bottom drawer is openedNo
closeDurationnumber300Animation duration when the bottom drawer is closedNo
onOpenfunctionnullCallback function when the bottom drawer is openedNo
onClosefunctionnullCallback function when the bottom drawer is closedNo
onBackdropPressfunctiontrueCallback function when the backdrop is pressedNo
onBackPressfunctionnullCallback function when the hardware back button is pressedNo
closeOnPressBackbooleantrueSetting this true will allow the bottom drawer to close when hardware back is pressed (only on android)No
closeOnBackdropPressbooleantrueSetting this true will allow the bottom drawer to close when backdrop is pressedNo
openOnMountbooleanfalseSetting this true will automatically open the bottom drawer when the parent component is mountedNo
enableSnappingbooleanfalseSet this to true when you want to snap the bottom drawer to multiple heightsNo
snapPointsnumber[][400]Points for the bottom sheet to snap to, points should be sorted from bottom to top. It accepts array of number. Example: [300, 500, 700]Yes, if enableSnapping is true
backdropColorstring#000Color of the backdropNo
backdropOpacitynumber0.5Opacity of the backdropNo
customStylesobject{}Add your custom styles here!No
overDragbooleantrueSetting this true will allow the bottom sheet to be overdraggedNo
initialIndexnumber0The initial index out of snapPoints when the bottom sheet is openedNo
initialHeightnumber420The initial height of the bottom sheet when opened. Note: This prop is not available when enableSnapping is set to trueNo
safeTopOffsetnumber50Minimum safe distance from top while dragging the sheet or keyboard is openedNo

Available Methods

These methods can be accessed by bottom drawer reference or useBottomDrawer hook.

open

Opens the bottom drawer

type open = (
  // open at provided sheetHeight
  sheetHeight?: number,
) => void;

NOTE: sheetHeight is only read when enableSnapping is set to false. If enableSnapping is true, then the bottom sheet will be opened at index 0 out of snapPoints.

close

Closes the bottom drawer

type close = () => void;

snapToPosition

Snaps the bottom drawer to given position

type snapToPosition = (
  sheetHeight: number,
  config?: {
    resetLastPosition?: boolean;
  },
) => void;

snapToIndex

Snaps the bottom drawer to given index out of snapPoints (requires enableSnapping to be true)

type snapToIndex = (index: number) => void;

NOTE: This method is only accessible when enableSnapping is set to true.

0.0.24

1 month ago

0.0.23

1 month ago