Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sergeyshpadyrev/react-native-easy-router
Screen navigation for React Native
https://github.com/sergeyshpadyrev/react-native-easy-router
Last synced: 6 days ago
JSON representation
Screen navigation for React Native
- Host: GitHub
- URL: https://github.com/sergeyshpadyrev/react-native-easy-router
- Owner: sergeyshpadyrev
- License: mit
- Created: 2018-05-18T07:57:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-05T10:14:47.000Z (over 4 years ago)
- Last Synced: 2024-04-30T06:01:01.533Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 349 KB
- Stars: 154
- Watchers: 10
- Forks: 16
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-react-native - react-native-easy-router ★78 - React Native router with easy-to-use API (Components / Navigation)
- awesome-react-native - react-native-easy-router ★78 - React Native router with easy-to-use API (Components / Navigation)
- awesome-react-native - react-native-easy-router ★78 - React Native router with easy-to-use API (Components / Navigation)
- awesome-react-native - react-native-easy-router ★78 - React Native router with easy-to-use API (Components / Navigation)
README
# React Native Easy Router
[![npm version](https://img.shields.io/npm/v/react-native-easy-router)](https://badge.fury.io/js/react-native-easy-router)
[![License: MIT](https://img.shields.io/npm/l/react-native-easy-router)](https://opensource.org/licenses/MIT)React Native Easy Router is an easy-to-use and performant screen navigation library for React Native
**If this project has helped you out, please support us with a star** 🌟
## Installation
```
npm install --save react-native-easy-router## or
yarn add react-native-easy-router
```## Usage
```js
import { AppRegistry, Text, View } from 'react-native'
import { name } from './app.json'
import React from 'react'
import Navigator from 'react-native-easy-router'const First = ({ navigator }) => (
First screen
navigator.push('Second', { name: 'John' })}>Go forward
)const Second = ({ navigator, name }) => (
Second screen
Hello {name}!
navigator.pop()}>Go back
)const Application = () =>
AppRegistry.registerComponent(name, () => Application)
```
You can look at [example](https://github.com/sergeyshpadyrev/react-native-easy-router/tree/master/example) for better understanding## Documentation
### Navigator properties
#### screens (_required_)
Screen components keyed by screen name_Example_:
```js
Welcome }}/>
```#### initialStack (_required_)
Initial stack can be a first screen name, an array of screen names or even array of screen objects that are are returned from `navigator.stack` or `onStackUpdate`.
_Examples_:
```js```
or
```js```
or
```js```
#### onStackUpdate
Callback that is called when stack updates_Example_:
```js
console.log(stack, previousStack)}/>
```#### backHandler
_Default value_: `navigator => navigator.pop()`
Function that is called when user presses back button on Android or makes swipe back on IOS.
If you return `false` from this function on Android app will be minimized._Example_:
```js
navigator.pop()}/>
```#### navigatorRef
Callback that is called on navigator initialization with `navigator` reference so you can manage your navigator from the outside._Example_:
```js
(this.navigator = ref)}/>
```#### animations
Custom animations that you can use for transitions. Because navigator uses native transitions you can use only 'transform' animations. You can use this animation with any `navigator` method._Example_:
```js
import { Dimensions } from 'react-native'
const { width: windowWidth, height: windowHeight } = Dimensions.get('window')```
### Navigator methods
Navigator passes `navigator` object to every screen. With this object you can manage your screens. Also you can get this object with `navigatorRef`.#### push(screen, props, transitionProps)
Pushes new screen to the stack. Returns `Promise` that is resolved after transition finishes._Example_:
```js
// Stack before: First
navigator.push('Second', {email: '[email protected]'}, {animation: 'bottom'})
// Stack after: First, Second
```#### pop(transitionProps)
Pops last screen from the stack. If `transitionProps` are not provided uses those transitionProps that this screen was pushed with. Returns `Promise` that is resolved after transition finishes._Example_:
```js
// Stack before: First, Second
navigator.pop({animation: 'left'})
// Stack after: First
```#### reset(screen, props, transitionProps)
Resets the whole stack to a new screen. Returns `Promise` that is resolved after transition finishes._Example_:
```js
// Stack before: First, Second
navigator.reset('Third', {name: 'John'}, {animation: 'fade'})
// Stack after: Third
```#### stack
Returns the stack_Example_:
```js
// Stack before: First, Second
console.log(navigator.stack) // [{id: 'some-id', screen: 'First', props: {name: 'John'}, transitionProps: {animation: 'left', duration: 500, easing: 'ease-in-out'}}]
```#### popTo(screenId, transitionProps)
Pops all screens after the certain screen. If `transitionProps` are not provided uses those transitionProps that this screen was pushed with. Returns `Promise` that is resolved after transition finishes._Example_:
```js
// Stack before: First, Second, Third, Fourth
navigator.popTo(navigator.stack[1].id)
// Stack after: First, Second
```#### resetFrom(screenId, screen, props, transitionProps)
Resets the stack after the certain screen. Returns `Promise` that is resolved after transition finishes._Example_:
```js
// Stack before: First, Second, Third, Fourth
navigator.resetFrom(navigator.stack[1].id, 'Fifth', {age: 18})
// Stack after: First, Second, Fifth
```#### register/unregisterBackHandler
If you want to handle Android hardware back press and IOS swipe back on the certain screen you can use this methods. If you return `false` from callback function on Android app will be minimized.
_Example_:
```js
componentDidMount = () => {
this.props.navigator.registerBackHandler(this.onBack)
}componentWillUnmount = () => {
this.props.navigator.unregisterBackHandler()
}onBack = navigator => navigator.pop()
```### Transition props
#### animation
_Default value_: `'right'`One of default animations: `right`, `left`, `top`, `bottom`, `none`, `fade`. Or one of custom animations provided to navigator by `animations` property.
#### duration
_Default value_: `250`Duration of transition in milliseconds. Not applied to `none` animation.
#### easing
_Default value_: `'ease-in-out'`One of easings from [this table](https://github.com/oblador/react-native-animatable#properties). Not applied to `none` animation.