国际惯例,先来看看效果图
使用起来简单
安装
npm install --save react-navigation
然后把我的代码复制。 覆盖你原来的index.ios.js文件即可
跑跑看,然后看看代码完全能懂怎么使用
这里是详细使用教程地址。 https://reactnavigation.org/docs/intro/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
Image
} from 'react-native';
import { TabNavigator } from 'react-navigation';
class A extends Component {
static navigationOptions = {
tabBar: {
label: 'A',
icon: ({ tintColor }) => (
<Image
source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
},
}
render() {
return (
<View style={styles.container}>
<Button
onPress={() => this.props.navigation.navigate('C')}
title="去第三个页面"
/>
</View>
);
}
}
class B extends React.Component {
static navigationOptions = {
tabBar: {
label: 'B',
icon: ({ tintColor }) => (
<Image
source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
},
}
render() {
return (
<View style={styles.container}>
<Text >第二个页面</Text>
</View>
);
}
}
class C extends React.Component {
static navigationOptions = {
tabBar: {
label: 'C',
icon: ({ tintColor }) => (
<Image
source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
},
}
render() {
return (
<View style={styles.container}>
<Button
onPress={() => this.props.navigation.goBack()}
title="第三个页面,点我返回第一个页面"
/>
</View>
);
}
}
class D extends React.Component {
static navigationOptions = {
tabBar: {
label: 'D',
icon: ({ tintColor }) => (
<Image
source={{uri:'https://zos.alipayobjects.com/rmsportal/dNuvNrtqUztHCwM.png'}}
style={[styles.icon, {tintColor: tintColor}]}
/>
),
},
}
render() {
return (
<View style={styles.container}>
<Text >第四个页面</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
icon: {
width: 26,
height: 26,
},
});
const demo = TabNavigator(
{
A: {
screen: A,
},
B: {
screen: B,
},
C: {
screen: C,
},
D: {
screen: D,
},
},
{
tabBarOptions: {
activeTintColor: '#FF6400',
},
}
);
AppRegistry.registerComponent('demo', () => demo);