React Native Linking to web page and push back button

问题描述 投票:0回答:1

我构建了一个本机应用程序,如果用户单击链接,则该应用程序将打开默认的Web浏览器并转到该链接。

Linking.openURL(notification.link);

如果用户从android或ios设备上按下后退按钮,有什么方法可以检测到后退?

react-native
1个回答
0
投票

您可以在react native中为其添加一个侦听器。

总共有4个相同的列表器。

  1. willFocus-屏幕将聚焦
  2. didFocus-屏幕聚焦(如果存在过渡,则过渡完成)
  3. willBlur-屏幕将无法对焦
  4. didBlur-屏幕未聚焦(如果存在过渡,则过渡完成)

试试下面的代码

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
      }
    );
}

完成后,请不要忘记删除它。

componentWillUnmount(){
    didFocusSubscription.remove();
}

更多,您可以阅读here。谢谢:)

© www.soinside.com 2019 - 2024. All rights reserved.