【问题标题】:How to get bottomTab press action with wix react-native-navigation?如何使用 wix react-native-navigation 获得 bottomTab 按下操作?
【发布时间】:2020-08-23 19:08:28
【问题描述】:

我已经在 react-native-navigation 中设置了带有底部标签的导航,这工作正常

bottomTabs: {
  id: 'BOTTOM_TABS_LAYOUT',
  children: [
    {
      stack: {
        id: 'HOME_TAB',
        children: [
          {
            component: {
              id: 'HOME_SCREEN'
              name: 'HomeScreen'
            }
          }
        ],
        options: {
          bottomTab: {
            icon: require('./home.png')
          }
        }
      }
    },
    {
      stack: {
        id: 'PROFILE_TAB',
        children: [
          {
            component: {
              id: 'PROFILE_SCREEN',
              name: 'ProfileScreen'
            }
          }
        ],
        options: {
          bottomTab: {
            icon: require('./profile.png')
          }
        }
      }
    }
  ]
}

但是当我从一个选项卡切换到另一个选项卡时,我想添加一些其他代码,该怎么做?

【问题讨论】:

    标签: react-native react-native-navigation wix-react-native-navigation


    【解决方案1】:

    您可以通过注册导航事件侦听器来侦听选项卡选择事件。 tabSelected 事件在选定的选项卡发生更改时发出。

    Navigation.events().registerBottomTabSelectedListener((selectedTabIndex, unselectedTabIndex) => {
    });
    

    如果您想自己处理选项卡选择,请在您想处理选项的bottomTab 上设置selectTabOnPress: false 选项,并注册一个tabPressed 侦听器来处理选项卡按下事件。当用户按下选项卡时会发出此事件。

    options: {
      bottomTab: {
        icon: require('./home.png'),
        selectTabOnPress: false
      }
    }
    
    Navigation.events().registerBottomPressedListener((tabIndex) => {
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-20
      • 2018-12-02
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2020-01-15
      相关资源
      最近更新 更多