Skip to content

Commit 4053886

Browse files
Add navigator methods to docs
1 parent 5717e03 commit 4053886

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

readme.md

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _Example_:
8585
#### backHandler
8686
_Default value_: `navigator => navigator.pop()`
8787
Function that is called when user presses back button on Android or makes swipe back on IOS.
88-
If you return `false` from this function on Android app will be minimized
88+
If you return `false` from this function on Android app will be minimized.
8989

9090
_Example_:
9191
```js
@@ -120,11 +120,77 @@ const { width: windowWidth, height: windowHeight } = Dimensions.get('window')
120120
Navigator passes `navigator` object to every screen. With this object you can manage your screens. Also you can get this object with `navigatorRef`.
121121

122122
#### push(screen, props, transitionProps)
123-
Pushes new screen to the stack
123+
Pushes new screen to the stack. Returns `Promise` that is resolved after transition finishes.
124124

125125
_Example_:
126126
```js
127-
// Stack: First
127+
// Stack before: First
128128
navigator.push('Second', {email: 'john@gmail.com'}, {animation: 'bottom'})
129-
// Stack: First, Second
129+
// Stack after: First, Second
130+
```
131+
132+
#### pop(transitionProps)
133+
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.
134+
135+
_Example_:
136+
```js
137+
// Stack before: First, Second
138+
navigator.pop({animation: 'left'})
139+
// Stack after: First
140+
```
141+
142+
#### reset(screen, props, transitionProps)
143+
Resets the whole stack to a new screen. Returns `Promise` that is resolved after transition finishes.
144+
145+
_Example_:
146+
```js
147+
// Stack before: First, Second
148+
navigator.reset('Third', {name: 'John'}, {animation: 'fade'})
149+
// Stack after: Third
150+
```
151+
152+
#### stack
153+
Returns the stack
154+
155+
_Example_:
156+
```js
157+
// Stack before: First, Second
158+
console.log(navigator.stack) // [{id: 'some-id', screen: 'First', props: {name: 'John'}, transitionProps: {animation: 'left', duration: 500, easing: 'ease-in-out'}}]
159+
```
160+
161+
#### popTo(screenId, transitionProps)
162+
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.
163+
164+
_Example_:
165+
```js
166+
// Stack before: First, Second, Third, Fourth
167+
navigator.popTo(navigator.stack[1].id)
168+
// Stack after: First, Second
169+
```
170+
171+
#### resetFrom(screenId, screen, props, transitionProps)
172+
Resets the stack after the certain screen. Returns `Promise` that is resolved after transition finishes.
173+
174+
_Example_:
175+
```js
176+
// Stack before: First, Second, Third, Fourth
177+
navigator.resetFrom(navigator.stack[1].id, 'Fifth', {age: 18})
178+
// Stack after: First, Second, Fifth
179+
```
180+
181+
#### register/unregisterBackHandler
182+
183+
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.
184+
185+
_Example_:
186+
```js
187+
componentDidMount = () => {
188+
this.props.navigator.registerBackHandler(this.onBack)
189+
}
190+
191+
componentWillUnmount = () => {
192+
this.props.navigator.unregisterBackHandler()
193+
}
194+
195+
onBack = navigator => navigator.pop()
130196
```

0 commit comments

Comments
 (0)