|
@@ -0,0 +1,289 @@
|
|
1
|
+# Screen API
|
|
2
|
+
|
|
3
|
+This API is relevant when in a screen component context - it allows a screen to push other screens, pop screens, change its navigator style, etc. Access to this API is available through the `Navigation` module and expect to receive the current presented component id from screen `props.componentId`.\
|
|
4
|
+Component must initialize in stack in order to push another component.
|
|
5
|
+
|
|
6
|
+## push(componentId, layout)
|
|
7
|
+
|
|
8
|
+Push a new screen into this screen's navigation stack.
|
|
9
|
+
|
|
10
|
+```js
|
|
11
|
+Navigation.push(this.props.componentId, {
|
|
12
|
+ stack: {
|
|
13
|
+ children: [{
|
|
14
|
+ component: {
|
|
15
|
+ name: 'example.PushedScreen',
|
|
16
|
+ passProps: {
|
|
17
|
+ text: 'Pushed screen'
|
|
18
|
+ },
|
|
19
|
+ options: {
|
|
20
|
+ topBar: {
|
|
21
|
+ title: {
|
|
22
|
+ text: 'Pushed screen title'
|
|
23
|
+ }
|
|
24
|
+ }
|
|
25
|
+ }
|
|
26
|
+ }
|
|
27
|
+ }]
|
|
28
|
+ }
|
|
29
|
+});
|
|
30
|
+```
|
|
31
|
+
|
|
32
|
+## pop(componentId)
|
|
33
|
+
|
|
34
|
+Pop the top screen from this screen's navigation stack.
|
|
35
|
+
|
|
36
|
+```js
|
|
37
|
+Navigation.pop(this.props.componentId);
|
|
38
|
+```
|
|
39
|
+
|
|
40
|
+## popToRoot(componentId)
|
|
41
|
+
|
|
42
|
+Pop all the screens until the root from this screen's navigation stack.
|
|
43
|
+
|
|
44
|
+```js
|
|
45
|
+Navigation.popToRoot(this.props.componentId);
|
|
46
|
+```
|
|
47
|
+
|
|
48
|
+<!-- ## resetTo(params)
|
|
49
|
+
|
|
50
|
+Reset the screen's navigation stack to a new screen (the stack root is changed).
|
|
51
|
+
|
|
52
|
+```js
|
|
53
|
+this.props.navigator.resetTo({
|
|
54
|
+ screen: 'example.ScreenThree', // unique ID registered with Navigation.registerScreen
|
|
55
|
+ title: undefined, // navigation bar title of the pushed screen (optional)
|
|
56
|
+ passProps: {}, // simple serializable object that will pass as props to the pushed screen (optional)
|
|
57
|
+ animated: true, // does the resetTo have transition animation or does it happen immediately (optional)
|
|
58
|
+ animationType: 'fade', // 'fade' (for both) / 'slide-horizontal' (for android) does the resetTo have different transition animation (optional)
|
|
59
|
+ navigatorStyle: {}, // override the navigator style for the pushed screen (optional)
|
|
60
|
+ navigatorButtons: {} // override the nav buttons for the pushed screen (optional)
|
|
61
|
+});
|
|
62
|
+``` -->
|
|
63
|
+
|
|
64
|
+## showModal(layout = {})
|
|
65
|
+
|
|
66
|
+Show a screen as a modal.
|
|
67
|
+
|
|
68
|
+```js
|
|
69
|
+Navigation.showModal({
|
|
70
|
+ stack: {
|
|
71
|
+ children: [{
|
|
72
|
+ component: {
|
|
73
|
+ name: 'example.ModalScreen',
|
|
74
|
+ passProps: {
|
|
75
|
+ text: 'stack with one child'
|
|
76
|
+ },
|
|
77
|
+ options: {
|
|
78
|
+ topBar: {
|
|
79
|
+ title: {
|
|
80
|
+ text: 'Modal'
|
|
81
|
+ }
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+ }
|
|
85
|
+ }]
|
|
86
|
+ }
|
|
87
|
+});
|
|
88
|
+```
|
|
89
|
+
|
|
90
|
+## dismissModal(componentId)
|
|
91
|
+
|
|
92
|
+Dismiss the current modal.
|
|
93
|
+
|
|
94
|
+```js
|
|
95
|
+Navigation.dismissModal(this.props.componentId);
|
|
96
|
+```
|
|
97
|
+
|
|
98
|
+## dismissAllModals()
|
|
99
|
+
|
|
100
|
+Dismiss all the current modals at the same time.
|
|
101
|
+
|
|
102
|
+```js
|
|
103
|
+Navigation.dismissAllModals();
|
|
104
|
+```
|
|
105
|
+
|
|
106
|
+## showOverlay(layout = {})
|
|
107
|
+
|
|
108
|
+Show component as overlay.
|
|
109
|
+
|
|
110
|
+```js
|
|
111
|
+Navigation.showOverlay({
|
|
112
|
+ component: {
|
|
113
|
+ name: 'example.Overlay',
|
|
114
|
+ options: {
|
|
115
|
+ overlay: {
|
|
116
|
+ interceptTouchOutside: true
|
|
117
|
+ }
|
|
118
|
+ }
|
|
119
|
+ }
|
|
120
|
+});
|
|
121
|
+```
|
|
122
|
+
|
|
123
|
+## dismissOverlay(componentId)
|
|
124
|
+
|
|
125
|
+Dismiss overlay matching the overlay componentId.
|
|
126
|
+
|
|
127
|
+```js
|
|
128
|
+Navigation.dismissOverlay(this.props.componentId);
|
|
129
|
+```
|
|
130
|
+
|
|
131
|
+<!-- ## handleDeepLink(params = {})
|
|
132
|
+
|
|
133
|
+Trigger a deep link within the app. See [deep links](https://wix.github.io/react-native-navigation/#/deep-links) for more details about how screens can listen for deep link events.
|
|
134
|
+
|
|
135
|
+```js
|
|
136
|
+this.props.navigator.handleDeepLink({
|
|
137
|
+ link: "chats/2349823023" // the link string (required)
|
|
138
|
+});
|
|
139
|
+```
|
|
140
|
+
|
|
141
|
+> `handleDeepLink` can also be called statically:
|
|
142
|
+```js
|
|
143
|
+ import {Navigation} from 'react-native-navigation';
|
|
144
|
+ Navigation.handleDeepLink(...);
|
|
145
|
+``` -->
|
|
146
|
+
|
|
147
|
+## setOptions(componentId, options = {})
|
|
148
|
+
|
|
149
|
+Set options dynamically for component.
|
|
150
|
+
|
|
151
|
+```js
|
|
152
|
+Navigation.setOptions(this.props.componentId, {
|
|
153
|
+ topBar: {
|
|
154
|
+ visible: true,
|
|
155
|
+ title: {
|
|
156
|
+ text: 'Title'
|
|
157
|
+ }
|
|
158
|
+ },
|
|
159
|
+ bottomTabs: {
|
|
160
|
+
|
|
161
|
+ },
|
|
162
|
+ bottomTab: {
|
|
163
|
+
|
|
164
|
+ },
|
|
165
|
+ sideMenu: {
|
|
166
|
+
|
|
167
|
+ },
|
|
168
|
+ overlay: {
|
|
169
|
+
|
|
170
|
+ }
|
|
171
|
+});
|
|
172
|
+```
|
|
173
|
+
|
|
174
|
+<!-- ## toggleDrawer(params = {})
|
|
175
|
+
|
|
176
|
+Toggle the side menu drawer assuming you have one in your app.
|
|
177
|
+
|
|
178
|
+```js
|
|
179
|
+this.props.navigator.toggleDrawer({
|
|
180
|
+ side: 'left', // the side of the drawer since you can have two, 'left' / 'right'
|
|
181
|
+ animated: true, // does the toggle have transition animation or does it happen immediately (optional)
|
|
182
|
+ to: 'open' // optional, 'open' = open the drawer, 'closed' = close it, missing = the opposite of current state
|
|
183
|
+});
|
|
184
|
+``` -->
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+<!-- ## setOnNavigatorEvent(callback)
|
|
188
|
+
|
|
189
|
+Set a handler for navigator events (like nav button press). This would normally go in your component constructor.
|
|
190
|
+Can not be used in conjuction with `addOnNavigatorEvent`.
|
|
191
|
+
|
|
192
|
+```js
|
|
193
|
+// this.onNavigatorEvent will be our handler
|
|
194
|
+this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
|
|
195
|
+```
|
|
196
|
+
|
|
197
|
+## addOnNavigatorEvent(callback)
|
|
198
|
+
|
|
199
|
+Add a handler for navigator events (like nav button press). This would normally go in your component constructor.
|
|
200
|
+If you choose to use `addOnNavigatorEvent` instead of `setOnNavigatorEvent` you will be able to add multiple handlers.
|
|
201
|
+Bear in mind that you can't use both `addOnNavigatorEvent` and `setOnNavigatorEvent`.
|
|
202
|
+`addOnNavigatorEvent` returns a function, that once called will remove the registered handler. -->
|
|
203
|
+
|
|
204
|
+<!-- # Screen Visibility
|
|
205
|
+
|
|
206
|
+`const isVisible = await this.props.navigator.screenIsCurrentlyVisible()`
|
|
207
|
+
|
|
208
|
+## Listen visibility events in onNavigatorEvent handler
|
|
209
|
+
|
|
210
|
+```js
|
|
211
|
+export default class ExampleScreen extends Component {
|
|
212
|
+ constructor(props) {
|
|
213
|
+ super(props);
|
|
214
|
+ this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
|
|
215
|
+ }
|
|
216
|
+ onNavigatorEvent(event) {
|
|
217
|
+ switch(event.id) {
|
|
218
|
+ case 'willAppear':
|
|
219
|
+ break;
|
|
220
|
+ case 'didAppear':
|
|
221
|
+ break;
|
|
222
|
+ case 'willDisappear':
|
|
223
|
+ break;
|
|
224
|
+ case 'didDisappear':
|
|
225
|
+ break;
|
|
226
|
+ case 'willCommitPreview':
|
|
227
|
+ break;
|
|
228
|
+ }
|
|
229
|
+ }
|
|
230
|
+}
|
|
231
|
+```
|
|
232
|
+
|
|
233
|
+## Listen to visibility events globally
|
|
234
|
+
|
|
235
|
+```js
|
|
236
|
+import {ScreenVisibilityListener as RNNScreenVisibilityListener} from 'react-native-navigation';
|
|
237
|
+
|
|
238
|
+export class ScreenVisibilityListener {
|
|
239
|
+
|
|
240
|
+ constructor() {
|
|
241
|
+ this.listener = new RNNScreenVisibilityListener({
|
|
242
|
+ didAppear: ({screen, startTime, endTime, commandType}) => {
|
|
243
|
+ console.log('screenVisibility', `Screen ${screen} displayed in ${endTime - startTime} millis after [${commandType}]`);
|
|
244
|
+ }
|
|
245
|
+ });
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ register() {
|
|
249
|
+ this.listener.register();
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ unregister() {
|
|
253
|
+ if (this.listener) {
|
|
254
|
+ this.listener.unregister();
|
|
255
|
+ this.listener = null;
|
|
256
|
+ }
|
|
257
|
+ }
|
|
258
|
+}
|
|
259
|
+```
|
|
260
|
+
|
|
261
|
+# Listening to tab selected events
|
|
262
|
+In order to listen to `bottomTabSelected` event, set an `onNavigatorEventListener` on screens that are pushed to BottomTab. The event is dispatched to the top most screen pushed to the selected tab's stack.
|
|
263
|
+
|
|
264
|
+```js
|
|
265
|
+export default class ExampleScreen extends Component {
|
|
266
|
+ constructor(props) {
|
|
267
|
+ super(props);
|
|
268
|
+ this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
|
|
269
|
+ }
|
|
270
|
+
|
|
271
|
+ onNavigatorEvent(event) {
|
|
272
|
+ if (event.id === 'bottomTabSelected') {
|
|
273
|
+ console.log('Tab selected!');
|
|
274
|
+ }
|
|
275
|
+ if (event.id === 'bottomTabReselected') {
|
|
276
|
+ console.log('Tab reselected!');
|
|
277
|
+ }
|
|
278
|
+ }
|
|
279
|
+}
|
|
280
|
+```
|
|
281
|
+
|
|
282
|
+# Peek and pop (3D touch)
|
|
283
|
+
|
|
284
|
+react-native-navigation supports the [Peek and pop](
|
|
285
|
+https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/Adopting3DTouchOniPhone/#//apple_ref/doc/uid/TP40016543-CH1-SW3) feature by setting a react view reference as a `previewView` parameter when doing a push, more options are available in the `push` section.
|
|
286
|
+
|
|
287
|
+You can define actions and listen for interactions on the pushed screen with the `PreviewActionPress` event.
|
|
288
|
+
|
|
289
|
+Previewed screens will have the prop `isPreview` that can be used to render different things when the screen is in the "Peek" state and will then recieve a navigator event of `willCommitPreview` when in the "Pop" state. -->
|