一、欢迎页到首页定时器

欢迎页

  1. //定时器
  2. componentDidMount() {
  3. setTimeout(()=>{
  4. this.props.navigation.navigate("Home")
  5. },3000)
  6. }
  7. //清除定时器
  8. componentWillUnmount(){
  9. if(this.timer){
  10. clearTimeout(this.timer)
  11. }
  12. }

routers/index.js

  1. const AppNavigator = createStackNavigator(
  2. {
  3. Welcom:{
  4. screen:WelcomPage,
  5. navigationOptions:{
  6. header:null //没有头部导航
  7. }
  8. },
  9. Home: {
  10. screen: HomePage,
  11. navigationOptions:{
  12. headerTitle:"网易云音乐",
  13. headerLeft:null, //首页不设置返回键
  14. }
  15. },
  16. )

二、配置带底部导航的顶部导航

官方文档

  1. //tabs.js
  2. const TabNavigator = createBottomTabNavigator({
  3. Music:{
  4. screen:MusicPage,
  5. navigationOptions:{
  6. tabBarLabel:"音乐"
  7. }
  8. },
  9. Mv:MvPage
  10. },{
  11. defaultNavigationOptions: ({ navigation }) => ({
  12. tabBarIcon: ({ focused, horizontal, tintColor }) => {
  13. const { routeName } = navigation.state;
  14. let IconComponent = Ionicons;
  15. let iconName;
  16. if (routeName === 'Music') {
  17. iconName = `ios-home`;
  18. } else if (routeName === 'Mv') {
  19. iconName = `ios-options`;
  20. }
  21. // You can return any component that you like here!
  22. return <IconComponent name={iconName} size={25} color={tintColor} />;
  23. },
  24. }),
  25. tabBarOptions:{
  26. activeTintColor:'red', //点击颜色
  27. inactiveTintColor:"blue", //初始颜色
  28. style:{
  29. backgroundColor:"#eee"
  30. },
  31. labelStyle: {
  32. fontSize: 18,
  33. }
  34. },
  35. //配置顶部导航
  36. navigationOptions:({navigation})=>{
  37. const {routeName}= navigation.state.routes[navigation.state.index];
  38. if (routeName === 'Music') {
  39. return{
  40. headerTitle:"音乐"
  41. }
  42. } else if (routeName === 'Mv') {
  43. return{
  44. headerTitle:"MV"
  45. }
  46. }
  47. }
  48. });