Wix 反应本机导航更改选项卡和推送屏幕



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

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
}    
});
}
}

您可以使用以下代码切换选项卡

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'
}
}
}
}
});

您可以制作一个组合这 2 个代码的函数。不是我知道的最好的解决方案,但有效!

没有任何方法可以passPropsswitchToTab. 我也在react-native-navigation中找到了,但没有得到任何解决方案。 更改选项卡并使用全局变量推送。

我正在使用react-native-navigation版本1.1.463

更改选项卡switchToTab

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

在索引 2setOnNavigatorEvent选项卡上的选项卡中

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
}
});
}

最新更新