Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Navigation 5 'focus' listener not triggered when app is brought back up from background

$
0
0

I am using React Navigation 5, and I am trying to set up a focus listener on a Screen to perform some actions.
The Screen where I need to set up the listener is a Class component that triggers the browser launch, and I want to listen to when the user closes the browser with the "back navigation" and return to the app.
While testing this flow I noticed that the listener is not triggered when returning from the browser, or even when coming up from the background. On the other hand, I could successfully test that when navigating between screens within the app everything works as expected.Moreover, I set up also the unsubscriber for the focus listener and I can see that it's not called improperly, and the listener still seems alive.

I searched for other issues, questions on SO, read the docs, but I couldn't find a solution. It's also true that I'm a newbie as long as React Native is concerned, but I would expect that the focus listener is triggered also after putting the app to background.Or is there actually a way to achieve that?

I managed to create a Snack with a sample code (my app is not using Expo CLI, but I saw that the issue is correctly reproduced there too).It's a very simple StackNavigator with 2 screens. Screen1 is the Class component in which I want to listen for the focus.

  1. by pressing the "GO TO BROWSER" button, the Google website is opened, but navigating back to the app no logs appear informing that the focus is on;
  2. going to background and getting the app back up no logs appear for the focus;
  3. by pressing the "GO TO SCREEN 2" button, the second screen is opened, and upon back navigation, the focus test log informs us that the focus is now on.

My software versions:

iOS and Android 12.4.7 and API 29&24
@react-navigation/native 5.5.1
@react-navigation/stack 5.5.1
react-native-gesture-handler 1.6.1
react-native-safe-area-context 3.0.5
react-native-screens 2.8.0
react-native 0.62.2
node 12.17.0
npm 6.14.6


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>