参考:
https://facebook.github.io/react-native/docs/getting-started.html
https://facebook.github.io/react-native/docs/tutorial.html#content
最新版本的React库源码:react-native v0.5
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var styles = StyleSheet.create({
container: {//定义 View 视图的样式
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {//定义 Text 的样式
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {//定义 Text 的样式
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
作用:定义了一段应用在 “Hello World” 文本上的样式。
var HelloReact = 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 HelloReact = React.createClass();
render: function() {//渲染的方法
return ();
}
<View style={styles.container}> //视图 View
</View>
<Text style={styles.welcome}> //文本 Text
Welcome to React Native!
</Text>
AppRegistry.registerComponent('HelloReact', () => HelloReact);