react-native - 如何使用react-native让TabBarIOS弹出到导航堆栈的顶部?

标签 react-native tabbar tabbarios

我有以下 TabBarIOS.Item 设置:

          <TabBarIOS.Item
            selected={this.state.selectedTab === 'tab1'}
            title='Tab 1'
            icon={require('./Components/Icons/IconImages/Tab1Icon.png')}
            onPress={() => {
              this.setState({
                selectedTab: 'tab1'
              });

             }}>
            <MyNavigatorIOS client={this.state.client} initialStep={this.state.initialStep} />

          </TabBarIOS.Item>

我正在尝试使用 onPress 事件来触发 this.props.navigator.popToTop();,按照this example in the react native docs 。但不同之处在于,我希望 TabBarIOS onPress 事件触发 popToTop() 而不是子 MyNavigatorIOS 组件。我怎样才能做到这一点?

最佳答案

我遇到了同样的问题,您可以做的就是向您的 View 及其内部的导航器添加引用,如下所示:

          this.refs.timeline.refs.timelineNavigator.popToTop()

所以 TabBar 代码如下所示:

    <TabBarIOS.Item
      systemIcon="history"
      title="Timeline"
      badge={this.state.timelineBadge}
      selected={this.state.selectedTab === 'timeline'}
      onPress={() => {
        if (this.state.selectedTab === 'timeline') {
          this.refs.timeline.refs.timelineNavigator.popToTop()
        } else {
          this.setState({ selectedTab: 'timeline' })
        }
      }}>
      <Timeline
        ref="timeline"
      /> 
    </TabBarIOS.Item>

关于react-native - 如何使用react-native让TabBarIOS弹出到导航堆栈的顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38468107/

相关文章:

react-native - React Navigation 使用 Redux 重置堆栈的正确方法

iphone sdk tabbar 查看 socket 未设置

iphone - TabBar:应用程序启动后首先显示在 ViewController 中

ios - 在 TabBarIOS 中使用图像 ~ 低质量,色调破坏图像

ios - 使用 React Native 隐藏在 TabBarIOS 后面的内容

javascript - 如何将属性传递给选项卡导航器内的 react-native 组件?

javascript - React Native POST 数据到 API 不起作用

javascript - 子类化并扩展 Jest 模拟的 Promise

ios - 如何使用背景图像删除 > iOS 10 和 Swift 4 中的标签栏顶部边框(阴影)?