【问题标题】:React Navigation 5 pass params to screen inside nested navigatorReact Navigation 5 将参数传递到嵌套导航器内的屏幕
【发布时间】:2020-05-27 11:14:53
【问题描述】:

我们正在将 React Navigation 4 中的应用程序迁移到 React Navigation 5。 该项目有一个 BottomTabNavigator,它的其中一条路线有一个嵌套的 TopTabNavigator,其中包含三个选项卡。按下时,BottomTabNavigator 中的选项卡之一导航到排序屏幕,您可以在其中选择排序参数以进行排序,然后导航到添加所选排序参数的“待定”路由,该路由应到达 TopTabNavigator 内的三个列表屏幕之一. 目前,我在这些屏幕中接收到的 route.params 为 null,我认为这是因为中间有另一个导航器(topTabNavigator)。

底部标签导航器

    <BottomTabsNavigator.Navigator
      tabBar={props => <CustomTabBar {...props} />}
      initialRouteName="Pending"
    >
      <BottomTabsNavigator.Screen name="Pending" component={createTopTabsNavigator} />
      <BottomTabsNavigator.Screen name="Sort" component={SortScreen} />
      <BottomTabsNavigator.Screen name="Tab 3" component={Fragment} />
      <BottomTabsNavigator.Screen name="Tab 4" component={Fragment} /> 
      <BottomTabsNavigator.Screen name="Tab 5" component={Fragment} />
      <BottomTabsNavigator.Screen name="Filter" component={Fragment} />
    </BottomTabsNavigator.Navigator>

排序屏幕选项卡:

    handleOnPress(item: { text: string; value: string; }): void {
        const {navigation} = this.props;

        const param = {orderBy: item.value};
        navigation.navigate('Pending', param);
    }

    render(){
        return(
            <View>
                <FlatList
                    data={orderOptions}
                    renderItem={({ item }) => (
                        <ListItem style={{ borderBottomWidth: 0 }} onPress={() => this.handleOnPress(item)}>
                            <Body>
                                <Text>{item.text}</Text>
                            </Body>
                        </ListItem>
                    )}
                    keyExtractor={item => item.text}
                />
            </View>
        );
    }

创建TopTabsNavigator:

    <TopTabsNavigator.Navigator>
      <TopTabsNavigator.Screen name="List1" component={Screen1} />
      <TopTabsNavigator.Screen name="List2" component={Screen2} />
      <TopTabsNavigator.Screen name="List3" component={Screen3} />
    </TopTabsNavigator.Navigator>

非常感谢您解决这个问题

【问题讨论】:

    标签: react-native react-navigation react-navigation-bottom-tab react-navigation-v5


    【解决方案1】:
    navigation.navigate('Root', {
      screen: 'Settings',
      params: { user: 'jane' },
    });
    

    https://reactnavigation.org/docs/en/nesting-navigators.html#navigating-to-a-screen-in-a-nested-navigator

    【讨论】:

    • 太棒了,现在我需要在单击选项卡时从嵌套导航器中获取哪个屏幕处于活动状态,有什么想法吗?因为三个屏幕中的每一个都有一个可以排序的列表
    猜你喜欢
    • 2022-11-11
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 2020-07-30
    • 2021-03-19
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    相关资源
    最近更新 更多