replace require with es6 import in docs
Reviewed By: svcscm Differential Revision: D2936839 fb-gh-sync-id: 7a921709a37de5e9aadf324d5438d51851326348 shipit-source-id: 7a921709a37de5e9aadf324d5438d51851326348
This commit is contained in:
parent
2260d900d4
commit
3ae99d0fea
|
@ -344,7 +344,7 @@ your project, you will need to install it with `npm i react-tween-state
|
||||||
--save` from your project directory.
|
--save` from your project directory.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var tweenState = require('react-tween-state');
|
import tweenState from 'react-tween-state';
|
||||||
|
|
||||||
var App = React.createClass({
|
var App = React.createClass({
|
||||||
mixins: [tweenState.Mixin],
|
mixins: [tweenState.Mixin],
|
||||||
|
@ -402,7 +402,7 @@ the middle of a press, it will animate back from the current state to
|
||||||
the original value.
|
the original value.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var rebound = require('rebound');
|
import rebound from 'rebound';
|
||||||
|
|
||||||
var App = React.createClass({
|
var App = React.createClass({
|
||||||
// First we initialize the spring and add a listener, which calls
|
// First we initialize the spring and add a listener, which calls
|
||||||
|
@ -532,8 +532,7 @@ make them customizable, React Native exposes a
|
||||||
[NavigatorSceneConfigs](https://github.com/facebook/react-native/blob/master/Libraries/CustomComponents/Navigator/NavigatorSceneConfigs.js) API.
|
[NavigatorSceneConfigs](https://github.com/facebook/react-native/blob/master/Libraries/CustomComponents/Navigator/NavigatorSceneConfigs.js) API.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var React = require('react-native');
|
import { Dimensions } from 'react-native';
|
||||||
var { Dimensions } = React;
|
|
||||||
var SCREEN_WIDTH = Dimensions.get('window').width;
|
var SCREEN_WIDTH = Dimensions.get('window').width;
|
||||||
var BaseConfig = Navigator.SceneConfigs.FloatFromRight;
|
var BaseConfig = Navigator.SceneConfigs.FloatFromRight;
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,10 @@ RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
|
||||||
```
|
```
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var React = require('react-native');
|
import React, {
|
||||||
var {
|
|
||||||
View,
|
View,
|
||||||
Image
|
Image
|
||||||
} = React;
|
} from 'react-native';
|
||||||
|
|
||||||
class ImageBrowserApp extends React.Component {
|
class ImageBrowserApp extends React.Component {
|
||||||
renderImage: function(imgURI) {
|
renderImage: function(imgURI) {
|
||||||
|
|
|
@ -128,11 +128,10 @@ Copy & paste the following code to `index.android.js` in your root folder — it
|
||||||
```js
|
```js
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var React = require('react-native');
|
import React, {
|
||||||
var {
|
|
||||||
Text,
|
Text,
|
||||||
View
|
View
|
||||||
} = React;
|
} from 'react-native';
|
||||||
|
|
||||||
class MyAwesomeApp extends React.Component {
|
class MyAwesomeApp extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -66,11 +66,10 @@ Copy & paste following starter code for `index.ios.js` – it’s a barebones Re
|
||||||
```
|
```
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var React = require('react-native');
|
import React, {
|
||||||
var {
|
|
||||||
Text,
|
Text,
|
||||||
View
|
View
|
||||||
} = React;
|
} from 'react-native';
|
||||||
|
|
||||||
var styles = React.StyleSheet.create({
|
var styles = React.StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
|
|
@ -105,7 +105,7 @@ The very final step is to create the JavaScript module that defines the interfac
|
||||||
```js
|
```js
|
||||||
// ImageView.js
|
// ImageView.js
|
||||||
|
|
||||||
var { requireNativeComponent, PropTypes } = require('react-native');
|
import { requireNativeComponent, PropTypes } from 'react-native';
|
||||||
|
|
||||||
var iface = {
|
var iface = {
|
||||||
name: 'ImageView',
|
name: 'ImageView',
|
||||||
|
|
|
@ -49,7 +49,7 @@ Then you just need a little bit of JavaScript to make this a usable React compon
|
||||||
```javascript
|
```javascript
|
||||||
// MapView.js
|
// MapView.js
|
||||||
|
|
||||||
var { requireNativeComponent } = require('react-native');
|
import { requireNativeComponent } from 'react-native';
|
||||||
|
|
||||||
// requireNativeComponent automatically resolves this to "RCTMapManager"
|
// requireNativeComponent automatically resolves this to "RCTMapManager"
|
||||||
module.exports = requireNativeComponent('RCTMap', null);
|
module.exports = requireNativeComponent('RCTMap', null);
|
||||||
|
@ -79,8 +79,7 @@ This isn't very well documented though - in order to know what properties are av
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// MapView.js
|
// MapView.js
|
||||||
var React = require('react-native');
|
import React, { requireNativeComponent } from 'react-native';
|
||||||
var { requireNativeComponent } = React;
|
|
||||||
|
|
||||||
class MapView extends React.Component {
|
class MapView extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
|
@ -302,7 +301,8 @@ Since all our native react views are subclasses of `UIView`, most style attribut
|
||||||
```javascript
|
```javascript
|
||||||
// DatePickerIOS.ios.js
|
// DatePickerIOS.ios.js
|
||||||
|
|
||||||
var RCTDatePickerIOSConsts = require('react-native').UIManager.RCTDatePicker.Constants;
|
import { UIManager } from 'react-native';
|
||||||
|
var RCTDatePickerIOSConsts = UIManager.RCTDatePicker.Constants;
|
||||||
...
|
...
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -130,14 +130,14 @@ To make it simpler to access your new functionality from JavaScript, it is commo
|
||||||
* 2. int duration: The duration of the toast. May be ToastAndroid.SHORT or
|
* 2. int duration: The duration of the toast. May be ToastAndroid.SHORT or
|
||||||
* ToastAndroid.LONG
|
* ToastAndroid.LONG
|
||||||
*/
|
*/
|
||||||
var { NativeModules } = require('react-native');
|
import { NativeModules } from 'react-native';
|
||||||
module.exports = NativeModules.ToastAndroid;
|
module.exports = NativeModules.ToastAndroid;
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, from your other JavaScript file you can call the method like this:
|
Now, from your other JavaScript file you can call the method like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var ToastAndroid = require('./ToastAndroid');
|
import ToastAndroid from './ToastAndroid';
|
||||||
|
|
||||||
ToastAndroid.show('Awesome', ToastAndroid.SHORT);
|
ToastAndroid.show('Awesome', ToastAndroid.SHORT);
|
||||||
```
|
```
|
||||||
|
@ -275,7 +275,7 @@ sendEvent(reactContext, "keyboardWillShow", params);
|
||||||
JavaScript modules can then register to receive events by `addListenerOn` using the `Subscribable` mixin
|
JavaScript modules can then register to receive events by `addListenerOn` using the `Subscribable` mixin
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var { DeviceEventEmitter } = require('react-native');
|
import { DeviceEventEmitter } from 'react-native';
|
||||||
...
|
...
|
||||||
|
|
||||||
var ScrollResponderMixin = {
|
var ScrollResponderMixin = {
|
||||||
|
|
|
@ -50,7 +50,8 @@ RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location)
|
||||||
Now, from your JavaScript file you can call the method like this:
|
Now, from your JavaScript file you can call the method like this:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var CalendarManager = require('react-native').NativeModules.CalendarManager;
|
import { NativeModules } from 'react-native';
|
||||||
|
var CalendarManager = NativeModules.CalendarManager;
|
||||||
CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey');
|
CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -334,7 +335,7 @@ The native module can signal events to JavaScript without being invoked directly
|
||||||
JavaScript code can subscribe to these events:
|
JavaScript code can subscribe to these events:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var { NativeAppEventEmitter } = require('react-native');
|
import { NativeAppEventEmitter } from 'react-native';
|
||||||
|
|
||||||
var subscription = NativeAppEventEmitter.addListener(
|
var subscription = NativeAppEventEmitter.addListener(
|
||||||
'EventReminder',
|
'EventReminder',
|
||||||
|
|
|
@ -37,7 +37,7 @@ BigButton.android.js
|
||||||
With this setup, you can just require the files from a different component without paying attention to the platform in which the app will run.
|
With this setup, you can just require the files from a different component without paying attention to the platform in which the app will run.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var BigButton = require('./components/BigButton');
|
import BigButton from './components/BigButton';
|
||||||
```
|
```
|
||||||
|
|
||||||
React Native will import the correct component for the running platform.
|
React Native will import the correct component for the running platform.
|
||||||
|
@ -46,7 +46,7 @@ React Native will import the correct component for the running platform.
|
||||||
A module is provided by React Native to detect what is the platform in which the app is running. This piece of functionality can be useful when only small parts of a component are platform specific.
|
A module is provided by React Native to detect what is the platform in which the app is running. This piece of functionality can be useful when only small parts of a component are platform specific.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var {Platform} = React;
|
var { Platform } = React;
|
||||||
|
|
||||||
var styles = StyleSheet.create({
|
var styles = StyleSheet.create({
|
||||||
height: (Platform.OS === 'ios') ? 200 : 100,
|
height: (Platform.OS === 'ios') ? 200 : 100,
|
||||||
|
|
|
@ -61,7 +61,7 @@ We found out that the primary cause of fatals in apps created with React Native
|
||||||
This library does not ship with React Native - in order to use it on your project, you will need to install it with `npm i react-timer-mixin --save` from your project directory.
|
This library does not ship with React Native - in order to use it on your project, you will need to install it with `npm i react-timer-mixin --save` from your project directory.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var TimerMixin = require('react-timer-mixin');
|
import TimerMixin from 'react-timer-mixin';
|
||||||
|
|
||||||
var Component = React.createClass({
|
var Component = React.createClass({
|
||||||
mixins: [TimerMixin],
|
mixins: [TimerMixin],
|
||||||
|
|
|
@ -96,12 +96,12 @@ You need to run `adb reverse tcp:8081 tcp:8081` to forward requests from the dev
|
||||||
|
|
||||||
## Module that uses `WebSocket` (such as Firebase) throws an exception
|
## Module that uses `WebSocket` (such as Firebase) throws an exception
|
||||||
|
|
||||||
React Native implements a polyfill for WebSockets. These polyfills are initialized as part of the react-native module that you include in your application through `require('react-native')`. If you load another module that requires WebSockets, be sure to load/require it after react-native.
|
React Native implements a polyfill for WebSockets. These polyfills are initialized as part of the react-native module that you include in your application through `import React from 'react-native'`. If you load another module that requires WebSockets, be sure to load/require it after react-native.
|
||||||
|
|
||||||
So:
|
So:
|
||||||
```
|
```
|
||||||
var React = require('react-native');
|
import React from 'react-native';
|
||||||
var Firebase = require('firebase');
|
import Firebase from 'firebase';
|
||||||
```
|
```
|
||||||
|
|
||||||
Requiring firebase *before* react-native will result in a 'No transports available' redbox.
|
Requiring firebase *before* react-native will result in a 'No transports available' redbox.
|
||||||
|
|
Loading…
Reference in New Issue