## 源碼
~~~
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var helloworld = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('hellowrold',() => helloworld);
~~~
## 問題
`AppRegistry.registerComponent('hellowrold',() => helloworld);`中`registerComponent`方法的第一個參數`hellowrold`參數一定要跟項目名一樣,否則就會報錯。

## 總結
新建項目分5步:
## 引入react-native
~~~
var React = require('react-native');
~~~
## 定義組件
~~~
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
~~~
## 定義界面控件
~~~
var helloworld = React.createClass({});
~~~
## 定義控件樣式
~~~
var styles = StyleSheet.create({});
~~~
## 為項目注冊界面
~~~
AppRegistry.registerComponent('項目名',() =>界面);
~~~
- 前言
- react-native試玩(1)
- react-native試玩(2)
- (3)-窺探開發者選項
- (4)-新建項目
- (5)-小菊花控件
- (6)-日期選擇控件
- (7)-圖片控件
- (8)-列表視圖
- (9)-地圖視圖
- (10)-導航欄
- (11)-模態
- (12)-iOS中導航欄
- (13)-選擇控件
- (14)-iOS中進度欄
- (15)-滾動視圖
- (16)-iOS分段控制控件
- (17)-iOS中的滑動條
- (18)-開關控件
- (19)-分頁欄
- (20)-分頁欄中的元素
- (21)-文本控件
- (22)-文本輸入框
- (23)-觸摸高亮
- (24)-觸摸模糊
- (25)-觸摸無反饋
- (26)-網頁視圖
- (27)-上拉菜單API
- (28)-彈出框API
- (29)-React Native Playground
- (30)-應用狀態API
- (31)-訪問相冊API
- (32)-推送通知API
- (33)-狀態欄API
- (34)-配置Android開發環境
- (35)-react-native-icons插件