一、欢迎页到首页定时器
欢迎页
//定时器
componentDidMount() {
setTimeout(()=>{
this.props.navigation.navigate("Home")
},3000)
}
//清除定时器
componentWillUnmount(){
if(this.timer){
clearTimeout(this.timer)
}
}
routers/index.js
const AppNavigator = createStackNavigator(
{
Welcom:{
screen:WelcomPage,
navigationOptions:{
header:null //没有头部导航
}
},
Home: {
screen: HomePage,
navigationOptions:{
headerTitle:"网易云音乐",
headerLeft:null, //首页不设置返回键
}
},
)
二、配置带底部导航的顶部导航
//tabs.js
const TabNavigator = createBottomTabNavigator({
Music:{
screen:MusicPage,
navigationOptions:{
tabBarLabel:"音乐"
}
},
Mv:MvPage
},{
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
let IconComponent = Ionicons;
let iconName;
if (routeName === 'Music') {
iconName = `ios-home`;
} else if (routeName === 'Mv') {
iconName = `ios-options`;
}
// You can return any component that you like here!
return <IconComponent name={iconName} size={25} color={tintColor} />;
},
}),
tabBarOptions:{
activeTintColor:'red', //点击颜色
inactiveTintColor:"blue", //初始颜色
style:{
backgroundColor:"#eee"
},
labelStyle: {
fontSize: 18,
}
},
//配置顶部导航
navigationOptions:({navigation})=>{
const {routeName}= navigation.state.routes[navigation.state.index];
if (routeName === 'Music') {
return{
headerTitle:"音乐"
}
} else if (routeName === 'Mv') {
return{
headerTitle:"MV"
}
}
}
});