Giter VIP home page Giter VIP logo

trendingtechnology / react-native-navigation-drawer-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lukebrandonfarrell/react-native-navigation-drawer-extension

0.0 1.0 0.0 1.96 MB

Drawer API built on top of wix react-native-navigation for iOS and Android (with TypeScript!)

JavaScript 51.63% TypeScript 33.81% Starlark 0.75% Java 7.56% Objective-C 5.02% Ruby 1.00% Shell 0.21%

react-native-navigation-drawer-extension's Introduction


React Native Navigation Drawer Extension

version license downloads

React Native Navigation by Wix does not offer an in-built solution for displaying a drawer on iOS. Their current side-menu has limited functionality on both iOS and Android. This is a drawer solution using showOverlay under the hood to display a drawer on iOS and Android.

If you are using React Native Navigation >= 3.0.0 then use version 3.x.x + of this library.

Install

 npm install react-native-navigation-drawer-extension --save

or

 yarn add react-native-navigation-drawer-extension

Usage

You need to register your drawer component with RNN. To do this use the register method and wrap your component in the RNNDrawer HOC.

import { Navigation } from "react-native-navigation";
import { RNNDrawer } from "react-native-navigation-drawer-extension";

// register our drawer component with RNN
Navigation.registerComponent("CustomDrawer", () => RNNDrawer.create(CustomDrawer));

You can then use the drawer by calling a custom method. The showDrawer method will take a single parameter options identical to showOverlay.

import { RNNDrawer } from "react-native-navigation-drawer-extension";

RNNDrawer.showDrawer({
  component: {
    name: "CustomDrawer",
    passProps: {
      animationOpenTime: 300,
      animationCloseTime: 300,
      direction: "left",
      dismissWhenTouchOutside: true,
      fadeOpacity: 0.6,
      drawerScreenWidth: "75%" || 445, // Use relative to screen '%' or absolute
      drawerScreenHeight: "100%" || 700,
      style: { // Styles the drawer container, supports any react-native style
        backgroundColor: "red",
      },
      parentComponentId: props.componentId, // Custom prop, will be available in your custom drawer component props
    },
  }
});

RNNDrawer.dismissDrawer();

To navigate from the drawer you must pass the parent componentId and use that to navigate. e.g:

// From drawer component
Navigation.push(parentComponentId, {
  component: {
    name: "CustomScreenFromDrawer",
  },
});

There's a complete and functional example at the example folder, with more thorough explanation on each method.

Props

The props below are used to configure the drawer and are to be used in RNN passProps:. Any aditional props will be passed to your custom drawer component.

Prop Type Optional Default Description
animationOpenTime float Yes 300 Time in milliseconds to execute the drawer opening animation.
animationCloseTime float Yes 300 Time in milliseconds to execute the drawer closing animation.
direction string Yes left Direction to open the collage, one of: ["left", "right", "top", "bottom"].
dismissWhenTouchOutside bool Yes true Should the drawer be dismissed when a click is registered outside?
fadeOpacity number Yes 0.6 Opacity of the screen outside the drawer.
drawerScreenWidth number Yes 0.8 0 - 1, width of drawer in relation to the screen.
drawerScreenHeight number Yes 1 0 - 1, height of drawer in relation to the screen.

SideMenuView

The library also exposes a component which will allow you to open the drawer by either swiping the left or right gutter of the phone. This is achieved by using event listeners to communicate with the RNNDrawer HOC component. To enable this feature wrap your screen with the SideMenuView component. <SideMenuView> is just an enhanced <View> all props are passed down to <View>.

import { SideMenuView } from "react-native-navigation-drawer-extension";

<SideMenuView
  style={{ flex: 1 }}
  drawerName={'CustomDrawer'}
  direction={'right'}
  passProps={{
    animationOpenTime: 300,
    animationCloseTime: 300,
    dismissWhenTouchOutside: true,
    fadeOpacity: 0.6,
    drawerScreenWidth: '75%',
    drawerScreenHeight: '100%',
    parentComponentId: props.componentId,
    style: {
      backgroundColor: 'white', 
    },
  }}
  options={{
    layout: {
      componentBackgroundColor: 'transparent',
    }
 >
  {...}
 </SideMenuView>

Props

Prop Type Optional Default Description
style StyleProp Yes The style of the drawer container.
drawerName string No The name of the drawer component.
direction string Yes left The direction to open the drawer, one of: ["left", "right"].
passProps object Yes The values passed to the drawer. See props in RNNDrawer above.
options Options Yes The options to configure properties of the React Native Navigation native screen. Refer to React Native Navigation's options object.
swipeSensitivity number Yes 0.2 The sensitivity of the swipe to invoke each function.
sideMargin number Yes 15 The size of the gutter for both sides.
sideMarginLeft number Yes The size of the gutter for the left side.
sideMarginRight number Yes The size of the gutter for the right side.

react-native-navigation-drawer-extension's People

Contributors

cinder92 avatar denise-ng avatar dependabot[bot] avatar kyle-ssg avatar lukebrandonfarrell avatar rodriigovieira avatar sturmenta avatar

Watchers

 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.