Wix react-native-navigation更改选项卡和推屏

时间:2018-08-16 07:07:52

标签: javascript react-native react-native-navigation

如何同时切换选项卡和推屏? 当按下按钮时, 我想切换到另一个标签并推送新屏幕。 可能吗?

class Example extends Component {
      buttonHandler = () => {
        this.props.navigator.switchToTab({
          tabIndex: 0
        });
        this.props.navigator.push({  // actually this navigator's tabIndex is 0 
          screen: "dc.Examplecreen",
          title: "Exampe", 
          passProps: {
            lesson : this.props
          }    
       });
   }
}

2 个答案:

答案 0 :(得分:2)

无法使用passPropsswitchToTab。我也在react-native-navigation中找到了,但没有任何解决方案。更改标签并使用全局变量进行推送。

我正在使用react-native-navigation1.1.463

更改标签switchToTab

global.isComeFromBooking = true
this.props.navigator.switchToTab({
   tabIndex: 2,
});

在索引2 setOnNavigatorEvent上的标签

componentDidMount() {
    this.props.navigator.setOnNavigatorEvent((e) => {
      if (e.id == 'willAppear' && global.isComeFromBooking) {
        this.props.navigator.push({
          screen: 'Reservations',
          title: 'Bookings',
          animated: true,
          style: {
            backgroundColor: 'black',
          },
          backButtonTitle: '',
        });
        global.isComeFromBooking = false
      }
    });
}

答案 1 :(得分:1)

您可以使用以下代码切换标签

Navigation.mergeOptions(this.props.componentId, {
  bottomTabs: {
    currentTabId: this.props.componentId
  }
});

并使用

推送
Navigation.push(this.props.componentId, {
  component: {
    name: 'example.PushedScreen',
    passProps: {
      text: 'Pushed screen'
    },
    options: {
      topBar: {
        title: {
          text: 'Pushed screen title'
        }
      }
    }
  }
});

您可以组合两个代码来创建函数。不是我所知道的最佳解决方案,但是可以!

相关问题