我有以下 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/