反应本机链接到网页并按回按钮 [英] React Native Linking to web page and push back button
本文介绍了反应本机链接到网页并按回按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我构建了一个 react-native 应用程序,如果用户点击一个链接,那么应用程序会打开一个默认的网络浏览器并转到该链接.
I built a react-native app and if user clicks a link then app opens a default web browser and go to the link.
Linking.openURL(notification.link);
如果用户在 android 或 ios 设备上按下后退按钮,我们有什么办法可以检测到后退动作吗?
If user push back button from the android or ios devices, is there any way we can detect the back move?
推荐答案
你可以在 React Native 中添加一个监听器.
共有 4 个监听器.
There are total 4 listners for the same.
- willFocus - 屏幕将聚焦
- didFocus - 屏幕聚焦(如果有过渡,则过渡已完成)
- willBlur - 屏幕将无法聚焦
- didBlur - 屏幕未聚焦(如果有过渡,则过渡已完成)
- willFocus - the screen will focus
- didFocus - the screen focused (if there was a transition, the transition completed)
- willBlur - the screen will be unfocused
- didBlur - the screen unfocused (if there was a transition, the transition completed)
试试下面的代码
Try the below code
componentWillMount(){
const didFocusSubscription = this.props.navigation.addListener(
'didFocus',
payload => {
console.warn('didFocus ', payload);
# just write your code/call a method here which you want to execute when the app comes from background
}
);
}
完成后不要忘记将其删除.
Dont forget to remove it when it is done.
componentWillUnmount(){
didFocusSubscription.remove();
}
您可以阅读更多这里.谢谢:)
More you can read here. Thanks :)
这篇关于反应本机链接到网页并按回按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文