diff --git a/docs/getting-started.html b/docs/getting-started.html index 29c4fb181ba..335aa3748f1 100644 --- a/docs/getting-started.html +++ b/docs/getting-started.html @@ -1,4 +1,4 @@ -React Native | A framework for building native apps using React

Getting Started

Requirements #

  1. OS X - This repo only contains the iOS implementation right now, and Xcode only runs on Mac.
  2. New to Xcode? Download it from the Mac App Store.
  3. Homebrew is the recommended way to install node, watchman, and flow.
  4. brew install node. New to node or npm?
  5. brew install watchman. We recommend installing watchman, otherwise you might hit a node file watching bug.
  6. brew install flow. If you want to use flow.

Quick start #

  • npm install -g react-native-cli
  • react-native init AwesomeProject

In the newly created folder AwesomeProject/

  • Open AwesomeProject.xcodeproj and hit run in Xcode
  • Open index.ios.js in your text editor of choice and edit some lines
  • Hit cmd+R (twice) in your iOS simulator to reload the app and see your change!

Congratulations! You've just successfully run and modified your first React Native app.

Getting Started

Requirements #

  1. OS X - This repo only contains the iOS implementation right now, and Xcode only runs on Mac.
  2. New to Xcode? Download it from the Mac App Store.
  3. Homebrew is the recommended way to install node, watchman, and flow.
  4. brew install node. New to node or npm?
  5. brew install watchman. We recommend installing watchman, otherwise you might hit a node file watching bug.
  6. brew install flow. If you want to use flow.

Quick start #

  • npm install -g react-native-cli
  • react-native init AwesomeProject

In the newly created folder AwesomeProject/

  • Open AwesomeProject.xcodeproj and hit run in Xcode
  • Open index.ios.js in your text editor of choice and edit some lines
  • Hit cmd+R (twice) in your iOS simulator to reload the app and see your change!

Congratulations! You've just successfully run and modified your first React Native app.

LinkingIOS

LinkingIOS gives you an interface to interact with both incoming and -outgoing app links.

Basic Usage #

Handling deep links #

If your app was launched from an external URL registered with your app, you can -access and handle it from any component you want with the following:

componentDidMount() { - var url = LinkingIOS.popInitialURL(); - if (url) { ... } -}

If you also want to listen to incoming app links during your app's -execution you'll need to add the following lines to you *AppDelegate.m:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { - return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; -}

And in your React component, you'll then be able to listen to the events from -LinkingIOS as follows

componentDidMount() { - LinkingIOS.addEventListener('url', this._handleOpenURL); -}, -componentWillUnmount() { - LinkingIOS.removeEventListener('url', this._handleOpenURL); -}, -_handleOpenURL(event) { - console.log(event.url); -}

Triggering App links #

To trigger an app link (browser, email, or custom schemes) you can call:

LinkingIOS.openURL(url)

If you want to check if a URL can be opened by an installed app on the system you can call

LinkingIOS.canOpenURL(url, (supported) => { - if (!supported) { - AlertIOS.alert('Can\'t handle url: ' + url); - } else { - LinkingIOS.openURL(url); - } -});

Methods #

static addEventListener(type: string, handler: Function) #

Add a handler to LinkingIOS changes by listening to the url event type -and providing the handler

static removeEventListener(type: string, handler: Function) #

Remove a handler by passing the url event type and the handler

static openURL(url: string) #

Try to open the given url with any of the installed apps. -If multiple applications can open url, the one that opens -is undefined.

static canOpenURL(url: string, callback: Function) #

Determine whether an installed app can handle a given url. -The callback function will be called with bool supported as the only argument

static popInitialURL() #

If the app launch was triggered by an app link, it will pop the link URL, -otherwise it will return null

LinkingIOS

All rights reserved.

This source code is licensed under the BSD-style license found in the +LICENSE file in the root directory of this source tree. An additional grant +of patent rights can be found in the PATENTS file in the same directory.

@flow

Methods #

static addEventListener(type, handler) #

static removeEventListener(type, handler) #

static openURL(url) #

static canOpenURL(url, callback) #

static popInitialURL() #

Navigator

Use ReactNavigator to transition between different scenes in your app. To +React Native | A framework for building native apps using React

Navigator

Use Navigator to transition between different scenes in your app. To accomplish this, provide route objects to the navigator to identify each scene, and also a renderScene function that the navigator can use to render the scene for a given route.

To change the animation or gesture properties of the scene, provide a configureScene prop to get the config object for a given route. See -ReactNavigator.SceneConfigs for default animations and more info on -scene config options.

Basic Usage #

<ReactNavigator +Navigator.SceneConfigs for default animations and more info on +scene config options.

Basic Usage #

<Navigator initialRoute={{name: 'My First Scene', index: 0}} renderScene={(route, navigator) => <MySceneComponent @@ -23,7 +23,7 @@ scene config options.

Basic Usag }} /> } - />

Navigation Methods #

ReactNavigator can be told to navigate in two ways. If you have a ref to + />

Navigation Methods #

Navigator can be told to navigate in two ways. If you have a ref to the element, you can invoke several methods on it to trigger navigation:

  • jumpBack() - Jump backward without unmounting the current scene
  • jumpForward() - Jump forward to the next scene in the route stack
  • jumpTo(route) - Transition to an existing scene without unmounting
  • push(route) - Navigate forward to a new scene, squashing any scenes that you could jumpForward to
  • pop() - Transition back and unmount the current scene
  • replace(route) - Replace the current scene with a new route
  • replaceAtIndex(route, index) - Replace a scene as specified by an index
  • replacePrevious(route) - Replace the previous scene
  • immediatelyResetRouteStack(routeStack) - Reset every scene with an array of routes
  • popToRoute(route) - Pop to a particular scene, as specified by it's @@ -35,11 +35,11 @@ few utilities:

    • parentNavigator - a refrence to the paren navigator
    • onDidFocus - used to pass a navigation focus event up to the parent navigator

Props #

configureScene function #

Optional function that allows configuration about scene animations and gestures. Will be invoked with the route and should return a scene -configuration object

(route) => ReactNavigator.SceneConfigs.FloatFromRight

initialRoute object #

Provide a single "route" to start on. A route is an arbitrary object +configuration object

(route) => Navigator.SceneConfigs.FloatFromRight

initialRoute object #

Provide a single "route" to start on. A route is an arbitrary object that the navigator will use to identify each scene before rendering. Either initialRoute or initialRouteStack is required.

initialRouteStack [object] #

Provide a set of routes to initially mount the scenes for. Required if no initialRoute is provided

navigationBar node #

Optionally provide a navigation bar that persists across scene -transitions

navigator object #

Optionally provide the navigator object from a parent ReactNavigator

onDidFocus function #

Will be called with the new route of each scene after the transition is +transitions

navigator object #

Optionally provide the navigator object from a parent Navigator

onDidFocus function #

Will be called with the new route of each scene after the transition is complete or after the initial mounting. This overrides the onDidFocus handler that would be found in this.props.navigator

onItemRef function #

Will be called with (ref, indexInStack) when the scene ref changes

onWillFocus function #

Will emit the target route upon mounting and before each nav transition, overriding the handler in this.props.navigator. This overrides the onDidFocus diff --git a/docs/tutorial.html b/docs/tutorial.html index 714ed0aef01..81acca9be8a 100644 --- a/docs/tutorial.html +++ b/docs/tutorial.html @@ -70,17 +70,17 @@

-

Fetching real data #

Fetching data from Rotten Tomatoes's API isn't really relevant to learning React Native so feel free to breeze through this section.

Add the following constants to the top of the file (typically below the requires) to create the REQUEST_URL used to request data with.

var API_KEY = '7waqfqbprs7pajbz28mqf6vz'; -var API_URL = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/in_theaters.json'; -var PAGE_SIZE = 25; -var PARAMS = '?apikey=' + API_KEY + '&page_limit=' + PAGE_SIZE; -var REQUEST_URL = API_URL + PARAMS;

Add some initial state to our application so that we can check this.state.movies === null to determine whether the movies data has been loaded or not. We can set this data when the response comes back with this.setState({movies: moviesData}). Add this code just above the render function inside our React class.

getInitialState: function() { +

Fetching real data #

Fetching data from Rotten Tomatoes's API isn't really relevant to learning React Native so feel free to breeze through this section.

Add the following constants to the top of the file (typically below the requires) to create the REQUEST_URL used to request data with.

/** + * For quota reasons we replaced the Rotten Tomatoes' API with a sample data of + * their very own API that lives in React Native's Gihub repo. + */ +var REQUEST_URL = 'https://raw.githubusercontent.com/facebook/react-native/master/docs/MoviesExample.json';

Add some initial state to our application so that we can check this.state.movies === null to determine whether the movies data has been loaded or not. We can set this data when the response comes back with this.setState({movies: moviesData}). Add this code just above the render function inside our React class.

getInitialState: function() { return { movies: null, }; },

We want to send off the request after the component has finished loading. componentDidMount is a function of React components that React will call exactly once, just after the component has been loaded.

componentDidMount: function() { this.fetchData(); - },

Now add fetchData function used above to our main component. This method will be respondible for handling data fetching. All you need to do is call this.setState({movies: data}) after resolving the promise chain because the way React works is that setState actually triggers a re-render and then the render function will notice that this.state.movies is no longer null. Note that we call done() at the end of the promise chain - always make sure to call done() or any errors thrown will get swallowed.

fetchData: function() { + },

Now add fetchData function used above to our main component. This method will be responsible for handling data fetching. All you need to do is call this.setState({movies: data}) after resolving the promise chain because the way React works is that setState actually triggers a re-render and then the render function will notice that this.state.movies is no longer null. Note that we call done() at the end of the promise chain - always make sure to call done() or any errors thrown will get swallowed.

fetchData: function() { fetch(REQUEST_URL) .then((response) => response.json()) .then((responseData) => { @@ -132,7 +132,7 @@ StyleSheet, Text, View, -} = React;

Now modify the render funtion so that once we have our data it renders a ListView of movies instead of a single movie.

render: function() { +} = React;

Now modify the render function so that once we have our data it renders a ListView of movies instead of a single movie.

render: function() { if (!this.state.loaded) { return this.renderLoadingView(); } @@ -144,7 +144,7 @@ style={styles.listView} /> ); - },

The DataSource is an interfacte that ListView is using to determine which rows have changed over the course of updates.

You'll notice we used dataSource from this.state. The next step is to add an empty dataSource to the object returned by getInitialState. Also, now that we're storing the data in dataSource, we should not longer use this.state.movies to avoid storing data twice. We can use boolean property of the state (this.state.loaded) to tell whether data fetching has finished.

getInitialState: function() { + },

The DataSource is an interface that ListView is using to determine which rows have changed over the course of updates.

You'll notice we used dataSource from this.state. The next step is to add an empty dataSource to the object returned by getInitialState. Also, now that we're storing the data in dataSource, we should no longer use this.state.movies to avoid storing data twice. We can use boolean property of the state (this.state.loaded) to tell whether data fetching has finished.

getInitialState: function() { return { dataSource: new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2,