diff --git a/releases/0.29/css/react-native.css b/releases/0.29/css/react-native.css index 4e8d3694689..1d7dd728018 100644 --- a/releases/0.29/css/react-native.css +++ b/releases/0.29/css/react-native.css @@ -1240,7 +1240,7 @@ div[data-twttr-id] iframe { .methodTitle { font-weight: bold; font-size: 24px; - color: #E9967A; + color: #2F9C0A; } .compactProps .methodTitle { diff --git a/releases/0.29/docs/navigator-comparison.html b/releases/0.29/docs/navigator-comparison.html index 4e25e9fe478..66c86eda34c 100644 --- a/releases/0.29/docs/navigator-comparison.html +++ b/releases/0.29/docs/navigator-comparison.html @@ -1,9 +1,43 @@ -Navigation – React Native | A framework for building native apps using React

Navigation #

Edit on GitHub

Mobile apps rarely consist of just one screen or scene. As soon as you add a second scene to your app, you will have to take into consideration how the user will navigate from one scene to the other.

Navigators in React Native allow you to push and pop scenes in a master/detail stack, or to pop up modal scenes. Navigators handle the transitions between scenes, and also maintain the navigational state of your application.

If you are just getting started with React Native, you will probably want to start with the Navigator component.

Navigator #

Navigator is a cross-platform implementation of a navigation stack, so it works on both iOS and Android. It is easy to customize and includes simple navigation bars.

<Navigator - initialRoute={{ title: 'My Initial Scene', index: 0}} +Navigation – React Native | A framework for building native apps using React

Navigation #

Edit on GitHub

Mobile apps rarely consist of just one scene (another word for screen). As soon as you add a second scene to your app, you will have to take into consideration how the user will navigate from one scene to the other.

You can use navigators to transition between multiple scenes. These transitions can be typical side-to-side animations down a master/detail stack, or vertical modal popups.

Navigator #

React Native has several built-in navigation components, but for your first app you will probably want to use Navigator. It provides a JavaScript implementation of a navigation stack, so it works on both iOS and Android and is easy to customize.

Something you will encounter a lot when dealing with navigation is the concept of routes. A route is an object that contains information about a scene. It is used to provide all the context that the navigator's renderScene function needs to render a scene. A basic Navigator implementation may look like this:

<Navigator + initialRoute={{ title: 'My Initial Scene', index: 0 }} renderScene={(route, navigator) => { - // We'll get to this function soon. - }} -/>

Something you will encounter a lot when dealing with navigation is the concept of routes. A route is an object that contains information about a scene. It is used to provide all the context the renderScene function needs to render a scene.

The push and pop functions provided by Navigator can be used to push and pop routes into the navigation stack. A more complete example that demonstrates the pushing and popping of routes could therefore look something like this:

class MyScene extends Component { + <MyScene title={route.title} /> + }} +/>

The above example will display a single scene, but in order to push a new scene onto screen you will need to learn about push and pop. These two methods are provided by the navigator object that is passed to your renderScene function. They can be used, as you may have realized, to push and pop routes into your navigation stack.

A more complete example that demonstrates the pushing and popping of routes could therefore look something like this:

import React, { Component, PropTypes } from 'react'; +import { Navigator, Text, TouchableHighlight, View } from 'react-native'; + +export default class SimpleNavigationApp extends Component { + render() { + return ( + <Navigator + initialRoute={{ title: 'My Initial Scene', index: 0 }} + renderScene={(route, navigator) => + <MyScene + title={route.title} + + // Function to call when a new scene should be displayed + onForward={ () => { + const nextIndex = route.index + 1; + navigator.push({ + title: 'Scene ' + nextIndex, + index: nextIndex, + }); + }} + + // Function to call to go back to the previous scene + onBack={() => { + if (route.index > 0) { + navigator.pop(); + } + }} + /> + } + /> + ) + } +} + +class MyScene extends Component { static propTypes = { title: PropTypes.string.isRequired, onForward: PropTypes.func.isRequired, @@ -22,40 +56,30 @@ </View> ) } -} - -class SimpleNavigationApp extends Component { - render() { - return ( - <Navigator - initialRoute={{ title: 'My Initial Scene', index: 0 }} - renderScene={(route, navigator) => - <MyScene - title={route.title} - onForward={ () => { - const nextIndex = route.index + 1; - navigator.push({ - title: 'Scene ' + nextIndex, - index: nextIndex, - }); - }} - onBack={() => { - if (route.index > 0) { - navigator.pop(); - } - }} - /> - } - /> - ) - } -}

In this example, the MyScene component is passed the title of the current route via the title prop. It displays two tappable components that call the onForward and onBack functions passed through its props, which in turn will call navigator.push() and navigator.pop() as needed.

While this is a very basic example, it can easily be adapted to render an entirely different component based on the route that is passed to the renderScene function. Navigator will push new scenes from the right by default, and you can control this behavior by using the configureScene function. Check out the Navigator API reference to learn more.

NavigatorIOS #

If you are targeting iOS only, you may also want to consider using NavigatorIOS. It looks and feels just like UINavigationController, because it is actually built on top of it.

<NavigatorIOS +}

In this example, the MyScene component is passed the title of the current route via the title prop. It displays two tappable components that call the onForward and onBack functions passed through its props, which in turn will call navigator.push() and navigator.pop() as needed.

While this is a very basic example, it can easily be adapted to render an entirely different component based on the route that is passed to the renderScene function. Navigator will push new scenes from the right by default, and you can control this behavior by using the configureScene function. You can also configure a navigation bar through the navigationBar prop.

Check out the Navigator API reference for more code samples.

NavigatorIOS #

If you are targeting iOS only, you may also want to consider using NavigatorIOS. It looks and feels just like UINavigationController, because it is actually built on top of it.

<NavigatorIOS initialRoute={{ component: MyScene, title: 'My Initial Scene', passProps: { myProp: 'foo' }, }} -/>

Just like Navigator, it it uses routes to represent scenes, with some important differences. The actual component that will be rendered can be specified using the component key in the route, and any props that should be passed to this component can be specified in passProps. A navigator object is automatically passed as a prop to the component, allowing you to call push and pop as needed.

Check out the NavigatorIOS reference docs to learn more about this component.

class MyScene extends Component { +/>

Just like Navigator, NavigatorIOS uses routes to represent scenes, with some important differences. The actual component that will be rendered can be specified using the component key in the route, and any props that should be passed to this component can be specified in passProps. A "navigator" object is automatically passed as a prop to the component, allowing you to call push and pop as needed.

As NavigatorIOS leverages native UIKit navigation, it will automatically render a navigation bar with a back button and title.

Check out the NavigatorIOS reference docs to learn more about this component.

import React, { Component, PropTypes } from 'react'; +import { NavigatorIOS, Text, TouchableHighlight, View } from 'react-native'; + +export default class NavigatorIOSApp extends Component { + render() { + return ( + <NavigatorIOS + initialRoute={{ + component: MyScene, + title: 'My Initial Scene', + }} + style={{flex: 1}} + /> + ) + } +} + +class MyScene extends Component { static propTypes = { title: PropTypes.string.isRequired, navigator: PropTypes.object.isRequired, @@ -64,7 +88,6 @@ class SimpleNavigationApp extends constructor(props, context) { super(props, context); this._onForward = this._onForward.bind(this); - this._onBack = this._onBack.bind(this); } _onForward() { @@ -73,10 +96,6 @@ class SimpleNavigationApp extends }); } - _onBack() { - this.props.navigator.pop(); - } - render() { return ( <View> @@ -84,30 +103,178 @@ class SimpleNavigationApp extends ={this._onForward}> <Text>Tap me to load the next scene</Text> </TouchableHighlight> - <TouchableHighlight onPress={this._onBack}> - <Text>Tap me to go back</Text> - </TouchableHighlight> </View> ) } -} +}

You may also want to check out react-native-navigation, a component that aims to provide native navigation on both iOS and Android.

NavigationExperimental #

Navigator and NavigatorIOS are both stateful components. If your app has multiple of these, it can become tricky to coordinate navigation transitions between them. NavigationExperimental provides a different approach to navigation, allowing any view to act as a navigation view and using reducers to manipulate state at a top-level object. It is bleeding edge as the name implies, but you might want to check it out if you are craving greater control over your app's navigation.

<NavigationCardStack + onNavigateBack={onPopRouteFunc} + navigationState={myNavigationState} + renderScene={renderSceneFun} +/>

You can import NavigationExperimental like any other component in React Native. Once you have that, you can deconstruct any additional components from NavigationExperimental that you may find useful. Since I am feeling like building navigation stacks today, I'll go ahead and pick out NavigationCardStack and NavigationStateUtils.

import React, { Component } from 'react'; +import { NavigationExperimental } from 'react-native'; + +const { + CardStack: NavigationCardStack, + StateUtils: NavigationStateUtils, +} = NavigationExperimental;

As I said earlier, NavigationExperimental takes a different approach than Navigator and NavigatorIOS. Using it to build a navigation stack requires a few more steps than the stateful components, but the payoff is worth it.

Step 1. Define Initial State and Top Level Component #

Create a new component for your application. This will be the top-level object, so we will define the initial state here. The navigation state will be defined in the navigationState key, where we define our initial route:

class BleedingEdgeApplication extends Component { + constructor(props, context) { + super(props, context); + + this.state = { + // This defines the initial navigation state. + navigationState: { + index: 0, // Starts with first route focused. + routes: [{key: 'My Initial Scene'}], // Starts with only one route. + }, + }; + + // We'll define this function later - hang on + this._onNavigationChange = this._onNavigationChange.bind(this); + } + + _onNavigationChange(type) { + // It's literally the next step. We'll get to it! + } -class NavigatorIOSApp extends Component { render() { return ( - <NavigatorIOS - initialRoute={{ - component: MyScene, - title: 'My Initial Scene', - index: 0 - }} - renderScene={ (route, navigator) => - <MyScene title={route.title} /> - } - /> - ) + <Text>This is a placeholder. We will come back to this and render our navigation here later.</Text> + ); } -}

You may also want to check out react-native-navigation, a component that aims to provide native navigation on both iOS and Android.

Navigation (Experimental) #

If you are looking for a more powerful navigation API, check out NavigationExperimental. It provides greater customization over your transitions, uses single-directional data flow using reducers to manipulate state at a top-level object, and offloads transition animations to the GPU.

© 2016 Facebook Inc.

Navigator #

Edit on GitHub

Navigator handles the transition between different scenes in your app. -You should consider using this component instead of NavigatorIOS if you're -building a cross-platform app. Navigator is implemented in JavaScript -whereas NavigatorIOS is a wrapper around UINavigationController.

To set up the Navigator you provide one or more objects called routes, +It is implemented in JavaScript and is available on both iOS and Android. If +you are targeting iOS only, you may also want to consider using +NavigatorIOS as it leverages native UIKit +navigation.

To set up the Navigator you provide one or more objects called routes, to identify each scene. You also provide a renderScene function that renders the scene for each route object.

import React, { Component } from 'react'; import { Text, Navigator } from 'react-native'; -class NavAllDay extends Component { +export default class NavAllDay extends Component { render() { return ( <Navigator - initialRoute={{name: 'Awesome Scene'}} + initialRoute={{ title: 'Awesome Scene', index: 0 }} renderScene={(route, navigator) => - <Text>Hello {route.name}!</Text> + <Text>Hello {route.title}!</Text> } style={{padding: 100}} /> ); } }

In the above example, initialRoute is used to specify the first route. It -contains a name property that identifies the route. The renderScene -prop returns a function that displays text based on the route's name.

Additional Scenes #

The first example demonstrated one scene. To set up multiple scenes, you pass +contains a title property that identifies the route. The renderScene +prop returns a function that displays text based on the route's title.

Additional Scenes #

The first example demonstrated one scene. To set up multiple scenes, you pass the initialRouteStack prop to Navigator:

render() { const routes = [ - {name: 'First Scene', index: 0}, - {name: 'Second Scene', index: 1}, + {title: 'First Scene', index: 0}, + {title: 'Second Scene', index: 1}, ]; return ( <Navigator @@ -38,7 +39,7 @@ the initialRouteStack prop to Navigator:

.pop(); } }}> - <Text>Hello {route.name}!</Text> + <Text>Hello {route.title}!</Text> </TouchableHighlight> } style={{padding: 100}} @@ -87,7 +88,11 @@ on the previous example, you can set this up as follows:

); } },

This sets up a left navigator bar button that's visible on scenes after the -the first one. When the button is tapped the navigator is popped.

Scene Transitions #

To change the animation or gesture properties of the scene, provide a +the first one. When the button is tapped the navigator is popped.

Another type of navigation bar, with breadcrumbs, is provided by +Navigator.BreadcrumbNavigationBar. You can also provide your own navigation +bar by passing it through the navigationBar prop. See the +UIExplorer +demo to try out both built-in navigation bars out and see how to use them.

Scene Transitions #

To change the animation or gesture properties of the scene, provide a configureScene prop to get the config object for a given route:

<Navigator renderScene={(route, navigator) => // ... diff --git a/releases/0.29/docs/navigatorios.html b/releases/0.29/docs/navigatorios.html index a6ce6ffca51..852767be319 100644 --- a/releases/0.29/docs/navigatorios.html +++ b/releases/0.29/docs/navigatorios.html @@ -1,18 +1,23 @@ -NavigatorIOS – React Native | A framework for building native apps using React

NavigatorIOS #

Edit on GitHub

NavigatorIOS is a wrapper around UIKit navigation, enabling you to -implement back-swipe functionality in your iOS app. Take a look at +NavigatorIOS – React Native | A framework for building native apps using React

NavigatorIOS #

Edit on GitHub

NavigatorIOS is a wrapper around +UINavigationController, +enabling you to implement a navigation stack. It works exactly the same as it +would on a native app using UINavigationController, providing the same +animations and behavior from UIKIt.

As the name implies, it is only available on iOS. Take a look at Navigator for a similar solution for your -cross-platform needs.

To set up the navigator, provide the initialRoute prop with a route +cross-platform needs, or check out +react-native-navigation, a +component that aims to provide native navigation on both iOS and Android.

To set up the navigator, provide the initialRoute prop with a route object. A route object is used to describe each scene that your app navigates to. initialRoute represents the first route in your navigator.

import React, { Component } from 'react'; import { NavigatorIOS, Text } from 'react-native'; -class NavvyIOS extends Component { +export default class NavigatorIOSApp extends Component { render() { return ( <NavigatorIOS initialRoute={{ - component: MyView, - title: 'My View Title', + component: MyScene, + title: 'My Initial Scene', }} style={{flex: 1}} /> @@ -20,24 +25,43 @@ class NavvyIOS extends } } -class MyView extends Component { - render() { - return( - <Text style={{marginTop: 200, alignSelf: 'center'}}> - See you on the other nav! - </Text> - ); +class MyScene extends Component { + static propTypes = { + title: PropTypes.string.isRequired, + navigator: PropTypes.object.isRequired, } -}

In this code, the navigator sets its title and renders MyView. The -component specified in initialRoute will receive a route prop and a -navigator prop representing the navigator.

You can optionally pass in a passProps property to your initialRoute. + + constructor(props, context) { + super(props, context); + this._onForward = this._onForward.bind(this); + this._onBack = this._onBack.bind(this); + } + + _onForward() { + this.props.navigator.push({ + title: 'Scene ' + nextIndex, + }); + } + + render() { + return ( + <View> + <Text>Current Scene: { this.props.title }</Text> + <TouchableHighlight onPress={this._onForward}> + <Text>Tap me to load the next scene</Text> + </TouchableHighlight> + </View> + ) + } +}

In this code, the navigator renders the component specified in initialRoute, +which in this case is MyScene. This component will receive a route prop +and a navigator prop representing the navigator. The navigator's navigation +bar will render the title for the current scene, "My Initial Scene".

You can optionally pass in a passProps property to your initialRoute. NavigatorIOS passes this in as props to the rendered component:

initialRoute={{ - component: MyView, - title: 'Foo This', + component: MyScene, + title: 'My Initial Scene', passProps: { myProp: 'foo' } -}}

You can then access the props passed in:

<Text style={{marginTop: 200, alignSelf: 'center'}}> - See you on the other nav {this.props.myProp}! -</Text>

Handling Navigation #

To trigger navigation functionality such as pushing or popping a view, you +}}

You can then access the props passed in via {this.props.myProp}.

Handling Navigation #

To trigger navigation functionality such as pushing or popping a view, you have access to a navigator object. The object is passed in as a prop to any component that is rendered by NavigatorIOS. You can then call the relevant methods to perform the navigation action you need:

class MyView extends Component { diff --git a/releases/0.29/docs/props.html b/releases/0.29/docs/props.html index 30501ff3ede..ede9c961b85 100644 --- a/releases/0.29/docs/props.html +++ b/releases/0.29/docs/props.html @@ -8,12 +8,12 @@ class Bananas extends : 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg' }; return ( - <Image source={pic} /> + <Image source={pic} style={{width: 193, height: 110}}/> ); } } -AppRegistry.registerComponent('Bananas', () => Bananas);

Notice that {pic} is surrounded by braces, to embed the variable pic into JSX. You can put any JavaScript expression inside braces in JSX.

Your own components can also use props. This lets you make a single component +AppRegistry.registerComponent('Bananas', () => Bananas);

Notice that {pic} is surrounded by braces, to embed the variable pic into JSX. You can put any JavaScript expression inside braces in JSX.

Your own components can also use props. This lets you make a single component that is used in many different places in your app, with slightly different properties in each place. Just refer to this.props in your render function. Here's an example:

import React, { Component } from 'react'; import { AppRegistry, Text, View } from 'react-native'; diff --git a/releases/0.29/img/NavigationStack-Navigator.gif b/releases/0.29/img/NavigationStack-Navigator.gif new file mode 100644 index 00000000000..c1f8313996c Binary files /dev/null and b/releases/0.29/img/NavigationStack-Navigator.gif differ diff --git a/releases/0.29/img/NavigationStack-NavigatorIOS.gif b/releases/0.29/img/NavigationStack-NavigatorIOS.gif new file mode 100644 index 00000000000..c1d56a1f555 Binary files /dev/null and b/releases/0.29/img/NavigationStack-NavigatorIOS.gif differ diff --git a/versions.html b/versions.html index 35d2ff0841c..5c24bd339fa 100644 --- a/versions.html +++ b/versions.html @@ -1,4 +1,4 @@ -Documentation archive – React Native | A framework for building native apps using React

React Native Versions

React Native is following a 2-week train release. Every two weeks, a Release Candidate (rc) branch is created off of master and the previous rc branch is being officially released.

masterDocs
0.29-rcDocsRelease Notes
(current) 0.28DocsRelease Notes
0.27DocsRelease Notes
0.26DocsRelease Notes
0.25DocsRelease Notes
0.24DocsRelease Notes
0.23DocsRelease Notes
0.22DocsRelease Notes
0.21DocsRelease Notes
0.20DocsRelease Notes
0.19DocsRelease Notes
0.18DocsRelease Notes
© 2016 Facebook Inc.

React Native Versions

React Native is following a 2-week train release. Every two weeks, a Release Candidate (rc) branch is created off of master and the previous rc branch is being officially released.

masterDocs
0.29-rcDocsRelease Notes
(current) 0.28DocsRelease Notes
0.27DocsRelease Notes
0.26DocsRelease Notes
0.25DocsRelease Notes
0.24DocsRelease Notes
0.23DocsRelease Notes
0.22DocsRelease Notes
0.21DocsRelease Notes
0.20DocsRelease Notes
0.19DocsRelease Notes
0.18DocsRelease Notes
© 2016 Facebook Inc.
\ No newline at end of file