代码之家  ›  专栏  ›  技术社区  ›  Ozgur

反应导航动态子屏幕

  •  0
  • Ozgur  · 技术社区  · 6 年前

    我正在创建一个社交媒体应用程序,我有下面的屏幕转换图:

    Emily的个人资料->。。。。

    下面是路由器的一部分来表达我的问题:

    const appStack = createStackNavigator(
      {
        [PROFILE_STACK]: { screen: profileStack },
        [PROFILE_FOLLOWERS_STACK]: { screen: profileFollowersStack },
        [PROFILE_FOLLOWINGS_STACK]: { screen: profileFollowingsStack }
      },
      {
        initialRouteName: PROFILE_STACK,
        headerMode: "none"
      }
    );
    
    const profileStack = createStackNavigator(
      {
        [PROFILE]: {
          screen: UserProfileScreen,
          navigationOptions: () => ({
            header: null
          })
        }
      },
      {
        initialRouteName: PROFILE
      }
    );
    
    const profileFollowersStack = createStackNavigator(
      {
        [PROFILE_FOLLOWERS]: {
          screen: UserFollowersScreen,
          navigationOptions: () => ({
            header: null
          })
        }
      },
      {
        initialRouteName: PROFILE_FOLLOWERS
      }
    );
    
    const profileFollowingsStack = createStackNavigator(
      {
        [PROFILE_FOLLOWINGS]: {
          screen: UserFollowingsScreen,
          navigationOptions: () => ({
            header: null
          })
        }
      },
      {
        initialRouteName: PROFILE_FOLLOWINGS
      }
    );
    
    export const goUserProfile = function(navigation, userId) {
      const { navigate } = navigation;
      navigate(PROFILE_STACK, {
        userId: userId
      });
    };
    
    export const goUserFollowers = function(navigation, userId) {
      const { push } = navigation;
      push(PROFILE_FOLLOWERS_STACK, {
        userId: userId
      });
    };
    
    export const goUserFollowings = function(navigation, userId) {
      const { push } = navigation;
      push(PROFILE_FOLLOWINGS_STACK, {
        userId: userId
      });
    };
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Ozgur    6 年前

    问题是我用的是 navigate() 我的方法 goUserProfile() ,不是 push() 推送() ,我的问题解决了。

    参考文献:

    React Navigation V2: Difference between navigation.push and navigation.navigate

    推荐文章