Skip to content

Commit 3085b35

Browse files
hramosFacebook Github Bot 5
authored andcommitted
Initial stab at NavigationExperimental tutorial
Summary: Add a NavigationExperimental section to the Navigation guide. ![navexp](https://cloud.githubusercontent.com/assets/165856/16355280/120e7d38-3a67-11e6-9567-51c19c249fdf.png) Closes #8431 Differential Revision: D3493158 Pulled By: JoelMarcey fbshipit-source-id: 5e9646c3abf97f5cce6f5ba5b3d10853aa84ee8e
1 parent 6b2a49e commit 3085b35

File tree

5 files changed

+376
-91
lines changed

5 files changed

+376
-91
lines changed

Libraries/Components/Navigation/NavigatorIOS.ios.js

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,17 @@ type Event = Object;
9393
*/
9494

9595
/**
96-
* `NavigatorIOS` is a wrapper around UIKit navigation, enabling you to
97-
* implement back-swipe functionality in your iOS app. Take a look at
96+
* `NavigatorIOS` is a wrapper around
97+
* [`UINavigationController`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/),
98+
* enabling you to implement a navigation stack. It works exactly the same as it
99+
* would on a native app using `UINavigationController`, providing the same
100+
* animations and behavior from UIKIt.
101+
*
102+
* As the name implies, it is only available on iOS. Take a look at
98103
* [`Navigator`](/docs/navigator.html) for a similar solution for your
99-
* cross-platform needs.
104+
* cross-platform needs, or check out
105+
* [react-native-navigation](https://github.com/wix/react-native-navigation), a
106+
* component that aims to provide native navigation on both iOS and Android.
100107
*
101108
* To set up the navigator, provide the `initialRoute` prop with a route
102109
* object. A route object is used to describe each scene that your app
@@ -106,53 +113,68 @@ type Event = Object;
106113
* import React, { Component } from 'react';
107114
* import { NavigatorIOS, Text } from 'react-native';
108115
*
109-
* class NavvyIOS extends Component {
116+
* export default class NavigatorIOSApp extends Component {
110117
* render() {
111118
* return (
112119
* <NavigatorIOS
113120
* initialRoute={{
114-
* component: MyView,
115-
* title: 'My View Title',
121+
* component: MyScene,
122+
* title: 'My Initial Scene',
116123
* }}
117124
* style={{flex: 1}}
118125
* />
119126
* );
120127
* }
121128
* }
122129
*
123-
* class MyView extends Component {
130+
* class MyScene extends Component {
131+
* static propTypes = {
132+
* title: PropTypes.string.isRequired,
133+
* navigator: PropTypes.object.isRequired,
134+
* }
135+
*
136+
* constructor(props, context) {
137+
* super(props, context);
138+
* this._onForward = this._onForward.bind(this);
139+
* this._onBack = this._onBack.bind(this);
140+
* }
141+
*
142+
* _onForward() {
143+
* this.props.navigator.push({
144+
* title: 'Scene ' + nextIndex,
145+
* });
146+
* }
147+
*
124148
* render() {
125-
* return(
126-
* <Text style={{marginTop: 200, alignSelf: 'center'}}>
127-
* See you on the other nav!
128-
* </Text>
129-
* );
149+
* return (
150+
* <View>
151+
* <Text>Current Scene: { this.props.title }</Text>
152+
* <TouchableHighlight onPress={this._onForward}>
153+
* <Text>Tap me to load the next scene</Text>
154+
* </TouchableHighlight>
155+
* </View>
156+
* )
130157
* }
131158
* }
132159
* ```
133160
*
134-
* In this code, the navigator sets its title and renders `MyView`. The
135-
* component specified in `initialRoute` will receive a `route` prop and a
136-
* `navigator` prop representing the navigator.
161+
* In this code, the navigator renders the component specified in initialRoute,
162+
* which in this case is `MyScene`. This component will receive a `route` prop
163+
* and a `navigator` prop representing the navigator. The navigator's navigation
164+
* bar will render the title for the current scene, "My Initial Scene".
137165
*
138166
* You can optionally pass in a `passProps` property to your `initialRoute`.
139167
* `NavigatorIOS` passes this in as props to the rendered component:
140168
*
141169
* ```
142170
* initialRoute={{
143-
* component: MyView,
144-
* title: 'Foo This',
171+
* component: MyScene,
172+
* title: 'My Initial Scene',
145173
* passProps: { myProp: 'foo' }
146174
* }}
147175
* ```
148176
*
149-
* You can then access the props passed in:
150-
*
151-
* ```
152-
* <Text style={{marginTop: 200, alignSelf: 'center'}}>
153-
* See you on the other nav {this.props.myProp}!
154-
* </Text>
155-
* ```
177+
* You can then access the props passed in via `{this.props.myProp}`.
156178
*
157179
* #### Handling Navigation
158180
*
@@ -254,6 +276,7 @@ type Event = Object;
254276
*
255277
* In the example above the navigation bar color is changed when the new route
256278
* is pushed.
279+
*
257280
*/
258281
var NavigatorIOS = React.createClass({
259282

Libraries/CustomComponents/Navigator/Navigator.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ var GESTURE_ACTIONS = [
130130

131131
/**
132132
* `Navigator` handles the transition between different scenes in your app.
133-
* You should consider using this component instead of `NavigatorIOS` if you're
134-
* building a cross-platform app. `Navigator` is implemented in JavaScript
135-
* whereas `NavigatorIOS` is a wrapper around `UINavigationController`.
133+
* It is implemented in JavaScript and is available on both iOS and Android. If
134+
* you are targeting iOS only, you may also want to consider using
135+
* [`NavigatorIOS`](docs/navigatorios.html) as it leverages native UIKit
136+
* navigation.
136137
*
137138
* To set up the `Navigator` you provide one or more objects called routes,
138139
* to identify each scene. You also provide a `renderScene` function that
@@ -142,13 +143,13 @@ var GESTURE_ACTIONS = [
142143
* import React, { Component } from 'react';
143144
* import { Text, Navigator } from 'react-native';
144145
*
145-
* class NavAllDay extends Component {
146+
* export default class NavAllDay extends Component {
146147
* render() {
147148
* return (
148149
* <Navigator
149-
* initialRoute={{name: 'Awesome Scene'}}
150+
* initialRoute={{ title: 'Awesome Scene', index: 0 }}
150151
* renderScene={(route, navigator) =>
151-
* <Text>Hello {route.name}!</Text>
152+
* <Text>Hello {route.title}!</Text>
152153
* }
153154
* style={{padding: 100}}
154155
* />
@@ -158,8 +159,8 @@ var GESTURE_ACTIONS = [
158159
* ```
159160
*
160161
* In the above example, `initialRoute` is used to specify the first route. It
161-
* contains a `name` property that identifies the route. The `renderScene`
162-
* prop returns a function that displays text based on the route's name.
162+
* contains a `title` property that identifies the route. The `renderScene`
163+
* prop returns a function that displays text based on the route's title.
163164
*
164165
* ### Additional Scenes
165166
*
@@ -169,8 +170,8 @@ var GESTURE_ACTIONS = [
169170
* ```
170171
* render() {
171172
* const routes = [
172-
* {name: 'First Scene', index: 0},
173-
* {name: 'Second Scene', index: 1},
173+
* {title: 'First Scene', index: 0},
174+
* {title: 'Second Scene', index: 1},
174175
* ];
175176
* return (
176177
* <Navigator
@@ -184,7 +185,7 @@ var GESTURE_ACTIONS = [
184185
* navigator.pop();
185186
* }
186187
* }}>
187-
* <Text>Hello {route.name}!</Text>
188+
* <Text>Hello {route.title}!</Text>
188189
* </TouchableHighlight>
189190
* }
190191
* style={{padding: 100}}
@@ -256,6 +257,12 @@ var GESTURE_ACTIONS = [
256257
* This sets up a left navigator bar button that's visible on scenes after the
257258
* the first one. When the button is tapped the navigator is popped.
258259
*
260+
* Another type of navigation bar, with breadcrumbs, is provided by
261+
* `Navigator.BreadcrumbNavigationBar`. You can also provide your own navigation
262+
* bar by passing it through the `navigationBar` prop. See the
263+
* [UIExplorer](https://github.com/facebook/react-native/tree/master/Examples/UIExplorer)
264+
* demo to try out both built-in navigation bars out and see how to use them.
265+
*
259266
* ### Scene Transitions
260267
*
261268
* To change the animation or gesture properties of the scene, provide a

0 commit comments

Comments
 (0)