简体   繁体   English

React Native Router Flux-如何在Android中访问从导航栏(而非硬件后退按钮)按下的后退?

[英]React native router flux - How to access back pressed from navigation bar (not hardware back button) in android?

First of all, I'm very new to react native. 首先,我是新来的本地人。 I have used react native router flux for navigation in my project. 我已在项目中使用react本机路由器流量进行导航。

Problem: I want to check if the user has pressed back from top bar(navigation bar). 问题:我想检查用户是否从顶部栏(导航栏)按下了。 I know how to listen to hardware back button press. 我知道如何聆听硬件后退按钮的按下声。

But I cannot figure out how to listen if the user has pressed back from top bar. 但是我无法弄清楚如果用户从顶部栏按下了该如何收听。

I searched for almost everyday possible. 我几乎每天都在搜索。 But I'm not able to get the solution. 但是我无法找到解决方案。

Any suggestions . 有什么建议么 。

Register your scene as: 将场景注册为:

<Scene 
         key="latest"
         title="LATEST"
         titleStyle={{flex:0}}
         component={Latest}
         onRight={()=>{}} 
         rightButtonImage={NOTIFICATION_ICON}
         onLeft={()=>{}}
         leftButtonImage={NAV_SEARCH_ICON}
/>

and then in your componentDidMount() use setParams() as: 然后在您的componentDidMount()中使用setParams()作为:

componentDidMount() {
          this.props.navigation.setParams({
               'onRight': this.showNotifications,
               'onLeft': this.showSearch,
         })
  }

and implement showSearch or showNotifications method. 并实现showSearch或showNotifications方法。

That's it . 而已 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM