React Native Linking to web page and push back button

前端 未结 1 971
梦毁少年i
梦毁少年i 2021-01-16 21:33

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

1条回答
  •  再見小時候
    2021-01-16 21:47

    You can add a listener for the same in react native.

    There are total 4 listners for the same.

    1. willFocus - the screen will focus
    2. didFocus - the screen focused (if there was a transition, the transition completed)
    3. willBlur - the screen will be unfocused
    4. 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 :)

    0 讨论(0)
提交回复
热议问题