繁体   English   中英

如何知道React Native中哪个屏幕专注于屏幕级别?

[英]How to know which screen is focused at screen level in React Native?

我想知道如何在使用createBottomTabNavigator时使用React Navigation检索有关哪个选项卡聚焦在屏幕级别的createBottomTabNavigator 使用focused ,可以知道选项卡是否聚焦,但是如果不聚焦,我们就不知道哪个聚焦。 我需要的伪代码将类似于以下内容(currentRoute不存在):

 Homepage: {
    screen: HomeNavigator,
    navigationOptions: {
      tabBarIcon: ({ focused }) => {
        if (focused) {
          return <Icon source={homeLogoOn} />
        } else {
          if (currentRoute === 'Me') {
            return <Icon source={homeLogoOffLeft} />
          } else if (currentRoute === 'MyFriends') {
            return <Icon source={homeLogoOffRight} />
          }
        }
      },
      tabBarLabel: <View />,
    },

react-navigation使HOC知道当前屏幕是否聚焦。

您可以在此处查看有关此文档的文档: https : //reactnavigation.org/docs/en/with-navigation-focus.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM