npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-drawer-addmenu

v1.2.7

Published

React Native Drawer

Downloads

4

Readme

React Native Drawer

Configurable react native pull out drawer. Supports displace, overlay (material design) static (slack style) transitions modes, as well as custom tweens.

Installation

npm install react-native-drawer

Usage

var Drawer = require('react-native-drawer')

var Application = React.createClass({
  closeControlPanel: function(){
    this.refs.drawer.close()
  },
  openControlPanel: function(){
    this.refs.drawer.open()
  },
  render: function() {
    return (
      <Drawer
        ref="drawer"
        content={<ControlPanel />}
        >
        <MainView />
      </Drawer>
    )
  }
})

Examples

Simple

//Parallax Effect (slack style)
<Drawer
  type="static"
  content={<ControlPanel />}
  openDrawerOffset={100}
  styles={{main: {shadowColor: "#000000", shadowOpacity: 0.4, shadowRadius: 3}}}
  tweenHandler={Drawer.tweenPresets.parallax}
  >
    <Main />
</Drawer>

//Material Design Style Drawer
<Drawer
  type="overlay"
  openDrawerOffset={50} //50px gap on the right side of drawer
  panCloseMask={1} //can close with right to left swipe anywhere on screen
  styles={{
    drawer: {
      shadowColor: "#000000",
      shadowOpacity: 0.8,
      shadowRadius: 0,
    }
  }}
  tweenHandler={(ratio) => {
    return {
      drawer: { shadowRadius: Math.min(ratio*5*5, 5) },
      main: { opacity:(2-ratio)/2 },
    }
  }}
  content={<ControlPanel />}
  >
    <Main />
</Drawer>

Props

This module supports a wide range of drawer styles, and hence has a lot of props.

Important
  • content (React.Component) null - Menu component
  • type (String: displace:overlay:static) displace- Type of drawer.
  • openDrawerOffset (Number) 0 - Can either be a integer (pixel value) or decimal (ratio of screen width). Defines the right hand margin when the drawer is open.
  • closedDrawerOffset (Number) 0 - Same as openDrawerOffset, except defines left hand margin when drawer is closed.
  • disabled (Boolean) false - If true the drawer can not be opened and will not respond to pans.
Animation / Tween
  • tweenHandler (Function) null - Takes in the pan ratio (decimal 0 to 1) that represents the tween percent. Returns and object of native props to be set on the constituent views { drawer: {/native props/}, main: {/native props/} }
  • tweenDuration (Integer) 250 - The duration of the open/close animation.
  • tweenEasing (String) linear - A easing type supported by tween-functions
Event Handlers
  • onOpen (Function) - Will be called immediately after the drawer has entered the open state.
  • onClose (Function) - Will be called immediately after the drawer has entered the closed state.
Gestures
  • captureGestures (Boolean) false - If true, will capture all gestures inside of the pan mask. Meaning child buttons and scroll views will not trigger.
  • acceptDoubleTap (Boolean) false - Toggle drawer when double tap occurs within pan mask?
  • acceptTap (Boolean) false - Toggle drawer when any tap occurs within pan mask?
  • acceptPan (Boolean) true - Allow for drawer pan (on touch drag). Set to false to effectively disable the drawer while still allowing programmatic control.
Additional Configurations
  • openDrawerThreshold (Number) .25 - Ratio of screen width that must be travelled to trigger a drawer open/close
  • panOpenMask (Number) .05 - Ratio of screen width that is valid for the start of a pan open action. Make this number small if you need pans to propagate to children.
  • panCloseMask (Number) .25 - Ratio of screen width that is valid for the start of a pan close action. Make this number small if you need pans to propagate to children.
  • relativeDrag (Boolean) true - true -> open/close calculation based on pan dx : false -> calculation based on absolute pan position (i.e. touch location)
  • panStartCompensation (Boolean) false - Should the drawer catch up to the finger drag position?
  • initializeOpen (Boolean) false - Initialize with drawer open?
  • side (String left|right) left - which side the drawer should be on.

Tween Handler

You can achieve pretty much any animation you want using the tween handler with the transformMatrix property. E.G.

tweenHandler={(ratio) => {
  var r0 = -ratio/6
  var r1 = 1-ratio/6
  var t = [
             r1,  r0,  0,  0,
             -r0, r1,  0,  0,
             0,   0,   1,  0,
             0,   0,   0,  1,
          ]
  return {
    main: {
      style: {
        transformMatrix: t,
        opacity: 1 - ratio/2,
      },
    }
  }
}}

Will result in a skewed fade out animation.

warning: Frame rate, and perceived smoothness will vary based on the complexity and speed of the animation. It will likely require some tweaking and compromise to get the animation just right.

Demo

  • git clone https://github.com/rt2zz/react-native-drawer.git
  • cd rn-drawer && npm install
  • Open ``./examples/RNDrawerDemo/RNDrawerDemo.xcodeproject` in xcode
  • command+r (in xcode)

Credits

Component was adapted from and inspired by @khanghoang's RNSideMenu AND @kureevalexey's react-native-side-menu