【问题标题】:React Native. Hiding item from BottomTab.Navigator in react-navigation反应原生。在反应导航中隐藏底部 Tab.Navigator 中的项目
【发布时间】:2020-05-03 15:39:55
【问题描述】:

假设我有 3 页。 HomeSettingsPage

我有

<BottomTab.Navigator>
  <BottomTab.Screen name="Home" component={HomeScreen}/>
  <BottomTab.Screen name="Settings" component={SettingsScreen}/>
  <BottomTab.Screen name="Page" component={PageScreen}/>
</BottomTab.Navigator>

所有 3 个都显示在底部导航中。

我想从底部导航访问HomeSettings,从Home 页面内的链接访问Page

我的问题是有没有办法从底部导航隐藏Page,但仍然从其他页面链接到它并将道具和数据传递给它?

我尝试从&lt;BottomTab.Screen&gt; 中删除Page,但后来我无法使用navigation.navigate("Page") 导航到页面,我需要这个以便将道具和数据传递到该页面

这是来自应用程序的一些代码。这段代码是用expo生成的

// App.js
render (
<NavigationContainer
          ref={containerRef}
          initialState={initialNavigationState}
        >
          <Stack.Navigator>
            <Stack.Screen name="Root" component={BottomTabNavigator} />
          </Stack.Navigator>
        </NavigationContainer>
      </View>
)
//bottomTabNavigator component
<RootStack.Navigator initialRouteName={INITIAL_ROUTE_NAME}>
      <RootStack.Screen
        name="Home"
        component={HomeScreen}
        options={{
          title: "Get Started",
          tabBarIcon: ({ focused }) => (
            <TabBarIcon focused={focused} name="md-code-working" />
          ),
        }}
      />
      <RootStack.Screen
        name="Profile"
        component={ProfileScreen}
        options={{
          tabBarVisible: false,
          title: "Your Profile",
          tabBarIcon: ({ focused }) => (
            <TabBarIcon focused={focused} name="md-book" />
          ),
        }}
      />
    </RootStack.Navigator>

谢谢

【问题讨论】:

    标签: javascript react-native navigation react-navigation


    【解决方案1】:

    我不确定我是否理解正确,但我认为这就是你要找的。

    https://reactnavigation.org/docs/stack-navigator/

    安装完所有东西后,你可以做这样的事情

    const RootStackNavigator = () => {
        return(
            <RootStack.Navigator>
                <RootStack.Screen name="main" component = {BottomStackScreen}/>
                <RootStack.Screen name="Page" component={PageScreen} />
            </RootStack.Navigator>
        )
    }
    

    因此,在您的代码中,您可以将 app.js 切换为:

    <Stack.Navigator>
       <Stack.Screen name="Root" component={BottomTabNavigator} />
       <Stack.Screen name="Page" component={PageScreen} />
    </Stack.Navigator>
    

    然后你可以使用this.props.navigation.navigate("Page");导航到页面

    【讨论】:

    • 这就是我现在所拥有的。它会将HomeSettingsPage 渲染到底部导航中。我只想让它渲染HomeSettings
    • 您介意发布您的整个代码吗?因为这取决于你如何构建它以及你的 render() 函数里面有什么。如果你在你的 render() 中有你的底部导航器,它只会渲染你的底部堆栈导航器。如果您的渲染中有根堆栈,它将渲染您的根堆栈。
    • @MiletaDulovic 因此,为了确认,您只想显示 2 个底部堆栈导航,即主页和屏幕,但您希望主页和屏幕都能够访问页面。正确吗?
    • @MiletaDulovic 编辑了我的答案
    • 很抱歉回答迟了。就是这个。有用。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2020-09-26
    • 2020-03-19
    相关资源
    最近更新 更多