记录了学习React Native过程中一开始的上手项目, 对初学者提供对比参考。 Github Source
react native components:
third library:
rnpm
to link with third-party libraries Sometimes the third-party libraries not fully integrated into the project even doing rnpm link
. In such case, delete the node_modules folder and install again, rm -rf node_modules && npm install
, then do rnpm link
to help link with IOS libraries instead of doing it mannually.
Apply flex: 1, justifyContent: 'center', alignItems: 'center'
styling on image’s parent element, then for that image’s styling, only specify its fixed height and width will work!
TouchableHighlight component can only has one child element, thus if we want to have multiple children elements, wrap them into a single view container.
Finally using Navigator instead of NavigatorIOS, there are several important things to remember:
renderScene
method in index.ios.js that defines what component to render when there is an scene being pushed. // In parent component, we define renderScene method:
renderScene(route, navigator) {
if(route.name == 'Main') {
return <Main navigator={navigator} {...route.passProps} />
}
if(route.name == 'Home') {
return <Home navigator={navigator} {...route.passProps} />
}
},
// And in child component, we put all data we want to pass to next scene in route object.
_navigate(property){
this.props.navigator.push({
name: 'Home',
passProps: {
name: property
}
})
}
<TouchableHighlight onPress={ () => this._navigate('Hello World') }>
<Text>GO To View</Text>
</TouchableHighlight>
And utilizing the spread syntax of passing properties, we can easily allow next scene to use the data passed from the previous scene, the one being trigger(ususally by pressing).
onPress={this.onPress.bind(this)}
, we have to manually bind this to it!!! check this post for more information. And refer to the source code of example navigator example .
Check this post for more helpful information.
render() {
return (
<TabBarIOS selectedTab={this.state.selectedTab}>
<TabBarIOS.Item
selected={this.state.selectedTab === 'welcome'}
systemIcon="featured"
onPress={() => {
this.setState({
selectedTab: 'welcome',
});
}}>
<Welcome/>
</TabBarIOS.Item>
<TabBarIOS.Item
selected={this.state.selectedTab === 'more'}
systemIcon="featured"
onPress={() => {
this.setState({
selectedTab: 'more',
});
}}>
<More/>
</TabBarIOS.Item>
</TabBarIOS>
);
}
Here is a handy website that transforms rss feed into json, and provides a API for that: http://rss2json.com/ . For example, my blog’s rss feed being transformed to json is: http://rss2json.com/api.json?rss_url=http%3A%2F%2Fchocoluffy.com%2Fatom.xml . Then using this json file, we can have a much more consistent and clear structure to formatize into RN app.