- Easiest way to implement a drawer via react-native-router-flux without any third party library.
The files in the repository is having all the code to implement the react-native-router-flux drawer.
-
Routes.js
-
HomeScreen.js
-
SecondScreen.js
-
Sidebar.js
-
Routes.js ...... It includes all the Routes(scenes), and the builtin "Drawer" of the Router-Flux library.
-
HomeScreen.js ...... It includes a component with boilerplate and having the button to show the drawer.
-
SecondScreen.js ...... It is just for the purpose to know about the normal routing behaviour of the library between different scenes.
-
Sidebar.js ...... The component which is used for the "Drawer Content".
- First you have to install the library of react-native-router-flux through npm. Click here to get React-Native-Router-Flux.
- Make scenes per your requirements but one scene is must that should to be made in order to implement the Drawer. I had made HomeScreen and implemented the drawer in that scene.
- Make a folder by the name of "Routes", add a file with the name of Routes.js already given in repository, Define all the scenes along with their keys and components.
- Include Drawer in the import statement of the library as ( "import {Router,Scene,Drawer}from 'react-native-router-flux" ) and then whatever scene you want to add the "Drawer", just wrap it with the "Drawer Component" along with the props.
- The scene on which you have wrapped the Drawer Component, go to that scene, make a button and add the following code example ( onPress={()=> Actions.drawerOpen()} or onPress={()=> Actions.drawerToggle()} ), for this first you need to import Actions from react-native-router-flux.
position ="left" or "right"
drawerWidth ={200}
contentComponent ={ <your component that you have made to display on the drawer> }
key="any name you want"
type: "replace", //comment (not to move by IOS gestures.)
open:{false} //comment (first it would be close, by pressing button it will pop up.)