react-native-custom-tabs icon indicating copy to clipboard operation
react-native-custom-tabs copied to clipboard

Is there a way to know that user got back to the app?

Open ronilitman opened this issue 5 years ago • 1 comments

I need to know if the user clicked on Back or X and got back to the app. Is there a way?

ronilitman avatar Mar 11 '19 15:03 ronilitman

You can use AppState event Handler to know if your application has come back in foreground. For Functional component, register AppState.addEventListener('change', handleAppStateChange); in useEffect call and same thing in componentDidMount for class component.

this is my handleAppStateChange: const handleAppStateChange = async (nextAppState) => { console.log('AppState Changed: ', nextAppState); if (nextAppState === 'active') { setIsActive(true); } if(nextAppState === 'background'){ setIsActive(false); } }

Do not forget to unsubscribe for the event.

akanksha-agarwal93 avatar Jan 08 '21 06:01 akanksha-agarwal93