Browse Source

edited docs

yogevbd 6 years ago
parent
commit
07cd71adae
4 changed files with 458 additions and 0 deletions
  1. 6
    0
      docs/_sidebar.md
  2. 0
    0
      docs/docs/layout-types.md
  3. 289
    0
      docs/docs/screen-api.md
  4. 163
    0
      docs/docs/top-level-api-migration.md

+ 6
- 0
docs/_sidebar.md View File

@@ -3,3 +3,9 @@
3 3
   - [Working Locally](/docs/WorkingLocally)
4 4
   - [Usage](/docs/Usage)
5 5
 - [API](/api/README)
6
+  - [Top Level](/docs/top-level-api)
7
+  - [Screen](/docs/screen-api)
8
+  - [Layout types](/docs/layout-types)
9
+- [Migration from v1](/api/README)
10
+  - [Top Level](/docs/top-level-api-migration)
11
+  

+ 0
- 0
docs/docs/layout-types.md View File


+ 289
- 0
docs/docs/screen-api.md View File

@@ -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. -->

+ 163
- 0
docs/docs/top-level-api-migration.md View File

@@ -0,0 +1,163 @@
1
+# Top Level API Migration
2
+
3
+In order to make our API homogenous as much as possible, we provide setRoot function that will receive layout of any kind.
4
+
5
+## startTabBasedApp(params) -> setRoot({bottomTabs})
6
+
7
+```js
8
+Navigation.setRoot({
9
+  bottomTabs: {
10
+    children: [{
11
+      stack: {
12
+        children: [{
13
+          component: {
14
+            name: 'example.FirstTabScreen',
15
+            passProps: {
16
+              text: 'This is tab 1'
17
+            }
18
+          }
19
+        }],
20
+        options: {
21
+          bottomTab: {
22
+            title: 'Tab 1',
23
+            icon: require('../images/one.png'),
24
+            testID: 'FIRST_TAB_BAR_BUTTON'
25
+          }
26
+        }
27
+      }
28
+    },
29
+    {
30
+      component: {
31
+        name: 'navigation.playground.TextScreen',
32
+        passProps: {
33
+          text: 'This is tab 2'
34
+        },
35
+        options: {
36
+          bottomTab: {
37
+            title: 'Tab 2',
38
+            icon: require('../images/two.png'),
39
+            testID: 'SECOND_TAB_BAR_BUTTON'
40
+          }
41
+        }
42
+      }
43
+    }]
44
+  }
45
+});
46
+```
47
+
48
+## startSingleScreenApp(params) -> setRoot({stack})
49
+
50
+Change your app root into an app based on a single screen (like the iOS Calendar or Settings app). The screen will receive its own navigation stack with a native nav bar
51
+
52
+```js
53
+Navigation.setRoot({
54
+  stack: {
55
+    children: [{
56
+      component: {
57
+        name: 'example.WelcomeScreen',
58
+        passProps: {
59
+          text: 'stack with one child'
60
+        }
61
+      }
62
+    }],
63
+    options: {
64
+      topBar: {
65
+        title: {
66
+          text: 'Welcome screen'
67
+        }
68
+      }
69
+    }
70
+  }
71
+});
72
+```
73
+
74
+## showModal(params = {}) -> showModal(layout = {})
75
+
76
+Show a screen as a modal.
77
+
78
+```js
79
+Navigation.showModal({
80
+  stack: {
81
+    children: [{
82
+      component: {
83
+        name: 'example.ModalScreen',
84
+        passProps: {
85
+          text: 'stack with one child'
86
+        },
87
+        options: {
88
+          topBar: {
89
+            title: {
90
+              text: 'Modal with stack'
91
+            }
92
+          }
93
+        }
94
+      }
95
+    }]
96
+  }
97
+});
98
+```
99
+
100
+## dismissModal(params = {}) -> dismissModal(componentId)
101
+
102
+Dismiss the current modal.
103
+
104
+```js
105
+Navigation.dismissModal(this.props.componentId);
106
+```
107
+
108
+## dismissAllModals(params = {}) -> dismissAllModals()
109
+
110
+Dismiss all the current modals at the same time.
111
+
112
+```js
113
+Navigation.dismissAllModals();
114
+```
115
+
116
+<!-- ## showLightBox(params = {}) - Use showOverlay
117
+
118
+Show a screen as a lightbox.
119
+
120
+```js
121
+Navigation.showLightBox({
122
+  screen: 'example.LightBoxScreen', // unique ID registered with Navigation.registerScreen
123
+  passProps: {}, // simple serializable object that will pass as props to the lightbox (optional)
124
+  style: {
125
+    backgroundBlur: 'dark', // 'dark' / 'light' / 'xlight' / 'none' - the type of blur on the background
126
+    backgroundColor: '#ff000080', // tint color for the background, you can specify alpha here (optional)
127
+    tapBackgroundToDismiss: true // dismisses LightBox on background taps (optional)
128
+  }
129
+});
130
+``` -->
131
+
132
+<!-- ## dismissLightBox(params = {})
133
+
134
+Dismiss the current lightbox.
135
+
136
+```js
137
+Navigation.dismissLightBox();
138
+``` -->
139
+
140
+<!-- ## handleDeepLink(params = {})
141
+
142
+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.
143
+
144
+```js
145
+Navigation.handleDeepLink({
146
+  link: 'link/in/any/format',
147
+  payload: '' // (optional) Extra payload with deep link
148
+});
149
+``` -->
150
+
151
+<!-- ## registerScreen(screenID, generator)
152
+
153
+This is an internal function you probably don't want to use directly. If your screen components extend `Screen` directly (`import { Screen } from 'react-native-navigation'`), you can register them directly with `registerScreen` instead of with `registerComponent`. The main benefit of using `registerComponent` is that it wraps your regular screen component with a `Screen` automatically.
154
+
155
+```js
156
+Navigation.registerScreen('example.AdvancedScreen', () => AdvancedScreen);
157
+```
158
+
159
+## getCurrentlyVisibleScreenId()
160
+
161
+In some cases you might need the id of the currently visible screen. This method returns the unique id of the currently visible screen:
162
+`const visibleScreenInstanceId = await Navigation.getCurrentlyVisibleScreenId()`
163
+In order to have any use of this method, you'd need to map instanceId to screens your self. -->