diff --git a/docs/0.10/accessibility.html b/docs/0.10/accessibility.html index cae0646c0a7..43efbd79155 100644 --- a/docs/0.10/accessibility.html +++ b/docs/0.10/accessibility.html @@ -11,7 +11,7 @@

Accessibility properties

accessible (iOS, Android)

When true, indicates that the view is an accessibility element. When a view is an accessibility element, it groups its children into a single selectable component. By default, all touchable elements are accessible.

-

On Android, ‘accessible={true}’ property for a react-native View will be translated into native ‘focusable={true}’.

+

On Android, accessible={true} property for a react-native View will be translated into native focusable={true}.

<View accessible={true}>
   <Text>text one</Text>
   <Text>text two</Text>
@@ -61,7 +61,7 @@
 

onMagicTap (iOS)

Assign this property to a custom function which will be called when someone performs the "magic tap" gesture, which is a double-tap with two fingers. A magic tap function should perform the most relevant action a user could take on a component. In the Phone app on iPhone, a magic tap answers a phone call, or ends the current one. If the selected element does not have an onMagicTap function, the system will traverse up the view hierarchy until it finds a view that does.

accessibilityComponentType (Android)

-

In some cases, we also want to alert the end user of the type of selected component (i.e., that it is a “button”). If we were using native buttons, this would work automatically. Since we are using javascript, we need to provide a bit more context for TalkBack. To do so, you must specify the ‘accessibilityComponentType’ property for any UI component. For instances, we support ‘button’, ‘radiobutton_checked’ and ‘radiobutton_unchecked’ and so on.

+

In some cases, we also want to alert the end user of the type of selected component (i.e., that it is a “button”). If we were using native buttons, this would work automatically. Since we are using javascript, we need to provide a bit more context for TalkBack. To do so, you must specify the ‘accessibilityComponentType’ property for any UI component. We support 'none', ‘button’, ‘radiobutton_checked’ and ‘radiobutton_unchecked’.

<TouchableWithoutFeedback accessibilityComponentType=”button”
   onPress={this._onPress}>
   <View style={styles.button}>
@@ -105,13 +105,20 @@
 

The AccessibilityInfo API allows you to determine whether or not a screen reader is currently active. See the AccessibilityInfo documentation for details.

Sending Accessibility Events (Android)

Sometimes it is useful to trigger an accessibility event on a UI component (i.e. when a custom view appears on a screen or a custom radio button has been selected). Native UIManager module exposes a method ‘sendAccessibilityEvent’ for this purpose. It takes two arguments: view tag and a type of an event.

-
_onPress: function() {
-  this.state.radioButton = this.state.radioButton === “radiobutton_checked” ?
-  “radiobutton_unchecked” : “radiobutton_checked”;
-  if (this.state.radioButton === “radiobutton_checked”) {
-    RCTUIManager.sendAccessibilityEvent(
-      ReactNative.findNodeHandle(this),
-      RCTUIManager.AccessibilityEventTypes.typeViewClicked);
+
import { UIManager, findNodeHandle } from 'react-native';
+
+_onPress: function() {
+  const radioButton = this.state.radioButton === 'radiobutton_checked' ?
+    'radiobutton_unchecked' : 'radiobutton_checked'
+
+  this.setState({
+    radioButton: radioButton
+  });
+
+  if (radioButton === 'radiobutton_checked') {
+    UIManager.sendAccessibilityEvent(
+      findNodeHandle(this),
+      UIManager.AccessibilityEventTypes.typeViewClicked);
   }
 }
 
diff --git a/docs/0.10/animations.html b/docs/0.10/animations.html
index 05eee1d6971..ce0d80f12df 100644
--- a/docs/0.10/animations.html
+++ b/docs/0.10/animations.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.10/app-extensions.html b/docs/0.10/app-extensions.html index abf6705054c..8d2aad7beca 100644 --- a/docs/0.10/app-extensions.html +++ b/docs/0.10/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.10/building-for-apple-tv.html b/docs/0.10/building-for-apple-tv.html index ca6b67025d9..587e2b3713a 100644 --- a/docs/0.10/building-for-apple-tv.html +++ b/docs/0.10/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.10/height-and-width.html b/docs/0.10/height-and-width.html index b4969d71bef..16527986421 100644 --- a/docs/0.10/height-and-width.html +++ b/docs/0.10/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.10/images.html b/docs/0.10/images.html index e1e36f1ab07..dfd614fa54f 100644 --- a/docs/0.10/images.html +++ b/docs/0.10/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.10/improvingux.html b/docs/0.10/improvingux.html index 2e07da66ba7..39ccabfb7b0 100644 --- a/docs/0.10/improvingux.html +++ b/docs/0.10/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.10/more-resources.html b/docs/0.10/more-resources.html index b6000c621c4..c2dc51c8ed0 100644 --- a/docs/0.10/more-resources.html +++ b/docs/0.10/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.10/native-components-android.html b/docs/0.10/native-components-android.html index 68fab8aba7c..08289d8b5da 100644 --- a/docs/0.10/native-components-android.html +++ b/docs/0.10/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.10/native-modules-android.html b/docs/0.10/native-modules-android.html
index 6ecf2117737..f50e6022164 100644
--- a/docs/0.10/native-modules-android.html
+++ b/docs/0.10/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.10/navigation.html b/docs/0.10/navigation.html
index f591331f684..ff6ea9190b1 100644
--- a/docs/0.10/navigation.html
+++ b/docs/0.10/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.10/network.html b/docs/0.10/network.html
index 90525ee765e..e3f6ad5a406 100644
--- a/docs/0.10/network.html
+++ b/docs/0.10/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.11/app-extensions.html b/docs/0.11/app-extensions.html index 35701b2c477..8e6b2fadea6 100644 --- a/docs/0.11/app-extensions.html +++ b/docs/0.11/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.11/building-for-apple-tv.html b/docs/0.11/building-for-apple-tv.html index 73d6865a304..a439b4df678 100644 --- a/docs/0.11/building-for-apple-tv.html +++ b/docs/0.11/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.11/height-and-width.html b/docs/0.11/height-and-width.html index a14d6a40573..84650bd774b 100644 --- a/docs/0.11/height-and-width.html +++ b/docs/0.11/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.11/images.html b/docs/0.11/images.html index 1e5414ef72a..cabb1edb8b9 100644 --- a/docs/0.11/images.html +++ b/docs/0.11/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.11/improvingux.html b/docs/0.11/improvingux.html index c1282b2814f..9fb5f15275d 100644 --- a/docs/0.11/improvingux.html +++ b/docs/0.11/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.11/more-resources.html b/docs/0.11/more-resources.html index d50d56565fb..ab987b43f9b 100644 --- a/docs/0.11/more-resources.html +++ b/docs/0.11/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.11/native-components-android.html b/docs/0.11/native-components-android.html index 37e316ecf37..ea056aff570 100644 --- a/docs/0.11/native-components-android.html +++ b/docs/0.11/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.11/native-modules-android.html b/docs/0.11/native-modules-android.html
index dc5ffd6fb3f..947412183ba 100644
--- a/docs/0.11/native-modules-android.html
+++ b/docs/0.11/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.11/navigation.html b/docs/0.11/navigation.html
index 0b41db93dbb..034d3a12514 100644
--- a/docs/0.11/navigation.html
+++ b/docs/0.11/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.11/network.html b/docs/0.11/network.html
index 30927ece9e8..9749bde5a4e 100644
--- a/docs/0.11/network.html
+++ b/docs/0.11/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.12/app-extensions.html b/docs/0.12/app-extensions.html index 36348887e92..18528268589 100644 --- a/docs/0.12/app-extensions.html +++ b/docs/0.12/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.12/building-for-apple-tv.html b/docs/0.12/building-for-apple-tv.html index 57c12a36fc3..a6b79ece515 100644 --- a/docs/0.12/building-for-apple-tv.html +++ b/docs/0.12/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.12/height-and-width.html b/docs/0.12/height-and-width.html index 14e434906a9..9c9859082ea 100644 --- a/docs/0.12/height-and-width.html +++ b/docs/0.12/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.12/images.html b/docs/0.12/images.html index 9a827c2fba3..07fa0dd6f3a 100644 --- a/docs/0.12/images.html +++ b/docs/0.12/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.12/improvingux.html b/docs/0.12/improvingux.html index 0380507236f..43df6263400 100644 --- a/docs/0.12/improvingux.html +++ b/docs/0.12/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.12/more-resources.html b/docs/0.12/more-resources.html index 89fff1a66ca..965f17cd973 100644 --- a/docs/0.12/more-resources.html +++ b/docs/0.12/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.12/native-components-android.html b/docs/0.12/native-components-android.html index 3329eb4471b..dcd38c04604 100644 --- a/docs/0.12/native-components-android.html +++ b/docs/0.12/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.12/native-modules-android.html b/docs/0.12/native-modules-android.html
index 7eb8ad309e7..a8ffeb62ec8 100644
--- a/docs/0.12/native-modules-android.html
+++ b/docs/0.12/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.12/navigation.html b/docs/0.12/navigation.html
index a343fa2a630..773b65091ca 100644
--- a/docs/0.12/navigation.html
+++ b/docs/0.12/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.12/network.html b/docs/0.12/network.html
index e9fe6a4dba4..a8a359eb3e2 100644
--- a/docs/0.12/network.html
+++ b/docs/0.12/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.13/app-extensions.html b/docs/0.13/app-extensions.html index 9d24c70f5d7..b9880d9ddcf 100644 --- a/docs/0.13/app-extensions.html +++ b/docs/0.13/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.13/building-for-apple-tv.html b/docs/0.13/building-for-apple-tv.html index 8cf5c821fdd..1e83d02b13a 100644 --- a/docs/0.13/building-for-apple-tv.html +++ b/docs/0.13/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.13/height-and-width.html b/docs/0.13/height-and-width.html index 70773c22b61..2ff2102af59 100644 --- a/docs/0.13/height-and-width.html +++ b/docs/0.13/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.13/images.html b/docs/0.13/images.html index 7b5b532e75b..6bc444217f0 100644 --- a/docs/0.13/images.html +++ b/docs/0.13/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.13/improvingux.html b/docs/0.13/improvingux.html index a7a4650f449..3134e25a367 100644 --- a/docs/0.13/improvingux.html +++ b/docs/0.13/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.13/more-resources.html b/docs/0.13/more-resources.html index 4f62ec3a4cd..3d98799c33c 100644 --- a/docs/0.13/more-resources.html +++ b/docs/0.13/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.13/native-components-android.html b/docs/0.13/native-components-android.html index c7487eb3dee..f04e0f3b213 100644 --- a/docs/0.13/native-components-android.html +++ b/docs/0.13/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.13/native-modules-android.html b/docs/0.13/native-modules-android.html
index 8a57709aa9a..dd470fd6114 100644
--- a/docs/0.13/native-modules-android.html
+++ b/docs/0.13/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.13/navigation.html b/docs/0.13/navigation.html
index d347d69c678..89426f8557c 100644
--- a/docs/0.13/navigation.html
+++ b/docs/0.13/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.13/network.html b/docs/0.13/network.html
index c8e59052885..afe43350e2f 100644
--- a/docs/0.13/network.html
+++ b/docs/0.13/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.14/app-extensions.html b/docs/0.14/app-extensions.html index 52590c1368b..e133c41bcfa 100644 --- a/docs/0.14/app-extensions.html +++ b/docs/0.14/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.14/building-for-apple-tv.html b/docs/0.14/building-for-apple-tv.html index 081ca859519..03c82303f90 100644 --- a/docs/0.14/building-for-apple-tv.html +++ b/docs/0.14/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.14/height-and-width.html b/docs/0.14/height-and-width.html index 26548ed232f..18d3de84d3b 100644 --- a/docs/0.14/height-and-width.html +++ b/docs/0.14/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.14/images.html b/docs/0.14/images.html index afd492a61c1..0759814c1fe 100644 --- a/docs/0.14/images.html +++ b/docs/0.14/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.14/improvingux.html b/docs/0.14/improvingux.html index 011113d391f..1f2dac621c6 100644 --- a/docs/0.14/improvingux.html +++ b/docs/0.14/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.14/more-resources.html b/docs/0.14/more-resources.html index 3ee3ecf4f2f..49e3035b7ba 100644 --- a/docs/0.14/more-resources.html +++ b/docs/0.14/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.14/native-components-android.html b/docs/0.14/native-components-android.html index 1b75248fd05..5829d0265ae 100644 --- a/docs/0.14/native-components-android.html +++ b/docs/0.14/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.14/native-modules-android.html b/docs/0.14/native-modules-android.html
index d699092afe9..7351588e883 100644
--- a/docs/0.14/native-modules-android.html
+++ b/docs/0.14/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.14/navigation.html b/docs/0.14/navigation.html
index cc241ef9754..fbea06afd6a 100644
--- a/docs/0.14/navigation.html
+++ b/docs/0.14/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.14/network.html b/docs/0.14/network.html
index c53c52ccd5d..4b3c9ed4b9b 100644
--- a/docs/0.14/network.html
+++ b/docs/0.14/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.15/app-extensions.html b/docs/0.15/app-extensions.html index 65b276b24ac..c6f87536bc5 100644 --- a/docs/0.15/app-extensions.html +++ b/docs/0.15/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.15/building-for-apple-tv.html b/docs/0.15/building-for-apple-tv.html index 6364418b325..e949ce1564e 100644 --- a/docs/0.15/building-for-apple-tv.html +++ b/docs/0.15/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.15/height-and-width.html b/docs/0.15/height-and-width.html index 25722cf51f2..e802f591ed2 100644 --- a/docs/0.15/height-and-width.html +++ b/docs/0.15/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.15/images.html b/docs/0.15/images.html index fd7482f5327..7eaf5c0d333 100644 --- a/docs/0.15/images.html +++ b/docs/0.15/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.15/improvingux.html b/docs/0.15/improvingux.html index 469e589c4d6..4a5db87d1d6 100644 --- a/docs/0.15/improvingux.html +++ b/docs/0.15/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.15/more-resources.html b/docs/0.15/more-resources.html index 0799c7922f6..a928f8d64b6 100644 --- a/docs/0.15/more-resources.html +++ b/docs/0.15/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.15/native-components-android.html b/docs/0.15/native-components-android.html index 31248d77477..c3c81aed6a0 100644 --- a/docs/0.15/native-components-android.html +++ b/docs/0.15/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.15/native-modules-android.html b/docs/0.15/native-modules-android.html
index 63c0089f6a0..4ae3fc9dbca 100644
--- a/docs/0.15/native-modules-android.html
+++ b/docs/0.15/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.15/navigation.html b/docs/0.15/navigation.html
index 102f03ddc50..188655fcf1a 100644
--- a/docs/0.15/navigation.html
+++ b/docs/0.15/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.15/network.html b/docs/0.15/network.html
index 7ad80c9138e..e7ebc906caf 100644
--- a/docs/0.15/network.html
+++ b/docs/0.15/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.16/app-extensions.html b/docs/0.16/app-extensions.html index 8172ade9e11..8a27f1644ac 100644 --- a/docs/0.16/app-extensions.html +++ b/docs/0.16/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.16/building-for-apple-tv.html b/docs/0.16/building-for-apple-tv.html index f6d9a5170f7..a8760259c16 100644 --- a/docs/0.16/building-for-apple-tv.html +++ b/docs/0.16/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.16/height-and-width.html b/docs/0.16/height-and-width.html index 526eefcd57a..94ab23a38c4 100644 --- a/docs/0.16/height-and-width.html +++ b/docs/0.16/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.16/images.html b/docs/0.16/images.html index c254e884127..ebfc0c8fd0b 100644 --- a/docs/0.16/images.html +++ b/docs/0.16/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.16/improvingux.html b/docs/0.16/improvingux.html index 54845ee54a9..0145f5b59da 100644 --- a/docs/0.16/improvingux.html +++ b/docs/0.16/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.16/more-resources.html b/docs/0.16/more-resources.html index 58c073e291f..bce260b2dc4 100644 --- a/docs/0.16/more-resources.html +++ b/docs/0.16/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.16/native-components-android.html b/docs/0.16/native-components-android.html index 8937f8a6653..981e5e5d3e4 100644 --- a/docs/0.16/native-components-android.html +++ b/docs/0.16/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.16/native-modules-android.html b/docs/0.16/native-modules-android.html
index 6c86746c83d..f17f2d96aeb 100644
--- a/docs/0.16/native-modules-android.html
+++ b/docs/0.16/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.16/navigation.html b/docs/0.16/navigation.html
index 42e7d7619ca..2b3745051be 100644
--- a/docs/0.16/navigation.html
+++ b/docs/0.16/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.16/network.html b/docs/0.16/network.html
index d99a9373c1e..8d4f30f8484 100644
--- a/docs/0.16/network.html
+++ b/docs/0.16/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.17/app-extensions.html b/docs/0.17/app-extensions.html index bbb1cc1e4aa..492b21de138 100644 --- a/docs/0.17/app-extensions.html +++ b/docs/0.17/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.17/building-for-apple-tv.html b/docs/0.17/building-for-apple-tv.html index 7e1282d2f78..e68f890b65b 100644 --- a/docs/0.17/building-for-apple-tv.html +++ b/docs/0.17/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.17/height-and-width.html b/docs/0.17/height-and-width.html index d787a911b4c..3ea2e6a7c45 100644 --- a/docs/0.17/height-and-width.html +++ b/docs/0.17/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.17/images.html b/docs/0.17/images.html index 30435d799ec..4c15df5269b 100644 --- a/docs/0.17/images.html +++ b/docs/0.17/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.17/improvingux.html b/docs/0.17/improvingux.html index 64d5048f77b..753ca551689 100644 --- a/docs/0.17/improvingux.html +++ b/docs/0.17/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.17/more-resources.html b/docs/0.17/more-resources.html index 7e49150c6d9..a65d251cbdb 100644 --- a/docs/0.17/more-resources.html +++ b/docs/0.17/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.17/native-components-android.html b/docs/0.17/native-components-android.html index 01592a20096..be7eb65e797 100644 --- a/docs/0.17/native-components-android.html +++ b/docs/0.17/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.17/native-modules-android.html b/docs/0.17/native-modules-android.html
index 83733e38212..7219612968a 100644
--- a/docs/0.17/native-modules-android.html
+++ b/docs/0.17/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.17/navigation.html b/docs/0.17/navigation.html
index 33c7d82a486..aaa23792cef 100644
--- a/docs/0.17/navigation.html
+++ b/docs/0.17/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.17/network.html b/docs/0.17/network.html
index bb2d18d818d..995c660018e 100644
--- a/docs/0.17/network.html
+++ b/docs/0.17/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.18/app-extensions.html b/docs/0.18/app-extensions.html index 9323e88fc68..91b185c918b 100644 --- a/docs/0.18/app-extensions.html +++ b/docs/0.18/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.18/building-for-apple-tv.html b/docs/0.18/building-for-apple-tv.html index 662dfdb8673..987d7e1e806 100644 --- a/docs/0.18/building-for-apple-tv.html +++ b/docs/0.18/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.18/height-and-width.html b/docs/0.18/height-and-width.html index 1a62c170253..a0eedaebb26 100644 --- a/docs/0.18/height-and-width.html +++ b/docs/0.18/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.18/images.html b/docs/0.18/images.html index c77debb9526..df2270d9d6b 100644 --- a/docs/0.18/images.html +++ b/docs/0.18/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.18/improvingux.html b/docs/0.18/improvingux.html index 79c8b06ac42..e44b0c7aa02 100644 --- a/docs/0.18/improvingux.html +++ b/docs/0.18/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.18/more-resources.html b/docs/0.18/more-resources.html index 8e199cf404f..5d5f9237e22 100644 --- a/docs/0.18/more-resources.html +++ b/docs/0.18/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.18/native-components-android.html b/docs/0.18/native-components-android.html index 967b4c1e1e9..46e7f1f7497 100644 --- a/docs/0.18/native-components-android.html +++ b/docs/0.18/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.18/native-modules-android.html b/docs/0.18/native-modules-android.html
index 4ab6dfb88d1..85c3c7a7b54 100644
--- a/docs/0.18/native-modules-android.html
+++ b/docs/0.18/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.18/navigation.html b/docs/0.18/navigation.html
index f7e85dcd38d..410ababc2ac 100644
--- a/docs/0.18/navigation.html
+++ b/docs/0.18/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.18/network.html b/docs/0.18/network.html
index 083a01b44cd..b2482e53a98 100644
--- a/docs/0.18/network.html
+++ b/docs/0.18/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.19/app-extensions.html b/docs/0.19/app-extensions.html index 0a0db128541..2e26e92faa4 100644 --- a/docs/0.19/app-extensions.html +++ b/docs/0.19/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.19/building-for-apple-tv.html b/docs/0.19/building-for-apple-tv.html index 282fa4dbc6f..64daf817996 100644 --- a/docs/0.19/building-for-apple-tv.html +++ b/docs/0.19/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.19/height-and-width.html b/docs/0.19/height-and-width.html index 732ab032208..975890fa9ec 100644 --- a/docs/0.19/height-and-width.html +++ b/docs/0.19/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.19/images.html b/docs/0.19/images.html index 48501300ada..b3f78d7421d 100644 --- a/docs/0.19/images.html +++ b/docs/0.19/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.19/improvingux.html b/docs/0.19/improvingux.html index 49c6b1baece..c8378887b77 100644 --- a/docs/0.19/improvingux.html +++ b/docs/0.19/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.19/more-resources.html b/docs/0.19/more-resources.html index 64f7a160617..c84d9e384aa 100644 --- a/docs/0.19/more-resources.html +++ b/docs/0.19/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.19/native-components-android.html b/docs/0.19/native-components-android.html index 4b6b6b33874..77ea23c9310 100644 --- a/docs/0.19/native-components-android.html +++ b/docs/0.19/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.19/native-modules-android.html b/docs/0.19/native-modules-android.html
index 499fd4fe253..01d499562a3 100644
--- a/docs/0.19/native-modules-android.html
+++ b/docs/0.19/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.19/navigation.html b/docs/0.19/navigation.html
index bd882f14dd1..95788dc0526 100644
--- a/docs/0.19/navigation.html
+++ b/docs/0.19/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.19/network.html b/docs/0.19/network.html
index b8ef26db30a..09a2fb49cd3 100644
--- a/docs/0.19/network.html
+++ b/docs/0.19/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.20/app-extensions.html b/docs/0.20/app-extensions.html index 16d09bef64e..4adc34c95a8 100644 --- a/docs/0.20/app-extensions.html +++ b/docs/0.20/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.20/building-for-apple-tv.html b/docs/0.20/building-for-apple-tv.html index 77c7b9a80eb..6e0ce6b27f1 100644 --- a/docs/0.20/building-for-apple-tv.html +++ b/docs/0.20/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.20/height-and-width.html b/docs/0.20/height-and-width.html index 0550d565eed..ec014dd6c54 100644 --- a/docs/0.20/height-and-width.html +++ b/docs/0.20/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.20/images.html b/docs/0.20/images.html index 42b4fa2e18a..e3ef89c19f9 100644 --- a/docs/0.20/images.html +++ b/docs/0.20/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.20/improvingux.html b/docs/0.20/improvingux.html index a9a5abe19b3..f19fd32fee2 100644 --- a/docs/0.20/improvingux.html +++ b/docs/0.20/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.20/more-resources.html b/docs/0.20/more-resources.html index 525c26463f2..73bf4e16a01 100644 --- a/docs/0.20/more-resources.html +++ b/docs/0.20/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.20/native-components-android.html b/docs/0.20/native-components-android.html index c4021a78326..e947368dc8f 100644 --- a/docs/0.20/native-components-android.html +++ b/docs/0.20/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.20/native-modules-android.html b/docs/0.20/native-modules-android.html
index 62137e18b33..2d1c2d8978d 100644
--- a/docs/0.20/native-modules-android.html
+++ b/docs/0.20/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.20/navigation.html b/docs/0.20/navigation.html
index 52bc03bf51e..0970b6dcb2b 100644
--- a/docs/0.20/navigation.html
+++ b/docs/0.20/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.20/network.html b/docs/0.20/network.html
index 49dbab575ed..90a3d48434f 100644
--- a/docs/0.20/network.html
+++ b/docs/0.20/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.21/app-extensions.html b/docs/0.21/app-extensions.html index 18a43cb976d..062cb5822f5 100644 --- a/docs/0.21/app-extensions.html +++ b/docs/0.21/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.21/building-for-apple-tv.html b/docs/0.21/building-for-apple-tv.html index e8b17287c6c..92326cdb02c 100644 --- a/docs/0.21/building-for-apple-tv.html +++ b/docs/0.21/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.21/height-and-width.html b/docs/0.21/height-and-width.html index 216cc5b6aa6..90f3a6c33ab 100644 --- a/docs/0.21/height-and-width.html +++ b/docs/0.21/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.21/images.html b/docs/0.21/images.html index b4ebf1e548f..06d05f1da2a 100644 --- a/docs/0.21/images.html +++ b/docs/0.21/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.21/improvingux.html b/docs/0.21/improvingux.html index 4bd773b57cc..e5eaf845e44 100644 --- a/docs/0.21/improvingux.html +++ b/docs/0.21/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.21/more-resources.html b/docs/0.21/more-resources.html index 93c4bef1e97..5868d8f124f 100644 --- a/docs/0.21/more-resources.html +++ b/docs/0.21/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.21/native-components-android.html b/docs/0.21/native-components-android.html index 24bab5e0f46..ac9cb419998 100644 --- a/docs/0.21/native-components-android.html +++ b/docs/0.21/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.21/native-modules-android.html b/docs/0.21/native-modules-android.html
index 9905fb89d82..d6e8165684e 100644
--- a/docs/0.21/native-modules-android.html
+++ b/docs/0.21/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.21/navigation.html b/docs/0.21/navigation.html
index 8f1d1003ac0..df3f40ff7a2 100644
--- a/docs/0.21/navigation.html
+++ b/docs/0.21/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.21/network.html b/docs/0.21/network.html
index 7858f9109de..53576a27935 100644
--- a/docs/0.21/network.html
+++ b/docs/0.21/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.22/app-extensions.html b/docs/0.22/app-extensions.html index d9d5f8885f6..cbea45f79a4 100644 --- a/docs/0.22/app-extensions.html +++ b/docs/0.22/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.22/building-for-apple-tv.html b/docs/0.22/building-for-apple-tv.html index 1e7d770b899..cbbce7e62c6 100644 --- a/docs/0.22/building-for-apple-tv.html +++ b/docs/0.22/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.22/height-and-width.html b/docs/0.22/height-and-width.html index 73611c73876..30a5dd63e88 100644 --- a/docs/0.22/height-and-width.html +++ b/docs/0.22/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.22/images.html b/docs/0.22/images.html index 8dc36a26aa4..a8719cb4957 100644 --- a/docs/0.22/images.html +++ b/docs/0.22/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.22/improvingux.html b/docs/0.22/improvingux.html index 2dbb3bff6a8..4c30124d16c 100644 --- a/docs/0.22/improvingux.html +++ b/docs/0.22/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.22/more-resources.html b/docs/0.22/more-resources.html index fe6e2396bb2..bd1494e84cf 100644 --- a/docs/0.22/more-resources.html +++ b/docs/0.22/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.22/native-components-android.html b/docs/0.22/native-components-android.html index 523230c56c2..d3cb20b07fc 100644 --- a/docs/0.22/native-components-android.html +++ b/docs/0.22/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.22/native-modules-android.html b/docs/0.22/native-modules-android.html
index b9038a67482..df730de7898 100644
--- a/docs/0.22/native-modules-android.html
+++ b/docs/0.22/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.22/navigation.html b/docs/0.22/navigation.html
index 93652800809..1af6ab64f15 100644
--- a/docs/0.22/navigation.html
+++ b/docs/0.22/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.22/network.html b/docs/0.22/network.html
index 781405a1f9f..43f1932d4f7 100644
--- a/docs/0.22/network.html
+++ b/docs/0.22/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.23/app-extensions.html b/docs/0.23/app-extensions.html index 40dd3e65c42..b171002e51d 100644 --- a/docs/0.23/app-extensions.html +++ b/docs/0.23/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.23/building-for-apple-tv.html b/docs/0.23/building-for-apple-tv.html index 8a1f7d4af3f..7efa797cd35 100644 --- a/docs/0.23/building-for-apple-tv.html +++ b/docs/0.23/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.23/height-and-width.html b/docs/0.23/height-and-width.html index 736227db5ea..6290a8aa95b 100644 --- a/docs/0.23/height-and-width.html +++ b/docs/0.23/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.23/images.html b/docs/0.23/images.html index f7f52360f77..c4e9b7a0136 100644 --- a/docs/0.23/images.html +++ b/docs/0.23/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.23/improvingux.html b/docs/0.23/improvingux.html index f4157f14043..e34d2fcb1dc 100644 --- a/docs/0.23/improvingux.html +++ b/docs/0.23/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.23/more-resources.html b/docs/0.23/more-resources.html index f1de7ad0042..9da748a683e 100644 --- a/docs/0.23/more-resources.html +++ b/docs/0.23/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.23/native-components-android.html b/docs/0.23/native-components-android.html index af944bce328..851de8e37ee 100644 --- a/docs/0.23/native-components-android.html +++ b/docs/0.23/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.23/native-modules-android.html b/docs/0.23/native-modules-android.html
index f41be408df5..57f6c9cd0de 100644
--- a/docs/0.23/native-modules-android.html
+++ b/docs/0.23/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.23/navigation.html b/docs/0.23/navigation.html
index 1abc779a49b..688c6cf130a 100644
--- a/docs/0.23/navigation.html
+++ b/docs/0.23/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.23/network.html b/docs/0.23/network.html
index 1635c1a1e3a..44073c4aff1 100644
--- a/docs/0.23/network.html
+++ b/docs/0.23/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.24/app-extensions.html b/docs/0.24/app-extensions.html index f5983e77e5c..601f2b9aab7 100644 --- a/docs/0.24/app-extensions.html +++ b/docs/0.24/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.24/building-for-apple-tv.html b/docs/0.24/building-for-apple-tv.html index c39b15128e5..61abc602755 100644 --- a/docs/0.24/building-for-apple-tv.html +++ b/docs/0.24/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.24/height-and-width.html b/docs/0.24/height-and-width.html index b4ee8304800..37993e9a2a8 100644 --- a/docs/0.24/height-and-width.html +++ b/docs/0.24/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.24/images.html b/docs/0.24/images.html index 9c38e3cd801..a234ad4f734 100644 --- a/docs/0.24/images.html +++ b/docs/0.24/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.24/improvingux.html b/docs/0.24/improvingux.html index 6f7f6bb72f3..a7004181a4d 100644 --- a/docs/0.24/improvingux.html +++ b/docs/0.24/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.24/more-resources.html b/docs/0.24/more-resources.html index bf243ad2cec..6aed3119e82 100644 --- a/docs/0.24/more-resources.html +++ b/docs/0.24/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.24/native-components-android.html b/docs/0.24/native-components-android.html index 40f9ad2e743..94d0d11332d 100644 --- a/docs/0.24/native-components-android.html +++ b/docs/0.24/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.24/native-modules-android.html b/docs/0.24/native-modules-android.html
index b0a7951301d..0c0e5c0bc75 100644
--- a/docs/0.24/native-modules-android.html
+++ b/docs/0.24/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.24/navigation.html b/docs/0.24/navigation.html
index 56f52f085e2..5c436d8a239 100644
--- a/docs/0.24/navigation.html
+++ b/docs/0.24/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.24/network.html b/docs/0.24/network.html
index e4bc8b2bbf8..288ca8c59f6 100644
--- a/docs/0.24/network.html
+++ b/docs/0.24/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.25/app-extensions.html b/docs/0.25/app-extensions.html index c772651ad0c..aa9d5b37536 100644 --- a/docs/0.25/app-extensions.html +++ b/docs/0.25/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.25/building-for-apple-tv.html b/docs/0.25/building-for-apple-tv.html index 8f0ecfaf994..5e2b0cb5eb8 100644 --- a/docs/0.25/building-for-apple-tv.html +++ b/docs/0.25/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.25/height-and-width.html b/docs/0.25/height-and-width.html index 6b2959076e0..ae21b7e9789 100644 --- a/docs/0.25/height-and-width.html +++ b/docs/0.25/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.25/images.html b/docs/0.25/images.html index 3c190837278..b095805b6fb 100644 --- a/docs/0.25/images.html +++ b/docs/0.25/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.25/improvingux.html b/docs/0.25/improvingux.html index f5b2c8e31e7..7183f27d16d 100644 --- a/docs/0.25/improvingux.html +++ b/docs/0.25/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.25/more-resources.html b/docs/0.25/more-resources.html index 25071601c07..c6ff7bc761f 100644 --- a/docs/0.25/more-resources.html +++ b/docs/0.25/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.25/native-components-android.html b/docs/0.25/native-components-android.html index 01d47b99ca7..24950749fcb 100644 --- a/docs/0.25/native-components-android.html +++ b/docs/0.25/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.25/native-modules-android.html b/docs/0.25/native-modules-android.html
index ab707f69f6c..9641d27ea54 100644
--- a/docs/0.25/native-modules-android.html
+++ b/docs/0.25/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.25/navigation.html b/docs/0.25/navigation.html
index daf4d624669..d5a26d2122a 100644
--- a/docs/0.25/navigation.html
+++ b/docs/0.25/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.25/network.html b/docs/0.25/network.html
index d80643c260d..1057ded33d8 100644
--- a/docs/0.25/network.html
+++ b/docs/0.25/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.26/app-extensions.html b/docs/0.26/app-extensions.html index 9934d34dae5..d6862c1c52b 100644 --- a/docs/0.26/app-extensions.html +++ b/docs/0.26/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.26/building-for-apple-tv.html b/docs/0.26/building-for-apple-tv.html index 030fa27b874..2637518579a 100644 --- a/docs/0.26/building-for-apple-tv.html +++ b/docs/0.26/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.26/height-and-width.html b/docs/0.26/height-and-width.html index 65381d99309..7b05c727e4e 100644 --- a/docs/0.26/height-and-width.html +++ b/docs/0.26/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.26/images.html b/docs/0.26/images.html index 586961a7e98..4efc0d043f9 100644 --- a/docs/0.26/images.html +++ b/docs/0.26/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.26/improvingux.html b/docs/0.26/improvingux.html index cfe6a555ba3..24b8183cfed 100644 --- a/docs/0.26/improvingux.html +++ b/docs/0.26/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.26/more-resources.html b/docs/0.26/more-resources.html index b22f62d60a4..1348846ca1e 100644 --- a/docs/0.26/more-resources.html +++ b/docs/0.26/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.26/native-components-android.html b/docs/0.26/native-components-android.html index 8d563075e3c..06b3dd4cdd0 100644 --- a/docs/0.26/native-components-android.html +++ b/docs/0.26/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.26/native-modules-android.html b/docs/0.26/native-modules-android.html
index acccf280c4c..0f213bb9a3e 100644
--- a/docs/0.26/native-modules-android.html
+++ b/docs/0.26/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.26/navigation.html b/docs/0.26/navigation.html
index bb7b4f0aee4..f9d930aeff2 100644
--- a/docs/0.26/navigation.html
+++ b/docs/0.26/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.26/network.html b/docs/0.26/network.html
index f59ff90e9c9..5d2974946df 100644
--- a/docs/0.26/network.html
+++ b/docs/0.26/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.27/app-extensions.html b/docs/0.27/app-extensions.html index adec63ea16e..132160ee683 100644 --- a/docs/0.27/app-extensions.html +++ b/docs/0.27/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.27/building-for-apple-tv.html b/docs/0.27/building-for-apple-tv.html index 35bca154730..9ec811079c1 100644 --- a/docs/0.27/building-for-apple-tv.html +++ b/docs/0.27/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.27/height-and-width.html b/docs/0.27/height-and-width.html index ab45f6ff12e..1ea58e46955 100644 --- a/docs/0.27/height-and-width.html +++ b/docs/0.27/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.27/images.html b/docs/0.27/images.html index 4aec54ac164..85127796d56 100644 --- a/docs/0.27/images.html +++ b/docs/0.27/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.27/improvingux.html b/docs/0.27/improvingux.html index 67be1f2af2e..4746d53e55f 100644 --- a/docs/0.27/improvingux.html +++ b/docs/0.27/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.27/more-resources.html b/docs/0.27/more-resources.html index 309861445be..02579145af5 100644 --- a/docs/0.27/more-resources.html +++ b/docs/0.27/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.27/native-components-android.html b/docs/0.27/native-components-android.html index f763df20321..a92b094af82 100644 --- a/docs/0.27/native-components-android.html +++ b/docs/0.27/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.27/native-modules-android.html b/docs/0.27/native-modules-android.html
index 2cf84f001cf..f15be89575e 100644
--- a/docs/0.27/native-modules-android.html
+++ b/docs/0.27/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.27/navigation.html b/docs/0.27/navigation.html
index 6211eaf6273..71dea7a5476 100644
--- a/docs/0.27/navigation.html
+++ b/docs/0.27/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.27/network.html b/docs/0.27/network.html
index 554bdf95efc..10c3d0465b9 100644
--- a/docs/0.27/network.html
+++ b/docs/0.27/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.28/app-extensions.html b/docs/0.28/app-extensions.html index f34bbe7683d..cecb20c9a52 100644 --- a/docs/0.28/app-extensions.html +++ b/docs/0.28/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.28/building-for-apple-tv.html b/docs/0.28/building-for-apple-tv.html index 6d439fb4234..43ff164ab65 100644 --- a/docs/0.28/building-for-apple-tv.html +++ b/docs/0.28/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.28/height-and-width.html b/docs/0.28/height-and-width.html index 78292ceef38..9d3b886b774 100644 --- a/docs/0.28/height-and-width.html +++ b/docs/0.28/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.28/images.html b/docs/0.28/images.html index e39c794f73a..995524f4578 100644 --- a/docs/0.28/images.html +++ b/docs/0.28/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.28/improvingux.html b/docs/0.28/improvingux.html index 993cc8deace..e0f337a1f74 100644 --- a/docs/0.28/improvingux.html +++ b/docs/0.28/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.28/more-resources.html b/docs/0.28/more-resources.html index 1c08ae0a7ff..d94531cd878 100644 --- a/docs/0.28/more-resources.html +++ b/docs/0.28/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.28/native-components-android.html b/docs/0.28/native-components-android.html index 629c9bae197..8f425ecdab4 100644 --- a/docs/0.28/native-components-android.html +++ b/docs/0.28/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.28/native-modules-android.html b/docs/0.28/native-modules-android.html
index ee6ef14cf9f..b79a183483d 100644
--- a/docs/0.28/native-modules-android.html
+++ b/docs/0.28/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.28/navigation.html b/docs/0.28/navigation.html
index f7f380c2860..fc34d556027 100644
--- a/docs/0.28/navigation.html
+++ b/docs/0.28/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.28/network.html b/docs/0.28/network.html
index 424ac271c93..8fb7a1ae753 100644
--- a/docs/0.28/network.html
+++ b/docs/0.28/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.29/app-extensions.html b/docs/0.29/app-extensions.html index a8e37dcb578..44b1f869eb2 100644 --- a/docs/0.29/app-extensions.html +++ b/docs/0.29/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.29/building-for-apple-tv.html b/docs/0.29/building-for-apple-tv.html index 4415aeb7601..a51268de021 100644 --- a/docs/0.29/building-for-apple-tv.html +++ b/docs/0.29/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.29/height-and-width.html b/docs/0.29/height-and-width.html index 1464d9ec3e6..0edfd9eb470 100644 --- a/docs/0.29/height-and-width.html +++ b/docs/0.29/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.29/images.html b/docs/0.29/images.html index 0ad9bea34f7..03ec0d5501d 100644 --- a/docs/0.29/images.html +++ b/docs/0.29/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.29/improvingux.html b/docs/0.29/improvingux.html index 15297f74b63..74be2e23f75 100644 --- a/docs/0.29/improvingux.html +++ b/docs/0.29/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.29/more-resources.html b/docs/0.29/more-resources.html index 770eabc0905..c3f01a0a552 100644 --- a/docs/0.29/more-resources.html +++ b/docs/0.29/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.29/native-components-android.html b/docs/0.29/native-components-android.html index 1d7a5987f86..57c6a76d2a5 100644 --- a/docs/0.29/native-components-android.html +++ b/docs/0.29/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.29/native-modules-android.html b/docs/0.29/native-modules-android.html
index 761856f3713..6ad4af2752c 100644
--- a/docs/0.29/native-modules-android.html
+++ b/docs/0.29/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.29/navigation.html b/docs/0.29/navigation.html
index ec539105c2a..cf5648b5ec6 100644
--- a/docs/0.29/navigation.html
+++ b/docs/0.29/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.29/network.html b/docs/0.29/network.html
index c6bd99f4117..ab19dbced1b 100644
--- a/docs/0.29/network.html
+++ b/docs/0.29/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.30/app-extensions.html b/docs/0.30/app-extensions.html index 82ea12cdb43..fba1b6131d4 100644 --- a/docs/0.30/app-extensions.html +++ b/docs/0.30/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.30/building-for-apple-tv.html b/docs/0.30/building-for-apple-tv.html index c47ab34b3a3..6da2fd7f415 100644 --- a/docs/0.30/building-for-apple-tv.html +++ b/docs/0.30/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.30/height-and-width.html b/docs/0.30/height-and-width.html index 82553487949..fd13291ebf3 100644 --- a/docs/0.30/height-and-width.html +++ b/docs/0.30/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.30/images.html b/docs/0.30/images.html index 879c1e3ebf7..d3e8d316d80 100644 --- a/docs/0.30/images.html +++ b/docs/0.30/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.30/improvingux.html b/docs/0.30/improvingux.html index a5dce6db05c..6bf64de88bd 100644 --- a/docs/0.30/improvingux.html +++ b/docs/0.30/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.30/more-resources.html b/docs/0.30/more-resources.html index 1b11e14dcf5..391a705fc60 100644 --- a/docs/0.30/more-resources.html +++ b/docs/0.30/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.30/native-components-android.html b/docs/0.30/native-components-android.html index a0dc25a7759..2c12cbd79c6 100644 --- a/docs/0.30/native-components-android.html +++ b/docs/0.30/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.30/native-modules-android.html b/docs/0.30/native-modules-android.html
index ca6dc6fdd28..b753fa1091a 100644
--- a/docs/0.30/native-modules-android.html
+++ b/docs/0.30/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.30/navigation.html b/docs/0.30/navigation.html
index 603bbe243ae..c0a8520677d 100644
--- a/docs/0.30/navigation.html
+++ b/docs/0.30/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.30/network.html b/docs/0.30/network.html
index cb5605dc77c..68e77f10b8a 100644
--- a/docs/0.30/network.html
+++ b/docs/0.30/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.31/app-extensions.html b/docs/0.31/app-extensions.html index 7396b627aa7..1e1dd699161 100644 --- a/docs/0.31/app-extensions.html +++ b/docs/0.31/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.31/building-for-apple-tv.html b/docs/0.31/building-for-apple-tv.html index 36fd27cb624..0b0e79c2a45 100644 --- a/docs/0.31/building-for-apple-tv.html +++ b/docs/0.31/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.31/height-and-width.html b/docs/0.31/height-and-width.html index f0570a603b9..09cd7bf5755 100644 --- a/docs/0.31/height-and-width.html +++ b/docs/0.31/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.31/images.html b/docs/0.31/images.html index d70ef7177a9..815c101d635 100644 --- a/docs/0.31/images.html +++ b/docs/0.31/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.31/improvingux.html b/docs/0.31/improvingux.html index b9d3364036b..dfe6cc2625b 100644 --- a/docs/0.31/improvingux.html +++ b/docs/0.31/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.31/more-resources.html b/docs/0.31/more-resources.html index dfad0d48f3e..da6a15163cd 100644 --- a/docs/0.31/more-resources.html +++ b/docs/0.31/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.31/native-components-android.html b/docs/0.31/native-components-android.html index 0519fb2000f..887eb42865d 100644 --- a/docs/0.31/native-components-android.html +++ b/docs/0.31/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.31/native-modules-android.html b/docs/0.31/native-modules-android.html
index 1f50a7c69cd..8408311f650 100644
--- a/docs/0.31/native-modules-android.html
+++ b/docs/0.31/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.31/navigation.html b/docs/0.31/navigation.html
index 15ba6fa258b..8cfc0c0840d 100644
--- a/docs/0.31/navigation.html
+++ b/docs/0.31/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.31/network.html b/docs/0.31/network.html
index c51f18639c3..60f81f9c7d2 100644
--- a/docs/0.31/network.html
+++ b/docs/0.31/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.32/app-extensions.html b/docs/0.32/app-extensions.html index 44e349cb280..d8501fa7fee 100644 --- a/docs/0.32/app-extensions.html +++ b/docs/0.32/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.32/building-for-apple-tv.html b/docs/0.32/building-for-apple-tv.html index 67e5a1827f6..d0bb9918881 100644 --- a/docs/0.32/building-for-apple-tv.html +++ b/docs/0.32/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.32/height-and-width.html b/docs/0.32/height-and-width.html index 4809d05722d..520f5cebd2c 100644 --- a/docs/0.32/height-and-width.html +++ b/docs/0.32/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.32/images.html b/docs/0.32/images.html index 3813498dfd4..1df3207e9dd 100644 --- a/docs/0.32/images.html +++ b/docs/0.32/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.32/improvingux.html b/docs/0.32/improvingux.html index 07402f497f8..b4af71d508d 100644 --- a/docs/0.32/improvingux.html +++ b/docs/0.32/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.32/more-resources.html b/docs/0.32/more-resources.html index 2bf0ba56504..82dc01f5fdf 100644 --- a/docs/0.32/more-resources.html +++ b/docs/0.32/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.32/native-components-android.html b/docs/0.32/native-components-android.html index 0af825dd38f..82895981454 100644 --- a/docs/0.32/native-components-android.html +++ b/docs/0.32/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.32/native-modules-android.html b/docs/0.32/native-modules-android.html
index 885fec4e81b..4cce06a2dfa 100644
--- a/docs/0.32/native-modules-android.html
+++ b/docs/0.32/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.32/navigation.html b/docs/0.32/navigation.html
index c3cd46ab792..d5eaff1d8e7 100644
--- a/docs/0.32/navigation.html
+++ b/docs/0.32/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.32/network.html b/docs/0.32/network.html
index c44b0d35fbb..997803ba031 100644
--- a/docs/0.32/network.html
+++ b/docs/0.32/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.33/app-extensions.html b/docs/0.33/app-extensions.html index 2d2ed97d3e7..09c1524fc55 100644 --- a/docs/0.33/app-extensions.html +++ b/docs/0.33/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.33/building-for-apple-tv.html b/docs/0.33/building-for-apple-tv.html index 5b28a62627b..c9017e7f115 100644 --- a/docs/0.33/building-for-apple-tv.html +++ b/docs/0.33/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.33/height-and-width.html b/docs/0.33/height-and-width.html index 5c021a0a882..d395daed0ef 100644 --- a/docs/0.33/height-and-width.html +++ b/docs/0.33/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.33/images.html b/docs/0.33/images.html index e857d4f9f24..ae4f3bbf168 100644 --- a/docs/0.33/images.html +++ b/docs/0.33/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.33/improvingux.html b/docs/0.33/improvingux.html index 09938d8dc9f..e322fcd4b5c 100644 --- a/docs/0.33/improvingux.html +++ b/docs/0.33/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.33/more-resources.html b/docs/0.33/more-resources.html index ce8829d2ca1..895ab4e944f 100644 --- a/docs/0.33/more-resources.html +++ b/docs/0.33/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.33/native-components-android.html b/docs/0.33/native-components-android.html index 81df9f41b33..102ca933c9c 100644 --- a/docs/0.33/native-components-android.html +++ b/docs/0.33/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.33/native-modules-android.html b/docs/0.33/native-modules-android.html
index e73d7dfcf16..6503acfda46 100644
--- a/docs/0.33/native-modules-android.html
+++ b/docs/0.33/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.33/navigation.html b/docs/0.33/navigation.html
index 4e274ab547e..80ffd76c64f 100644
--- a/docs/0.33/navigation.html
+++ b/docs/0.33/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.33/network.html b/docs/0.33/network.html
index 454e89efc41..2c9cf77f63c 100644
--- a/docs/0.33/network.html
+++ b/docs/0.33/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.34/app-extensions.html b/docs/0.34/app-extensions.html index 525de2c521e..d412eb395c1 100644 --- a/docs/0.34/app-extensions.html +++ b/docs/0.34/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.34/building-for-apple-tv.html b/docs/0.34/building-for-apple-tv.html index d2f9366b314..d2099e87531 100644 --- a/docs/0.34/building-for-apple-tv.html +++ b/docs/0.34/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.34/height-and-width.html b/docs/0.34/height-and-width.html index 8143b130803..17c538a5230 100644 --- a/docs/0.34/height-and-width.html +++ b/docs/0.34/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.34/images.html b/docs/0.34/images.html index 9070d9cddc0..399410c111c 100644 --- a/docs/0.34/images.html +++ b/docs/0.34/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.34/improvingux.html b/docs/0.34/improvingux.html index 58da1ab6bed..1831aa251b7 100644 --- a/docs/0.34/improvingux.html +++ b/docs/0.34/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.34/more-resources.html b/docs/0.34/more-resources.html index 4d1b3804949..8b13c95a9d1 100644 --- a/docs/0.34/more-resources.html +++ b/docs/0.34/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.34/native-components-android.html b/docs/0.34/native-components-android.html index 083f6be2027..d10a438e8fa 100644 --- a/docs/0.34/native-components-android.html +++ b/docs/0.34/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.34/native-modules-android.html b/docs/0.34/native-modules-android.html
index 779962f127b..7efc8b7f238 100644
--- a/docs/0.34/native-modules-android.html
+++ b/docs/0.34/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.34/navigation.html b/docs/0.34/navigation.html
index 9c22679284f..2af15b8cba9 100644
--- a/docs/0.34/navigation.html
+++ b/docs/0.34/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.34/network.html b/docs/0.34/network.html
index 4a8eaad2522..088d5efe9b3 100644
--- a/docs/0.34/network.html
+++ b/docs/0.34/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.35/app-extensions.html b/docs/0.35/app-extensions.html index cf56ad87806..1af8ee699b2 100644 --- a/docs/0.35/app-extensions.html +++ b/docs/0.35/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.35/building-for-apple-tv.html b/docs/0.35/building-for-apple-tv.html index cfe137cca6b..08f8db9d7a4 100644 --- a/docs/0.35/building-for-apple-tv.html +++ b/docs/0.35/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.35/height-and-width.html b/docs/0.35/height-and-width.html index 9b55b048cd0..51b3741d4ff 100644 --- a/docs/0.35/height-and-width.html +++ b/docs/0.35/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.35/images.html b/docs/0.35/images.html index 0001c8be6d2..71e22b9d0b8 100644 --- a/docs/0.35/images.html +++ b/docs/0.35/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.35/improvingux.html b/docs/0.35/improvingux.html index 493322b5cd7..49100d08d6b 100644 --- a/docs/0.35/improvingux.html +++ b/docs/0.35/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.35/more-resources.html b/docs/0.35/more-resources.html index ca19c6315fe..b173258cc35 100644 --- a/docs/0.35/more-resources.html +++ b/docs/0.35/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.35/native-components-android.html b/docs/0.35/native-components-android.html index 814fd8d5495..8e1c7d2c585 100644 --- a/docs/0.35/native-components-android.html +++ b/docs/0.35/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.35/native-modules-android.html b/docs/0.35/native-modules-android.html
index d248a2c5505..82d88d9b2d0 100644
--- a/docs/0.35/native-modules-android.html
+++ b/docs/0.35/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.35/navigation.html b/docs/0.35/navigation.html
index d63652aa2d3..54c6e40cb5c 100644
--- a/docs/0.35/navigation.html
+++ b/docs/0.35/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.35/network.html b/docs/0.35/network.html
index 5eb7e22745f..d0727d41337 100644
--- a/docs/0.35/network.html
+++ b/docs/0.35/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.36/app-extensions.html b/docs/0.36/app-extensions.html index af916352d1e..d8a7cdb4df0 100644 --- a/docs/0.36/app-extensions.html +++ b/docs/0.36/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.36/building-for-apple-tv.html b/docs/0.36/building-for-apple-tv.html index 7edddfc7e95..072bfc8c7b1 100644 --- a/docs/0.36/building-for-apple-tv.html +++ b/docs/0.36/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.36/height-and-width.html b/docs/0.36/height-and-width.html index 15ebce0c407..3bca9229413 100644 --- a/docs/0.36/height-and-width.html +++ b/docs/0.36/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.36/images.html b/docs/0.36/images.html index a8475798b06..32cb54c85d6 100644 --- a/docs/0.36/images.html +++ b/docs/0.36/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.36/improvingux.html b/docs/0.36/improvingux.html index 49f40562b82..6e334e1c8fe 100644 --- a/docs/0.36/improvingux.html +++ b/docs/0.36/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.36/more-resources.html b/docs/0.36/more-resources.html index 60e2e784a3d..bc3d57fa13c 100644 --- a/docs/0.36/more-resources.html +++ b/docs/0.36/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.36/native-components-android.html b/docs/0.36/native-components-android.html index db5c1e46090..2ddabe27ad8 100644 --- a/docs/0.36/native-components-android.html +++ b/docs/0.36/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.36/native-modules-android.html b/docs/0.36/native-modules-android.html
index ddc95391c5d..bb058b0dfe3 100644
--- a/docs/0.36/native-modules-android.html
+++ b/docs/0.36/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.36/navigation.html b/docs/0.36/navigation.html
index 24a574473e3..393490f70be 100644
--- a/docs/0.36/navigation.html
+++ b/docs/0.36/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.36/network.html b/docs/0.36/network.html
index ab7fd352667..56953315ab7 100644
--- a/docs/0.36/network.html
+++ b/docs/0.36/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.37/app-extensions.html b/docs/0.37/app-extensions.html index c2d893e4d96..6df979c149b 100644 --- a/docs/0.37/app-extensions.html +++ b/docs/0.37/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.37/building-for-apple-tv.html b/docs/0.37/building-for-apple-tv.html index 44b81ebe781..cdd66ddd51e 100644 --- a/docs/0.37/building-for-apple-tv.html +++ b/docs/0.37/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.37/height-and-width.html b/docs/0.37/height-and-width.html index 9a3b84332a7..865993bdfc2 100644 --- a/docs/0.37/height-and-width.html +++ b/docs/0.37/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.37/images.html b/docs/0.37/images.html index 252e3c28847..b3aac5d85c2 100644 --- a/docs/0.37/images.html +++ b/docs/0.37/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.37/improvingux.html b/docs/0.37/improvingux.html index d3fc1fa1bac..201e7fc56a9 100644 --- a/docs/0.37/improvingux.html +++ b/docs/0.37/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.37/more-resources.html b/docs/0.37/more-resources.html index 67cd05db16d..514042edebf 100644 --- a/docs/0.37/more-resources.html +++ b/docs/0.37/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.37/native-components-android.html b/docs/0.37/native-components-android.html index 0332a150033..4729efd780c 100644 --- a/docs/0.37/native-components-android.html +++ b/docs/0.37/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.37/native-modules-android.html b/docs/0.37/native-modules-android.html
index 7dc0e1889a8..2a6b2a41c53 100644
--- a/docs/0.37/native-modules-android.html
+++ b/docs/0.37/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.37/navigation.html b/docs/0.37/navigation.html
index 4bc172d8a48..13c5b196dc0 100644
--- a/docs/0.37/navigation.html
+++ b/docs/0.37/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.37/network.html b/docs/0.37/network.html
index 59692311669..f2482b9ae22 100644
--- a/docs/0.37/network.html
+++ b/docs/0.37/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.38/app-extensions.html b/docs/0.38/app-extensions.html index 73b9aad6cb7..fb5e2e043ba 100644 --- a/docs/0.38/app-extensions.html +++ b/docs/0.38/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.38/building-for-apple-tv.html b/docs/0.38/building-for-apple-tv.html index bc9d0d9007f..90af7e2797c 100644 --- a/docs/0.38/building-for-apple-tv.html +++ b/docs/0.38/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.38/height-and-width.html b/docs/0.38/height-and-width.html index ef8c351deab..a145c1d2f3d 100644 --- a/docs/0.38/height-and-width.html +++ b/docs/0.38/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.38/images.html b/docs/0.38/images.html index dbddec106d5..8a81b0f25d6 100644 --- a/docs/0.38/images.html +++ b/docs/0.38/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.38/improvingux.html b/docs/0.38/improvingux.html index 8a44198602d..1f86d2e0c43 100644 --- a/docs/0.38/improvingux.html +++ b/docs/0.38/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.38/more-resources.html b/docs/0.38/more-resources.html index 6fa12f0172a..e12abc5723a 100644 --- a/docs/0.38/more-resources.html +++ b/docs/0.38/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.38/native-components-android.html b/docs/0.38/native-components-android.html index 3dc1aac86da..e04577ffbb5 100644 --- a/docs/0.38/native-components-android.html +++ b/docs/0.38/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.38/native-modules-android.html b/docs/0.38/native-modules-android.html
index cee5732e6b7..02a6546eca5 100644
--- a/docs/0.38/native-modules-android.html
+++ b/docs/0.38/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.38/navigation.html b/docs/0.38/navigation.html
index 6817286d102..a4ec95af82a 100644
--- a/docs/0.38/navigation.html
+++ b/docs/0.38/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.38/network.html b/docs/0.38/network.html
index 9ea9dec373f..76559383dd7 100644
--- a/docs/0.38/network.html
+++ b/docs/0.38/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.39/app-extensions.html b/docs/0.39/app-extensions.html index 2653b3d64fe..0caaca1dc43 100644 --- a/docs/0.39/app-extensions.html +++ b/docs/0.39/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.39/building-for-apple-tv.html b/docs/0.39/building-for-apple-tv.html index a16d6afef60..d3e12895cab 100644 --- a/docs/0.39/building-for-apple-tv.html +++ b/docs/0.39/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.39/height-and-width.html b/docs/0.39/height-and-width.html index 5c60e2a1e06..8f02b307cd0 100644 --- a/docs/0.39/height-and-width.html +++ b/docs/0.39/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.39/images.html b/docs/0.39/images.html index 800b35f6245..8cbe1dfbcc5 100644 --- a/docs/0.39/images.html +++ b/docs/0.39/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.39/improvingux.html b/docs/0.39/improvingux.html index 5ff3fd9280a..2a0cb8dfa03 100644 --- a/docs/0.39/improvingux.html +++ b/docs/0.39/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.39/more-resources.html b/docs/0.39/more-resources.html index c9355d067ce..e67d50ab0f9 100644 --- a/docs/0.39/more-resources.html +++ b/docs/0.39/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.39/native-components-android.html b/docs/0.39/native-components-android.html index 44dc24b10b0..793b9933b2c 100644 --- a/docs/0.39/native-components-android.html +++ b/docs/0.39/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.39/native-modules-android.html b/docs/0.39/native-modules-android.html
index 4d9d1cf31f4..bac0de9a0a1 100644
--- a/docs/0.39/native-modules-android.html
+++ b/docs/0.39/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.39/navigation.html b/docs/0.39/navigation.html
index 45ae72a59dd..0a5104ac97e 100644
--- a/docs/0.39/navigation.html
+++ b/docs/0.39/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.39/network.html b/docs/0.39/network.html
index d6477cbd6d5..4f3b2dc2c64 100644
--- a/docs/0.39/network.html
+++ b/docs/0.39/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.40/app-extensions.html b/docs/0.40/app-extensions.html index 9f5997f8701..a0f3f298c11 100644 --- a/docs/0.40/app-extensions.html +++ b/docs/0.40/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.40/building-for-apple-tv.html b/docs/0.40/building-for-apple-tv.html index e8470b965ad..e883f582786 100644 --- a/docs/0.40/building-for-apple-tv.html +++ b/docs/0.40/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.40/height-and-width.html b/docs/0.40/height-and-width.html index 8525e9a6e16..af576f9bf27 100644 --- a/docs/0.40/height-and-width.html +++ b/docs/0.40/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.40/images.html b/docs/0.40/images.html index db8ef9e50b3..8b7cbf35ce1 100644 --- a/docs/0.40/images.html +++ b/docs/0.40/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.40/improvingux.html b/docs/0.40/improvingux.html index b06761a99cd..3c0de6feffd 100644 --- a/docs/0.40/improvingux.html +++ b/docs/0.40/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.40/more-resources.html b/docs/0.40/more-resources.html index b07c2275592..611587fcec9 100644 --- a/docs/0.40/more-resources.html +++ b/docs/0.40/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.40/native-components-android.html b/docs/0.40/native-components-android.html index 271e471f74e..b414ce4e06a 100644 --- a/docs/0.40/native-components-android.html +++ b/docs/0.40/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.40/native-modules-android.html b/docs/0.40/native-modules-android.html
index 453b7d46d8b..8672669771e 100644
--- a/docs/0.40/native-modules-android.html
+++ b/docs/0.40/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.40/navigation.html b/docs/0.40/navigation.html
index 7f1f2554ab7..9c3da79759f 100644
--- a/docs/0.40/navigation.html
+++ b/docs/0.40/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.40/network.html b/docs/0.40/network.html
index 34c47919f1b..43a3f74455c 100644
--- a/docs/0.40/network.html
+++ b/docs/0.40/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.41/app-extensions.html b/docs/0.41/app-extensions.html index 6fbdba86a11..36408b7cdf7 100644 --- a/docs/0.41/app-extensions.html +++ b/docs/0.41/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.41/building-for-apple-tv.html b/docs/0.41/building-for-apple-tv.html index 8516e35daba..1ed55f723aa 100644 --- a/docs/0.41/building-for-apple-tv.html +++ b/docs/0.41/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.41/height-and-width.html b/docs/0.41/height-and-width.html index 6998d2afb1f..6d39b889c4a 100644 --- a/docs/0.41/height-and-width.html +++ b/docs/0.41/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.41/images.html b/docs/0.41/images.html index be6f00f91d5..116222417ae 100644 --- a/docs/0.41/images.html +++ b/docs/0.41/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.41/improvingux.html b/docs/0.41/improvingux.html index d9cbc983f70..f6d9c090b86 100644 --- a/docs/0.41/improvingux.html +++ b/docs/0.41/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.41/more-resources.html b/docs/0.41/more-resources.html index dbc5558fbe1..d7d26ee32d6 100644 --- a/docs/0.41/more-resources.html +++ b/docs/0.41/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.41/native-components-android.html b/docs/0.41/native-components-android.html index 784e3535c74..8148afcd307 100644 --- a/docs/0.41/native-components-android.html +++ b/docs/0.41/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.41/native-modules-android.html b/docs/0.41/native-modules-android.html
index 539ea1c9a55..8ee06a89ec2 100644
--- a/docs/0.41/native-modules-android.html
+++ b/docs/0.41/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.41/navigation.html b/docs/0.41/navigation.html
index 39438eb37bd..dcc02a9358c 100644
--- a/docs/0.41/navigation.html
+++ b/docs/0.41/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.41/network.html b/docs/0.41/network.html
index f33a30cb9a0..c4bdbf17fc2 100644
--- a/docs/0.41/network.html
+++ b/docs/0.41/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.42/app-extensions.html b/docs/0.42/app-extensions.html index 1f23f5b79d7..bb30c0308d9 100644 --- a/docs/0.42/app-extensions.html +++ b/docs/0.42/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.42/building-for-apple-tv.html b/docs/0.42/building-for-apple-tv.html index 8e6e13969f1..98b35f638a1 100644 --- a/docs/0.42/building-for-apple-tv.html +++ b/docs/0.42/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.42/height-and-width.html b/docs/0.42/height-and-width.html index b3b9819889c..2655dc96434 100644 --- a/docs/0.42/height-and-width.html +++ b/docs/0.42/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.42/images.html b/docs/0.42/images.html index a17bc7f0364..83df9167d91 100644 --- a/docs/0.42/images.html +++ b/docs/0.42/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.42/improvingux.html b/docs/0.42/improvingux.html index 22d27201f73..5dad3929616 100644 --- a/docs/0.42/improvingux.html +++ b/docs/0.42/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.42/more-resources.html b/docs/0.42/more-resources.html index a1f60e06678..d26e6c592cb 100644 --- a/docs/0.42/more-resources.html +++ b/docs/0.42/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.42/native-components-android.html b/docs/0.42/native-components-android.html index aa853a5faff..5887c1853cc 100644 --- a/docs/0.42/native-components-android.html +++ b/docs/0.42/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.42/native-modules-android.html b/docs/0.42/native-modules-android.html
index 93a1877abc4..b52792ebe67 100644
--- a/docs/0.42/native-modules-android.html
+++ b/docs/0.42/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.42/navigation.html b/docs/0.42/navigation.html
index 5fcf2864042..efc5eec05c0 100644
--- a/docs/0.42/navigation.html
+++ b/docs/0.42/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.42/network.html b/docs/0.42/network.html
index 7e28a81e2f7..6bf7624b2c1 100644
--- a/docs/0.42/network.html
+++ b/docs/0.42/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.43/app-extensions.html b/docs/0.43/app-extensions.html index 18fc6de3665..10ea3657abf 100644 --- a/docs/0.43/app-extensions.html +++ b/docs/0.43/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.43/building-for-apple-tv.html b/docs/0.43/building-for-apple-tv.html index 95db2a3ae53..7697f8863f4 100644 --- a/docs/0.43/building-for-apple-tv.html +++ b/docs/0.43/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.43/height-and-width.html b/docs/0.43/height-and-width.html index 5279e0d7be0..331e47e590a 100644 --- a/docs/0.43/height-and-width.html +++ b/docs/0.43/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.43/images.html b/docs/0.43/images.html index 93140651d78..a8dc60e8980 100644 --- a/docs/0.43/images.html +++ b/docs/0.43/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.43/improvingux.html b/docs/0.43/improvingux.html index a3d726d3d42..8ff49719889 100644 --- a/docs/0.43/improvingux.html +++ b/docs/0.43/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.43/more-resources.html b/docs/0.43/more-resources.html index ea9b24b880e..955372666e5 100644 --- a/docs/0.43/more-resources.html +++ b/docs/0.43/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.43/native-components-android.html b/docs/0.43/native-components-android.html index 4f281e307e7..db9f744dd26 100644 --- a/docs/0.43/native-components-android.html +++ b/docs/0.43/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.43/native-modules-android.html b/docs/0.43/native-modules-android.html
index fed9e8c13ab..c87da222e89 100644
--- a/docs/0.43/native-modules-android.html
+++ b/docs/0.43/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.43/navigation.html b/docs/0.43/navigation.html
index 9fd6d429347..cd43fc21e70 100644
--- a/docs/0.43/navigation.html
+++ b/docs/0.43/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.43/network.html b/docs/0.43/network.html
index 7a855b3a074..079dd25d3a2 100644
--- a/docs/0.43/network.html
+++ b/docs/0.43/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.44/app-extensions.html b/docs/0.44/app-extensions.html index ae4ce491a92..d63eacbed94 100644 --- a/docs/0.44/app-extensions.html +++ b/docs/0.44/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.44/building-for-apple-tv.html b/docs/0.44/building-for-apple-tv.html index c889a69b495..d26f4d6205f 100644 --- a/docs/0.44/building-for-apple-tv.html +++ b/docs/0.44/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.44/height-and-width.html b/docs/0.44/height-and-width.html index 9339fe2ac0a..e5465b0aea5 100644 --- a/docs/0.44/height-and-width.html +++ b/docs/0.44/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.44/images.html b/docs/0.44/images.html index 12124e4284e..0921f191bd4 100644 --- a/docs/0.44/images.html +++ b/docs/0.44/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.44/improvingux.html b/docs/0.44/improvingux.html index 14fad337083..80c0589edf7 100644 --- a/docs/0.44/improvingux.html +++ b/docs/0.44/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.44/more-resources.html b/docs/0.44/more-resources.html index bed02a487d3..85053592862 100644 --- a/docs/0.44/more-resources.html +++ b/docs/0.44/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.44/native-components-android.html b/docs/0.44/native-components-android.html index 7af14e1d379..69bd7c247b6 100644 --- a/docs/0.44/native-components-android.html +++ b/docs/0.44/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.44/native-modules-android.html b/docs/0.44/native-modules-android.html
index d5403967bda..4cdeef00726 100644
--- a/docs/0.44/native-modules-android.html
+++ b/docs/0.44/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.44/navigation.html b/docs/0.44/navigation.html
index eb597a4e495..f5c50ee6a27 100644
--- a/docs/0.44/navigation.html
+++ b/docs/0.44/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.44/network.html b/docs/0.44/network.html
index 2c759ce6879..8c8c6421c6d 100644
--- a/docs/0.44/network.html
+++ b/docs/0.44/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.45/app-extensions.html b/docs/0.45/app-extensions.html index 156656fd52c..3918d1ddc2d 100644 --- a/docs/0.45/app-extensions.html +++ b/docs/0.45/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.45/building-for-apple-tv.html b/docs/0.45/building-for-apple-tv.html index 997b8d8e19a..0a3c34f67be 100644 --- a/docs/0.45/building-for-apple-tv.html +++ b/docs/0.45/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.45/height-and-width.html b/docs/0.45/height-and-width.html index 4e1198f0251..7ff5e8cacc1 100644 --- a/docs/0.45/height-and-width.html +++ b/docs/0.45/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.45/images.html b/docs/0.45/images.html index 52c230c9a1e..6e7ef238fde 100644 --- a/docs/0.45/images.html +++ b/docs/0.45/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.45/improvingux.html b/docs/0.45/improvingux.html index b2d98f07dbf..198e1dd2005 100644 --- a/docs/0.45/improvingux.html +++ b/docs/0.45/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.45/more-resources.html b/docs/0.45/more-resources.html index cf788d32735..93ec83cedff 100644 --- a/docs/0.45/more-resources.html +++ b/docs/0.45/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.45/native-components-android.html b/docs/0.45/native-components-android.html index fec72f26139..eb0ab2f30da 100644 --- a/docs/0.45/native-components-android.html +++ b/docs/0.45/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.45/native-modules-android.html b/docs/0.45/native-modules-android.html
index bd68c067b81..92bcb994c71 100644
--- a/docs/0.45/native-modules-android.html
+++ b/docs/0.45/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.45/navigation.html b/docs/0.45/navigation.html
index 4cdaee668b4..c0873845680 100644
--- a/docs/0.45/navigation.html
+++ b/docs/0.45/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.45/network.html b/docs/0.45/network.html
index 963c7bf727c..6d081f1d7b0 100644
--- a/docs/0.45/network.html
+++ b/docs/0.45/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.46/app-extensions.html b/docs/0.46/app-extensions.html index 44f6c31f357..83aac1aae70 100644 --- a/docs/0.46/app-extensions.html +++ b/docs/0.46/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.46/building-for-apple-tv.html b/docs/0.46/building-for-apple-tv.html index 95f655d6ae8..9fbb9e94110 100644 --- a/docs/0.46/building-for-apple-tv.html +++ b/docs/0.46/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.46/height-and-width.html b/docs/0.46/height-and-width.html index f10cf7d2ede..f3ca43f94f3 100644 --- a/docs/0.46/height-and-width.html +++ b/docs/0.46/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.46/images.html b/docs/0.46/images.html index ab98933c5f1..0fcef721eb6 100644 --- a/docs/0.46/images.html +++ b/docs/0.46/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.46/improvingux.html b/docs/0.46/improvingux.html index fe5109e88e7..658eb899cb6 100644 --- a/docs/0.46/improvingux.html +++ b/docs/0.46/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.46/more-resources.html b/docs/0.46/more-resources.html index b960ab0d6b7..fc6d282f6f3 100644 --- a/docs/0.46/more-resources.html +++ b/docs/0.46/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.46/native-components-android.html b/docs/0.46/native-components-android.html index b5f31c81282..a590a5bd436 100644 --- a/docs/0.46/native-components-android.html +++ b/docs/0.46/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.46/native-modules-android.html b/docs/0.46/native-modules-android.html
index 71a7469bbc4..cefec83470d 100644
--- a/docs/0.46/native-modules-android.html
+++ b/docs/0.46/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.46/navigation.html b/docs/0.46/navigation.html
index df58c28a8bf..ca7632b8458 100644
--- a/docs/0.46/navigation.html
+++ b/docs/0.46/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.46/network.html b/docs/0.46/network.html
index 8d43398b071..f1980c92e3f 100644
--- a/docs/0.46/network.html
+++ b/docs/0.46/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.47/app-extensions.html b/docs/0.47/app-extensions.html index 5f9876f58fe..2a5e85a692c 100644 --- a/docs/0.47/app-extensions.html +++ b/docs/0.47/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.47/building-for-apple-tv.html b/docs/0.47/building-for-apple-tv.html index 226ad7cf2f1..d2406729313 100644 --- a/docs/0.47/building-for-apple-tv.html +++ b/docs/0.47/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.47/height-and-width.html b/docs/0.47/height-and-width.html index db3d9e04c60..44512b7069d 100644 --- a/docs/0.47/height-and-width.html +++ b/docs/0.47/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.47/images.html b/docs/0.47/images.html index 5b28033191a..b8f356ce1c4 100644 --- a/docs/0.47/images.html +++ b/docs/0.47/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.47/improvingux.html b/docs/0.47/improvingux.html index 0f24aa97b93..2c81e94ea95 100644 --- a/docs/0.47/improvingux.html +++ b/docs/0.47/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.47/more-resources.html b/docs/0.47/more-resources.html index e26a4d6b06f..555596c0199 100644 --- a/docs/0.47/more-resources.html +++ b/docs/0.47/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.47/native-components-android.html b/docs/0.47/native-components-android.html index 1200dc02a29..8f0b0661c7a 100644 --- a/docs/0.47/native-components-android.html +++ b/docs/0.47/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.47/native-modules-android.html b/docs/0.47/native-modules-android.html
index 31031c8dfa0..3e4372e99a9 100644
--- a/docs/0.47/native-modules-android.html
+++ b/docs/0.47/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.47/navigation.html b/docs/0.47/navigation.html
index 6e4ef93aafe..25b001e2d0e 100644
--- a/docs/0.47/navigation.html
+++ b/docs/0.47/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.47/network.html b/docs/0.47/network.html
index 71bb6e69f42..353d6cb8c9c 100644
--- a/docs/0.47/network.html
+++ b/docs/0.47/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.48/app-extensions.html b/docs/0.48/app-extensions.html index c428f5774b1..090b9c65922 100644 --- a/docs/0.48/app-extensions.html +++ b/docs/0.48/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.48/building-for-apple-tv.html b/docs/0.48/building-for-apple-tv.html index 112190a7d91..4b070e457f9 100644 --- a/docs/0.48/building-for-apple-tv.html +++ b/docs/0.48/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.48/height-and-width.html b/docs/0.48/height-and-width.html index a0d00dd9894..d356d5da70a 100644 --- a/docs/0.48/height-and-width.html +++ b/docs/0.48/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.48/images.html b/docs/0.48/images.html index d51bf6cf8dc..dbb4132f11b 100644 --- a/docs/0.48/images.html +++ b/docs/0.48/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.48/improvingux.html b/docs/0.48/improvingux.html index 0c0e5c49927..6a13a58f8ae 100644 --- a/docs/0.48/improvingux.html +++ b/docs/0.48/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.48/more-resources.html b/docs/0.48/more-resources.html index c7b96603dd1..5a8fe8ca62f 100644 --- a/docs/0.48/more-resources.html +++ b/docs/0.48/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.48/native-components-android.html b/docs/0.48/native-components-android.html index 89c252c5865..1aa23509e5f 100644 --- a/docs/0.48/native-components-android.html +++ b/docs/0.48/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.48/native-modules-android.html b/docs/0.48/native-modules-android.html
index a489048ed5f..75e48fd749f 100644
--- a/docs/0.48/native-modules-android.html
+++ b/docs/0.48/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.48/navigation.html b/docs/0.48/navigation.html
index 90fa7d4b4f5..561b1d704c6 100644
--- a/docs/0.48/navigation.html
+++ b/docs/0.48/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.48/network.html b/docs/0.48/network.html
index 6bd9c22afda..189e5f44a55 100644
--- a/docs/0.48/network.html
+++ b/docs/0.48/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.49/app-extensions.html b/docs/0.49/app-extensions.html index b47690dd734..d030c44a357 100644 --- a/docs/0.49/app-extensions.html +++ b/docs/0.49/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.49/building-for-apple-tv.html b/docs/0.49/building-for-apple-tv.html index 4578f07300a..8776810b096 100644 --- a/docs/0.49/building-for-apple-tv.html +++ b/docs/0.49/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.49/height-and-width.html b/docs/0.49/height-and-width.html index 205c48faf94..7557b1cbe2a 100644 --- a/docs/0.49/height-and-width.html +++ b/docs/0.49/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.49/images.html b/docs/0.49/images.html index dc2c5894166..2d1ddd02b56 100644 --- a/docs/0.49/images.html +++ b/docs/0.49/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.49/improvingux.html b/docs/0.49/improvingux.html index 1d09dd403c5..455d6735a61 100644 --- a/docs/0.49/improvingux.html +++ b/docs/0.49/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.49/more-resources.html b/docs/0.49/more-resources.html index a6c997d7126..9eae3dfb1a4 100644 --- a/docs/0.49/more-resources.html +++ b/docs/0.49/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.49/native-components-android.html b/docs/0.49/native-components-android.html index 01d6d0484b3..260e0369d98 100644 --- a/docs/0.49/native-components-android.html +++ b/docs/0.49/native-components-android.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
    Edit

    Native UI Components

    There are tons of native UI widgets out there ready to be used in the latest apps - some of them are part of the platform, others are available as third-party libraries, and still more might be in use in your very own portfolio. React Native has several of the most critical platform components already wrapped, like ScrollView and TextInput, but not all of them, and certainly not ones you might have written yourself for a previous app. Fortunately, it's quite easy to wrap up these existing components for seamless integration with your React Native application.

    -

    Like the native module guide, this too is a more advanced guide that assumes you are somewhat familiar with Android SDK programming. This guide will show you how to build a native UI component, walking you through the implementation of a subset of the existing ImageViewcomponent available in the core React Native library.

    +

    Like the native module guide, this too is a more advanced guide that assumes you are somewhat familiar with Android SDK programming. This guide will show you how to build a native UI component, walking you through the implementation of a subset of the existing ImageView component available in the core React Native library.

    ImageView example

    For this example we are going to walk through the implementation requirements to allow the use of ImageViews in JavaScript.

    Native views are created and manipulated by extending ViewManager or more commonly SimpleViewManager . A SimpleViewManager is convenient in this case because it applies common properties such as background color, opacity, and Flexbox layout.

    @@ -71,7 +71,7 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
 import {requireNativeComponent, ViewPropTypes} from 'react-native';
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.49/native-modules-android.html b/docs/0.49/native-modules-android.html
index a29be45f2a7..0062d99551b 100644
--- a/docs/0.49/native-modules-android.html
+++ b/docs/0.49/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.49/navigation.html b/docs/0.49/navigation.html
index a59ed8cd82c..bec326bca63 100644
--- a/docs/0.49/navigation.html
+++ b/docs/0.49/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.49/network.html b/docs/0.49/network.html
index ed4b7b0b019..c1d2879e25d 100644
--- a/docs/0.49/network.html
+++ b/docs/0.49/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.5/app-extensions.html b/docs/0.5/app-extensions.html index 11fabb7a228..f3f917ab1e6 100644 --- a/docs/0.5/app-extensions.html +++ b/docs/0.5/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.5/building-for-apple-tv.html b/docs/0.5/building-for-apple-tv.html index f9150392693..dfa625da358 100644 --- a/docs/0.5/building-for-apple-tv.html +++ b/docs/0.5/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.5/height-and-width.html b/docs/0.5/height-and-width.html index 35119f314be..27ee277d14c 100644 --- a/docs/0.5/height-and-width.html +++ b/docs/0.5/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.5/images.html b/docs/0.5/images.html index 990abc5acd7..5ff986a2b8b 100644 --- a/docs/0.5/images.html +++ b/docs/0.5/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.5/improvingux.html b/docs/0.5/improvingux.html index 0dd9d549953..923a9fb5d40 100644 --- a/docs/0.5/improvingux.html +++ b/docs/0.5/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.5/more-resources.html b/docs/0.5/more-resources.html index c7855ecb160..6b090ced70d 100644 --- a/docs/0.5/more-resources.html +++ b/docs/0.5/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.5/native-components-android.html b/docs/0.5/native-components-android.html index 09f4708d14e..9af4c2fdae8 100644 --- a/docs/0.5/native-components-android.html +++ b/docs/0.5/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.5/native-modules-android.html b/docs/0.5/native-modules-android.html
index 5c3ae537c11..16ccf89c946 100644
--- a/docs/0.5/native-modules-android.html
+++ b/docs/0.5/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.5/navigation.html b/docs/0.5/navigation.html
index 85e011077f6..172ee8a20e8 100644
--- a/docs/0.5/navigation.html
+++ b/docs/0.5/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.5/network.html b/docs/0.5/network.html
index e9eb67ff94d..2d122bf51dd 100644
--- a/docs/0.5/network.html
+++ b/docs/0.5/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.50/app-extensions.html b/docs/0.50/app-extensions.html index 3b1acd523a3..69729c49566 100644 --- a/docs/0.50/app-extensions.html +++ b/docs/0.50/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.50/building-for-apple-tv.html b/docs/0.50/building-for-apple-tv.html index e76c1fd071f..7a76271887d 100644 --- a/docs/0.50/building-for-apple-tv.html +++ b/docs/0.50/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.50/height-and-width.html b/docs/0.50/height-and-width.html index b3f88ceae89..10672eba2d8 100644 --- a/docs/0.50/height-and-width.html +++ b/docs/0.50/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.50/images.html b/docs/0.50/images.html index e722228a1a7..75a9de3306c 100644 --- a/docs/0.50/images.html +++ b/docs/0.50/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.50/improvingux.html b/docs/0.50/improvingux.html index fc11603f2b4..c7360474e80 100644 --- a/docs/0.50/improvingux.html +++ b/docs/0.50/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.50/more-resources.html b/docs/0.50/more-resources.html index 0faa9a35099..f730cb4ad2c 100644 --- a/docs/0.50/more-resources.html +++ b/docs/0.50/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.50/native-components-android.html b/docs/0.50/native-components-android.html index 05173506894..235d4a80d97 100644 --- a/docs/0.50/native-components-android.html +++ b/docs/0.50/native-components-android.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
    Edit

    Native UI Components

    There are tons of native UI widgets out there ready to be used in the latest apps - some of them are part of the platform, others are available as third-party libraries, and still more might be in use in your very own portfolio. React Native has several of the most critical platform components already wrapped, like ScrollView and TextInput, but not all of them, and certainly not ones you might have written yourself for a previous app. Fortunately, it's quite easy to wrap up these existing components for seamless integration with your React Native application.

    -

    Like the native module guide, this too is a more advanced guide that assumes you are somewhat familiar with Android SDK programming. This guide will show you how to build a native UI component, walking you through the implementation of a subset of the existing ImageViewcomponent available in the core React Native library.

    +

    Like the native module guide, this too is a more advanced guide that assumes you are somewhat familiar with Android SDK programming. This guide will show you how to build a native UI component, walking you through the implementation of a subset of the existing ImageView component available in the core React Native library.

    ImageView example

    For this example we are going to walk through the implementation requirements to allow the use of ImageViews in JavaScript.

    Native views are created and manipulated by extending ViewManager or more commonly SimpleViewManager . A SimpleViewManager is convenient in this case because it applies common properties such as background color, opacity, and Flexbox layout.

    @@ -71,7 +71,7 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
 import {requireNativeComponent, ViewPropTypes} from 'react-native';
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.50/native-modules-android.html b/docs/0.50/native-modules-android.html
index 4d39abcd38b..01de33e1e39 100644
--- a/docs/0.50/native-modules-android.html
+++ b/docs/0.50/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.50/navigation.html b/docs/0.50/navigation.html
index 2623025abbe..04a93ecfdd5 100644
--- a/docs/0.50/navigation.html
+++ b/docs/0.50/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.50/network.html b/docs/0.50/network.html
index 7825be49b5a..ad444c45007 100644
--- a/docs/0.50/network.html
+++ b/docs/0.50/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.51/app-extensions.html b/docs/0.51/app-extensions.html index faa5986c00e..5a91c1e8cf4 100644 --- a/docs/0.51/app-extensions.html +++ b/docs/0.51/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.51/building-for-apple-tv.html b/docs/0.51/building-for-apple-tv.html index 2e5287e1255..8a0cbdb68d2 100644 --- a/docs/0.51/building-for-apple-tv.html +++ b/docs/0.51/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.51/height-and-width.html b/docs/0.51/height-and-width.html index c28e98121c9..c7ee03185e2 100644 --- a/docs/0.51/height-and-width.html +++ b/docs/0.51/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.51/images.html b/docs/0.51/images.html index 001914f4a13..532e714dee3 100644 --- a/docs/0.51/images.html +++ b/docs/0.51/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.51/improvingux.html b/docs/0.51/improvingux.html index 94adf0760f0..e30085263eb 100644 --- a/docs/0.51/improvingux.html +++ b/docs/0.51/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.51/more-resources.html b/docs/0.51/more-resources.html index 1c16be10d61..648a249382b 100644 --- a/docs/0.51/more-resources.html +++ b/docs/0.51/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.51/native-components-android.html b/docs/0.51/native-components-android.html index b176403ffe5..c97530baf57 100644 --- a/docs/0.51/native-components-android.html +++ b/docs/0.51/native-components-android.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
    Edit

    Native UI Components

    There are tons of native UI widgets out there ready to be used in the latest apps - some of them are part of the platform, others are available as third-party libraries, and still more might be in use in your very own portfolio. React Native has several of the most critical platform components already wrapped, like ScrollView and TextInput, but not all of them, and certainly not ones you might have written yourself for a previous app. Fortunately, it's quite easy to wrap up these existing components for seamless integration with your React Native application.

    -

    Like the native module guide, this too is a more advanced guide that assumes you are somewhat familiar with Android SDK programming. This guide will show you how to build a native UI component, walking you through the implementation of a subset of the existing ImageViewcomponent available in the core React Native library.

    +

    Like the native module guide, this too is a more advanced guide that assumes you are somewhat familiar with Android SDK programming. This guide will show you how to build a native UI component, walking you through the implementation of a subset of the existing ImageView component available in the core React Native library.

    ImageView example

    For this example we are going to walk through the implementation requirements to allow the use of ImageViews in JavaScript.

    Native views are created and manipulated by extending ViewManager or more commonly SimpleViewManager . A SimpleViewManager is convenient in this case because it applies common properties such as background color, opacity, and Flexbox layout.

    @@ -71,7 +71,7 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
 import {requireNativeComponent, ViewPropTypes} from 'react-native';
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.51/native-modules-android.html b/docs/0.51/native-modules-android.html
index 98005e54bea..15f35165750 100644
--- a/docs/0.51/native-modules-android.html
+++ b/docs/0.51/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.51/navigation.html b/docs/0.51/navigation.html
index c21c85378b0..902f9ce22cd 100644
--- a/docs/0.51/navigation.html
+++ b/docs/0.51/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.51/network.html b/docs/0.51/network.html
index a1f344a895f..f5d42989e02 100644
--- a/docs/0.51/network.html
+++ b/docs/0.51/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.52/building-for-apple-tv.html b/docs/0.52/building-for-apple-tv.html index 2c4a0b54f4e..bb283845578 100644 --- a/docs/0.52/building-for-apple-tv.html +++ b/docs/0.52/building-for-apple-tv.html @@ -1,10 +1,10 @@ -Building For TV Devices · React Native

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.6/improvingux.html b/docs/0.6/improvingux.html index 9cb21c4c96c..eab8ba16fae 100644 --- a/docs/0.6/improvingux.html +++ b/docs/0.6/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.6/more-resources.html b/docs/0.6/more-resources.html index b115fa4db5d..39eac3cff9f 100644 --- a/docs/0.6/more-resources.html +++ b/docs/0.6/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.6/native-components-android.html b/docs/0.6/native-components-android.html index fad41765eb8..f3e18eb93a8 100644 --- a/docs/0.6/native-components-android.html +++ b/docs/0.6/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.6/native-modules-android.html b/docs/0.6/native-modules-android.html
index ae64fbd1203..c3d9f58b95d 100644
--- a/docs/0.6/native-modules-android.html
+++ b/docs/0.6/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.6/navigation.html b/docs/0.6/navigation.html
index deb00262a54..6ed3a2901a6 100644
--- a/docs/0.6/navigation.html
+++ b/docs/0.6/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.6/network.html b/docs/0.6/network.html
index 91e0d003130..1cce959cb99 100644
--- a/docs/0.6/network.html
+++ b/docs/0.6/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.7/app-extensions.html b/docs/0.7/app-extensions.html index 231c642faa1..7ae612037a7 100644 --- a/docs/0.7/app-extensions.html +++ b/docs/0.7/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.7/building-for-apple-tv.html b/docs/0.7/building-for-apple-tv.html index 2bcb7e0e522..e02ea56f335 100644 --- a/docs/0.7/building-for-apple-tv.html +++ b/docs/0.7/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.7/height-and-width.html b/docs/0.7/height-and-width.html index c31d1d788c6..8370edf43a8 100644 --- a/docs/0.7/height-and-width.html +++ b/docs/0.7/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.7/images.html b/docs/0.7/images.html index bc5bdc9e666..d0f61438816 100644 --- a/docs/0.7/images.html +++ b/docs/0.7/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.7/improvingux.html b/docs/0.7/improvingux.html index 62d1a439692..71825052883 100644 --- a/docs/0.7/improvingux.html +++ b/docs/0.7/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.7/more-resources.html b/docs/0.7/more-resources.html index 14fe4354845..52dd324012c 100644 --- a/docs/0.7/more-resources.html +++ b/docs/0.7/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.7/native-components-android.html b/docs/0.7/native-components-android.html index 29b4424b826..31142e0c945 100644 --- a/docs/0.7/native-components-android.html +++ b/docs/0.7/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.7/native-modules-android.html b/docs/0.7/native-modules-android.html
index 2a38b82e68f..10e6067f2e6 100644
--- a/docs/0.7/native-modules-android.html
+++ b/docs/0.7/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.7/navigation.html b/docs/0.7/navigation.html
index 55f492fc77c..dfe80272d50 100644
--- a/docs/0.7/navigation.html
+++ b/docs/0.7/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.7/network.html b/docs/0.7/network.html
index 7952d2a194b..b51a2aa92a9 100644
--- a/docs/0.7/network.html
+++ b/docs/0.7/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.8/app-extensions.html b/docs/0.8/app-extensions.html index aab0114fcf4..5f72de0b1c1 100644 --- a/docs/0.8/app-extensions.html +++ b/docs/0.8/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.8/building-for-apple-tv.html b/docs/0.8/building-for-apple-tv.html index 3d7155a6148..5d992ccecfc 100644 --- a/docs/0.8/building-for-apple-tv.html +++ b/docs/0.8/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.8/height-and-width.html b/docs/0.8/height-and-width.html index 17cd4d07bd8..5abaeb2f9f3 100644 --- a/docs/0.8/height-and-width.html +++ b/docs/0.8/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.8/images.html b/docs/0.8/images.html index 92ef4bd6402..2630ebe4461 100644 --- a/docs/0.8/images.html +++ b/docs/0.8/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.8/improvingux.html b/docs/0.8/improvingux.html index aa8a960d342..a104fd09111 100644 --- a/docs/0.8/improvingux.html +++ b/docs/0.8/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.8/more-resources.html b/docs/0.8/more-resources.html index 2419196cb20..5c384f74e5d 100644 --- a/docs/0.8/more-resources.html +++ b/docs/0.8/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.8/native-components-android.html b/docs/0.8/native-components-android.html index 37449ac9313..5a3a8e4c98c 100644 --- a/docs/0.8/native-components-android.html +++ b/docs/0.8/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.8/native-modules-android.html b/docs/0.8/native-modules-android.html
index e90d4c5bf1f..70bff14512b 100644
--- a/docs/0.8/native-modules-android.html
+++ b/docs/0.8/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.8/navigation.html b/docs/0.8/navigation.html
index 61767385bca..194967bbbe5 100644
--- a/docs/0.8/navigation.html
+++ b/docs/0.8/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.8/network.html b/docs/0.8/network.html
index 10f41fd0459..7460e72ecc6 100644
--- a/docs/0.8/network.html
+++ b/docs/0.8/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

Animations

Animations are very important to create a great user experience. Stationary objects must overcome inertia as they start moving. Objects in motion have momentum and rarely come to a stop immediately. Animations allow you to convey physically believable motion in your interface.

-

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

+

React Native provides two complementary animation systems: Animated for granular and interactive control of specific values, and LayoutAnimation for animated global layout transactions.

Animated API

The Animated API is designed to make it very easy to concisely express a wide variety of interesting animation and interaction patterns in a very performant way. Animated focuses on declarative relationships between inputs and outputs, with configurable transforms in between, and simple start/stop methods to control time-based animation execution.

Animated exports four animatable component types: View, Text, Image, and ScrollView, but you can also create your own using Animated.createAnimatedComponent().

diff --git a/docs/0.9/app-extensions.html b/docs/0.9/app-extensions.html index bb51706831d..d2030d818f4 100644 --- a/docs/0.9/app-extensions.html +++ b/docs/0.9/app-extensions.html @@ -10,7 +10,7 @@

We highly recommend that you watch Conrad Kramer's talk on Memory Use in Extensions to learn more about this topic.

Today widget

The memory limit of a Today widget is 16 MB. As it happens, Today widget implementations using React Native may work unreliably because the memory usage tends to be too high. You can tell if your Today widget is exceeding the memory limit if it yields the message 'Unable to Load':

-

+

Always make sure to test your app extensions in a real device, but be aware that this may not be sufficient, especially when dealing with Today widgets. Debug-configured builds are more likely to exceed the memory limits, while release-configured builds don't fail right away. We highly recommend that you use Xcode's Instruments to analyze your real world memory usage, as it's very likely that your release-configured build is very close to the 16 MB limit. In situations like these, it is easy to go over the 16 MB limit by performing common operations, such as fetching data from an API.

To experiment with the limits of React Native Today widget implementations, try extending the example project in react-native-today-widget.

Other app extensions

diff --git a/docs/0.9/building-for-apple-tv.html b/docs/0.9/building-for-apple-tv.html index a767be5d4ec..1cb2914db60 100644 --- a/docs/0.9/building-for-apple-tv.html +++ b/docs/0.9/building-for-apple-tv.html @@ -1,10 +1,82 @@ -Building For Apple TV · React Native
Edit

Headless JS

Headless JS is a way to run tasks in JavaScript while your app is in the background. It can be used, for example, to sync fresh data, handle push notifications, or play music.

The JS API

A task is a simple async function that you register on AppRegistry, similar to registering React applications:

-
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
+
AppRegistry.registerHeadlessTask('SomeTaskName', () => require('SomeTaskName'));
 

Then, in SomeTaskName.js:

-
module.exports = async (taskData) => {
+
module.exports = async (taskData) => {
   // do stuff
 };
 
diff --git a/docs/0.9/height-and-width.html b/docs/0.9/height-and-width.html index 39db5bc4ef1..f645438ce57 100644 --- a/docs/0.9/height-and-width.html +++ b/docs/0.9/height-and-width.html @@ -5,7 +5,7 @@ nav.classList.toggle('docsSliderActive'); };
Edit

Height and Width

A component's height and width determine its size on the screen.

-

Fixed Dimensions

+

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Native are unitless, and represent density-independent pixels.

import React, { Component } from 'react';
 import { AppRegistry, View } from 'react-native';
@@ -27,7 +27,7 @@ AppRegistry.registerComponent('AwesomeProject', () => FixedDimensionsBasics);
 

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

-

Flex Dimensions

+

Flex Dimensions

Use flex in a component's style to have the component expand and shrink dynamically based on available space. Normally you will use flex: 1, which tells a component to fill all available space, shared evenly amongst each other component with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

A component can only expand to fill available space if its parent has dimensions greater than 0. If a parent does not have either a fixed width and height or flex, the parent will have dimensions of 0 and the flex children will not be visible.

diff --git a/docs/0.9/images.html b/docs/0.9/images.html index 1939529a363..7954b37e0ea 100644 --- a/docs/0.9/images.html +++ b/docs/0.9/images.html @@ -47,8 +47,8 @@ var icon = this.props.active

Note that image sources required this way include size (width, height) info for the Image. If you need to scale the image dynamically (i.e. via flex), you may need to manually set { width: undefined, height: undefined } on the style attribute.

Static Non-Image Resources

-

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

-

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

+

The require syntax described above can be used to statically include audio, video or document files in your project as well. Most common file types are supported including .mp3, .wav, .mp4, .mov, .html and .pdf. See packager defaults for the full list.

+

You can add support for other types by creating a packager config file (see the packager config file for the full list of configuration options).

A caveat is that videos must use absolute positioning instead of flexGrow, since size info is not currently passed for non-image assets. This limitation doesn't occur for videos that are linked directly into Xcode or the Assets folder for Android.

Images From Hybrid App's Resources

If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

diff --git a/docs/0.9/improvingux.html b/docs/0.9/improvingux.html index d17de9af3d1..41626dd8a79 100644 --- a/docs/0.9/improvingux.html +++ b/docs/0.9/improvingux.html @@ -18,7 +18,7 @@

Configure text inputs

-

Entering text on touch phone is a challange - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

+

Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:

  • Focus the first field automatically
  • Use placeholder text as an example of expected data format
  • @@ -41,6 +41,8 @@

    Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.

    Try it on your phone

    +

    Screen orientation lock

    +

    Unless supporting both, it is considered good practice to lock the screen orientation to either portrait or landscape. On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation=”portrait”' to lock to portrait or 'android:screenOrientation=”landscape”' to lock to landscape.

    Learn more

    Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.

    Edit

    JavaScript Environment

    JavaScript Runtime

    When using React Native, you're going to be running your JavaScript code in two environments:

      -
    • On iOS simulators and devices, Android emulators and devices React Native uses JavaScriptCore which is the JavaScript engine that powers Safari. On iOS JSC doesn't use JIT due to the absence of writable executable memory in iOS apps.
    • -
    • When using Chrome debugging, it runs all the JavaScript code within Chrome itself and communicates with native code via WebSocket. So you are using V8.
    • +
    • In most cases, React Native will use JavaScriptCore, the JavaScript engine that powers Safari. Note that on iOS, JavaScriptCore does not use JIT due to the absence of writable executable memory in iOS apps.
    • +
    • When using Chrome debugging, all JavaScript code runs within Chrome itself, communicating with native code via WebSockets. Chrome uses V8 as its JavaScript engine.
    -

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JS engines in the future, so it's best to avoid relying on specifics of any runtime.

    +

    While both environments are very similar, you may end up hitting some inconsistencies. We're likely going to experiment with other JavaScript engines in the future, so it's best to avoid relying on specifics of any runtime.

    JavaScript Syntax Transformers

    Syntax transformers make writing code more enjoyable by allowing you to use new JavaScript syntax without having to wait for support on all interpreters.

    -

    As of version 0.5.0, React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    +

    React Native ships with the Babel JavaScript compiler. Check Babel documentation on its supported transformations for more details.

    Here's a full list of React Native's enabled transformations.

    ES5

    -

    ES7

    +

    ES8

    +

    Stage 3

    +

    Specific

      -
    • JSX: <View style={{color: 'red'}} />
    • +
    • JSX: <View style={{color: 'red'}} />
    • Flow: function foo(x: ?number): string {}

    Polyfills

    @@ -59,12 +62,16 @@

    ES6

    ES7

    +

    ES8

    +

    Specific

    diff --git a/docs/0.9/more-resources.html b/docs/0.9/more-resources.html index 41501eafda0..947dc50016f 100644 --- a/docs/0.9/more-resources.html +++ b/docs/0.9/more-resources.html @@ -8,16 +8,16 @@

    Popular Libraries

    If you're using React Native, you probably already know about React. So I feel a bit silly mentioning this. But if you haven't, check out React - it's the best way to build a modern website.

    One common question is how to handle the "state" of your React Native application. The most popular library for this is Redux. Don't be afraid of how often Redux uses the word "reducer" - it's a pretty simple library, and there's also a nice series of videos explaining it.

    -

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff. You can also find a curated list of React Native libraries at Native Directory, together with quality assessment, recommendations, a lot of pertinent GitHub information, and code examples.

    +

    If you're looking for a library that does a specific thing, check out Awesome React Native, a curated list of components that also has demos, articles, and other stuff.

    Examples

    Try out apps from the Showcase to see what React Native is capable of! There are also some example apps on GitHub. You can run the apps on a simulator or device, and you can see the source code for these apps, which is neat.

    -

    The folks who built the app for Facebook's F8 conference in 2016 also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    +

    The folks who built the app for Facebook's F8 conference also open-sourced the code and wrote up a detailed series of tutorials. This is useful if you want a more in-depth example that's more realistic than most sample apps out there.

    Extending React Native

      -
    • Looking for a component? JS.coach
    • Fellow developers write and publish React Native modules to npm and open source them on GitHub.
    • Making modules helps grow the React Native ecosystem and community. We recommend writing modules for your use cases and sharing them on npm.
    • Read the guides on Native Modules (iOS, Android) and Native UI Components (iOS, Android) if you are interested in extending native functionality.
    • +
    • Looking for a pre-built component? Check JS.coach.

    Development Tools

    Nuclide is the IDE that Facebook uses internally for JavaScript development. The killer feature of Nuclide is its debugging ability. It also has great inline Flow support. VS Code is another IDE that is popular with JavaScript developers.

    diff --git a/docs/0.9/native-components-android.html b/docs/0.9/native-components-android.html index 0125222bc74..c3b3a0df459 100644 --- a/docs/0.9/native-components-android.html +++ b/docs/0.9/native-components-android.html @@ -71,10 +71,10 @@

5. Implement the JavaScript module

The very final step is to create the JavaScript module that defines the interface layer between Java and JavaScript for the users of your new view. Much of the effort is handled by internal React code in Java and JavaScript and all that is left for you is to describe the propTypes.

-
// ImageView.js
+
// ImageView.js
 
 import PropTypes from 'prop-types';
-import {requireNativeComponent, View} from 'react-native';
+import {requireNativeComponent, ViewPropTypes} from 'react-native';
 
 var iface = {
   name: 'ImageView',
@@ -82,7 +82,7 @@
     src: PropTypes.string,
     borderRadius: PropTypes.number,
     resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch']),
-    ...View.propTypes, // include the default view properties
+    ...ViewPropTypes, // include the default view properties
   },
 };
 
@@ -119,7 +119,7 @@
 }
 

This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:

-
// MyCustomView.js
+
// MyCustomView.js
 
 class MyCustomView extends React.Component {
   constructor(props) {
diff --git a/docs/0.9/native-modules-android.html b/docs/0.9/native-modules-android.html
index 3364595dada..21292e2ae69 100644
--- a/docs/0.9/native-modules-android.html
+++ b/docs/0.9/native-modules-android.html
@@ -107,7 +107,7 @@ ReadableArray -><
 }
 

To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of NativeModules each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality.

-
/**
+
/**
  * This exposes the native ToastExample module as a JS module. This has a
  * function 'show' which takes the following parameters:
  *
@@ -119,14 +119,16 @@ ReadableArray -><
 module.exports = NativeModules.ToastExample;
 

Now, from your other JavaScript file you can call the method like this:

-
import ToastExample from './ToastExample';
+
import ToastExample from './ToastExample';
 
 ToastExample.show('Awesome', ToastExample.SHORT);
 

Beyond Toasts

Callbacks

Native modules also support a special kind of argument - a callback. In most cases it is used to provide the function call result to JavaScript.

-
public class UIManagerModule extends ReactContextBaseJavaModule {
+
import com.facebook.react.bridge.Callback;
+
+public class UIManagerModule extends ReactContextBaseJavaModule {
 
 ...
 
@@ -151,7 +153,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

This method would be accessed in JavaScript using:

-
UIManager.measureLayout(
+
UIManager.measureLayout(
   100,
   100,
   (msg) => {
@@ -197,7 +199,7 @@ ToastExample.show('Awesome', ToastExample.SHORT
 ...
 

The JavaScript counterpart of this method returns a Promise. This means you can use the await keyword within an async function to call it and wait for its result:

-
async function measureLayout() {
+
async function measureLayout() {
   try {
     var {relativeX, relativeY, width, height} = await UIManager.measureLayout(
       100,
@@ -230,7 +232,7 @@ WritableMap params = Arguments.createMap();
 sendEvent(reactContext, "keyboardWillShow", params);
 

JavaScript modules can then register to receive events by addListenerOn using the Subscribable mixin.

-
import { DeviceEventEmitter } from 'react-native';
+
import { DeviceEventEmitter } from 'react-native';
 ...
 
 var ScrollResponderMixin = {
@@ -250,7 +252,7 @@ var ScrollResponderMixin = {
   },
 

You can also directly use the DeviceEventEmitter module to listen for events.

-
...
+
...
 componentWillMount: function() {
   DeviceEventEmitter.addListener('keyboardWillShow', function(e: Event) {
     // handle event.
diff --git a/docs/0.9/navigation.html b/docs/0.9/navigation.html
index 033bbffc526..40de434c484 100644
--- a/docs/0.9/navigation.html
+++ b/docs/0.9/navigation.html
@@ -5,7 +5,7 @@
             nav.classList.toggle('docsSliderActive');
           };
         
Edit

Navigating Between Screens

Mobile apps are rarely made up of a single screen. Managing the presentation of, and transition between, multiple screens is typically handled by what is known as a navigator.

-

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

+

This guide covers the various navigation components available in React Native. If you are just getting started with navigation, you will probably want to use React Navigation. React Navigation provides an easy to use navigation solution, with the ability to present common stack navigation and tabbed navigation patterns on both iOS and Android. As this is a JavaScript implementation, it provides the greatest amount of configurability as well as flexibility when integrating with state management libraries such as redux.

If you're only targeting iOS, you may want to also check out NavigatorIOS as a way of providing a native look and feel with minimal configuration, as it provides a wrapper around the native UINavigationController class. This component will not work on Android, however.

If you'd like to achieve a native look and feel on both iOS and Android, or you're integrating React Native into an app that already manages navigation natively, the following libraries provide native navigation on both platforms: native-navigation, react-native-navigation.

React Navigation

@@ -43,10 +43,10 @@ const App = StackNavigator({

React Navigation routers make it easy to override navigation logic or integrate it into redux. Because routers can be nested inside each other, developers can override navigation logic for one area of the app without making widespread changes.

The views in React Navigation use native components and the Animated library to deliver 60fps animations that are run on the native thread. Plus, the animations and gestures can be easily customized.

-

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

+

For a complete intro to React Navigation, follow the React Navigation Getting Started Guide, or browse other docs such as the Intro to Navigators.

NavigatorIOS

NavigatorIOS looks and feels just like UINavigationController, because it is actually built on top of it.

-

+

<NavigatorIOS
   initialRoute={{
     component: MyScene,
diff --git a/docs/0.9/network.html b/docs/0.9/network.html
index 2969bd99e20..9fac2b272b7 100644
--- a/docs/0.9/network.html
+++ b/docs/0.9/network.html
@@ -9,10 +9,10 @@
 

React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.

Making requests

In order to fetch content from an arbitrary URL, just pass the URL to fetch:

-
fetch('https://mywebsite.com/mydata.json');
+
fetch('https://mywebsite.com/mydata.json');
 

Fetch also takes an optional second argument that allows you to customize the HTTP request. You may want to specify additional headers, or make a POST request:

-
fetch('https://mywebsite.com/endpoint/', {
+
fetch('https://mywebsite.com/endpoint/', {
   method: 'POST',
   headers: {
     Accept: 'application/json',
@@ -28,7 +28,7 @@
 

Handling the response

The above examples show how you can make a request. In many cases, you will want to do something with the response.

Networking is an inherently asynchronous operation. Fetch methods will return a Promise that makes it straightforward to write code that works in an asynchronous manner:

-
function getMoviesFromApiAsync() {
+
function getMoviesFromApiAsync() {
   return fetch('https://facebook.github.io/react-native/movies.json')
     .then((response) => response.json())
     .then((responseJson) => {
@@ -40,7 +40,7 @@
 }
 

You can also use the proposed ES2017 async/await syntax in a React Native app:

-
async function getMoviesFromApi() {
+
async function getMoviesFromApi() {
   try {
     let response = await fetch(
       'https://facebook.github.io/react-native/movies.json'
@@ -53,48 +53,52 @@
 }
 

Don't forget to catch any errors that may be thrown by fetch, otherwise they will be dropped silently.

-
-

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

+

In a real application, you probably won't be setting state with a timer. You might set state when you have new data arrive from the server, or from user input. You can also use a state container like Redux to control your data flow. In that case you would use Redux to modify your state rather than calling setState directly.

When setState is called, BlinkApp will re-render its Component. By calling setState within the Timer, the component will re-render every time the Timer ticks.

State works the same way as it does in React, so for more details on handling state, you can look at the React.Component API. At this point, you might be annoyed that most of our examples so far use boring default black text. To make things more beautiful, you will have to learn about Style.

Edit

AppState

AppState can tell you if the app is in the foreground or background, and notify you when the state changes.

-

AppState is frequently used to determine the intent and proper behavior when handling push notifications.

+

AppState is frequently used to determine the intent and proper behavior when handling push notifications.

App States

  • active - The app is running in the foreground
  • diff --git a/docs/building-for-apple-tv.html b/docs/building-for-apple-tv.html index 0930a3dc018..bb2e17a6e50 100644 --- a/docs/building-for-apple-tv.html +++ b/docs/building-for-apple-tv.html @@ -1,10 +1,10 @@ -Building For TV Devices · React Native