【问题标题】:React native router flux - How to access back pressed from navigation bar (not hardware back button) in android?反应本机路由器通量 - 如何在android中从导航栏(不是硬件后退按钮)访问后退?
【发布时间】:2019-03-10 16:20:33
【问题描述】:
首先,我对本机反应非常陌生。
我在我的项目中使用了 react native router Flux 进行导航。
问题:
我想检查用户是否从顶部栏(导航栏)按下。
我知道如何听硬件返回按钮按下。
但我不知道如果用户从顶栏按下了回音,我该如何收听。
我几乎每天都在搜索。但我无法得到解决方案。
任何建议。
【问题讨论】:
标签:
android
react-native
back
react-native-router-flux
【解决方案1】:
将您的场景注册为:
<Scene
key="latest"
title="LATEST"
titleStyle={{flex:0}}
component={Latest}
onRight={()=>{}}
rightButtonImage={NOTIFICATION_ICON}
onLeft={()=>{}}
leftButtonImage={NAV_SEARCH_ICON}
/>
然后在您的 componentDidMount() 中使用 setParams() 作为:
componentDidMount() {
this.props.navigation.setParams({
'onRight': this.showNotifications,
'onLeft': this.showSearch,
})
}
并实现 showSearch 或 showNotifications 方法。
就是这样。