Codemod import React from 'react-native'
Reviewed By: spicyj Differential Revision: D3223162 fb-gh-sync-id: 0b1af846afe17cdf8b2c2ca7f31f1197cde752c0 fbshipit-source-id: 0b1af846afe17cdf8b2c2ca7f31f1197cde752c0
This commit is contained in:
parent
8e43b24a36
commit
6f43d1f2cb
|
@ -39,7 +39,9 @@ RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
|
|||
```
|
||||
'use strict';
|
||||
|
||||
import React, {
|
||||
import React from 'react';
|
||||
import {
|
||||
AppRegistry,
|
||||
View,
|
||||
Image
|
||||
} from 'react-native';
|
||||
|
@ -59,7 +61,7 @@ class ImageBrowserApp extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
React.AppRegistry.registerComponent('ImageBrowserApp', () => ImageBrowserApp);
|
||||
AppRegistry.registerComponent('ImageBrowserApp', () => ImageBrowserApp);
|
||||
```
|
||||
|
||||
`RCTRootView` also provides a read-write property `appProperties`. After `appProperties` is set, the React Native app is re-rendered with new properties. The update is only performed when the new updated properties differ from the previous ones.
|
||||
|
|
|
@ -128,7 +128,10 @@ Copy & paste the following code to `index.android.js` in your root folder — it
|
|||
```js
|
||||
'use strict';
|
||||
|
||||
import React, {
|
||||
import React from 'react';
|
||||
import {
|
||||
AppRegistry,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View
|
||||
} from 'react-native';
|
||||
|
@ -142,7 +145,7 @@ class MyAwesomeApp extends React.Component {
|
|||
)
|
||||
}
|
||||
}
|
||||
var styles = React.StyleSheet.create({
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
|
@ -154,7 +157,7 @@ var styles = React.StyleSheet.create({
|
|||
},
|
||||
});
|
||||
|
||||
React.AppRegistry.registerComponent('MyAwesomeApp', () => MyAwesomeApp);
|
||||
AppRegistry.registerComponent('MyAwesomeApp', () => MyAwesomeApp);
|
||||
```
|
||||
|
||||
## Run your app
|
||||
|
|
|
@ -66,12 +66,15 @@ Copy & paste following starter code for `index.ios.js` – it’s a barebones Re
|
|||
```
|
||||
'use strict';
|
||||
|
||||
import React, {
|
||||
import React from 'react';
|
||||
import {
|
||||
AppRegistry,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View
|
||||
} from 'react-native';
|
||||
|
||||
var styles = React.StyleSheet.create({
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: 'red'
|
||||
|
@ -88,7 +91,7 @@ class SimpleApp extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
|
||||
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);
|
||||
```
|
||||
|
||||
`SimpleApp` will be your **module name**, which will be used later on.
|
||||
|
|
|
@ -37,7 +37,7 @@ ES6
|
|||
* [Constants](https://babeljs.io/docs/learn-es2015/#let-const): `const answer = 42;`
|
||||
* [Destructuring](http://babeljs.io/docs/learn-es2015/#destructuring): `var {isActive, style} = this.props;`
|
||||
* [for...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of): `for (var num of [1, 2, 3]) {}`
|
||||
* [Modules](http://babeljs.io/docs/learn-es2015/#modules): `import React, { Component } from 'react-native';`
|
||||
* [Modules](http://babeljs.io/docs/learn-es2015/#modules): `import { Component } from 'react-native';`
|
||||
* [Computed Properties](http://babeljs.io/docs/learn-es2015/#enhanced-object-literals): `var key = 'abc'; var obj = {[key]: 10};`
|
||||
* Object Consise Method: `var obj = { method() { return 10; } };`
|
||||
* [Object Short Notation](http://babeljs.io/docs/learn-es2015/#enhanced-object-literals): `var name = 'vjeux'; var obj = { name };`
|
||||
|
|
|
@ -105,7 +105,8 @@ The very final step is to create the JavaScript module that defines the interfac
|
|||
```js
|
||||
// ImageView.js
|
||||
|
||||
import { requireNativeComponent, PropTypes } from 'react-native';
|
||||
import { PropTypes } from 'react';
|
||||
import { requireNativeComponent } from 'react-native';
|
||||
|
||||
var iface = {
|
||||
name: 'ImageView',
|
||||
|
|
|
@ -80,7 +80,8 @@ This isn't very well documented though - in order to know what properties are av
|
|||
|
||||
```javascript
|
||||
// MapView.js
|
||||
import React, { requireNativeComponent } from 'react-native';
|
||||
import React from 'react';
|
||||
import { requireNativeComponent } from 'react-native';
|
||||
|
||||
class MapView extends React.Component {
|
||||
render() {
|
||||
|
|
Loading…
Reference in New Issue