写在前面的话
学前准备
配置好环境后,运行第一个项目hello world
Hello World!
几乎所有语言开始都是hello world,RN也不例外。
打开项目目录
现在就来修改下index.android.js
来实现我们的helloworld。
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
class HelloWorld extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
</View>
);
}
}
const 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('HelloWorld', () => HelloWorld);
这里我们只需修改render()
方法就可以去实现helloword(render就是渲染的意思)
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
HelloWorld!
</Text>
</View>
);
}
当然这只是一个最简单的例子(简直LOW爆了(╯‵□′)╯︵┻━┻),对RN里的组件,属性,状态都没有涉及,这些将会出现在下篇React-Native学习笔记中。
写在后面的话
一些学前准备的汇总:
- 环境搭建:
- 江清清的技术专栏(React Native专题):
- React 入门实例教程:
- 阮一峰的《ECMAScript 6入门》: (es6了解即可)
也是刚开始学习RN,小半个月吧,实现了一两个demo,之后会慢慢的将自己的学习过程写下来,一是帮自己回顾,二是帮助一些想学习RN的朋友。
学习路漫漫,吾将上下而求索。