React Native 浅入门

作为一个前端,怎么可能不去尝一下 React Native,这位号称“learn once, write anywhere”的家伙。

learn once, write anywhere

浅尝之后,觉得还是有必要简单的进行一下总结,主要就是从前端的角度罢,看是否可转换或者从“老前端”的角度来学习和使用 React Native。

权当一个笔记,再写写或许更明白点

有些需要注意的地方,也顺手写在这里:

使用es6语法后,getInitialState、getDefaultProps和propTypes使用模式发生了变化:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {count: props.initialCount};
}
tick() {
this.setState({count: this.state.count + 1});
}
render() {
return (
<div onClick={this.tick.bind(this)}>
Clicks: {this.state.count}
);
}
}
Counter.propTypes = { initialCount: React.PropTypes.number };
Counter.defaultProps = { initialCount: 0 };

React Native 的 Component 如何显示其背后的内容,即变得透明

1
2
3
{
backgroundColor: 'transparent'
}