lon*_*an4 5 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
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以使用以下代码切换选项卡
Navigation.mergeOptions(this.props.componentId, {
bottomTabs: {
currentTabId: this.props.componentId
}
});
Run Code Online (Sandbox Code Playgroud)
并推动使用
Navigation.push(this.props.componentId, {
component: {
name: 'example.PushedScreen',
passProps: {
text: 'Pushed screen'
},
options: {
topBar: {
title: {
text: 'Pushed screen title'
}
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
您可以结合这两个代码创建一个函数。这不是我所知道的最好的解决方案,但有效!
没有任何办法可以passProps与switchToTab. 我也找到了react-native-navigation但没有得到任何解决方案。使用全局变量更改选项卡和推送。
我正在使用react-native-navigation版本1.1.463
更改选项卡switchToTab
global.isComeFromBooking = true
this.props.navigator.switchToTab({
tabIndex: 2,
});
Run Code Online (Sandbox Code Playgroud)
在索引 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
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2313 次 |
| 最近记录: |