'React Native: Is it possible to prompt a splash screen every time the user goes out of focus?

I was wondering if it was possible to show the user the splash screen every time he opens the application after going out of focus (navigating to other open applications, and then coming back to mine).

So if a user opens the application, and then navigates to another one without closing mine, he must go through the splash screen again. I could not find any library or method that does this.



Solution 1:[1]

you can use AppState from react-native.

import { AppState } from "react-native";

const appStateChangeListener = (val) => {
  if (val == "active") {
    //val will be "active" only when app is in foreground
    // use navigation to navigate to Splashscreen
  }
};
useEffect(() => {
  const subscription = AppState.addEventListener(
    "change",
    appStateChangeListener
  );

  return () => {
    AppState.removeEventListener("change", appStateChangeListener);
  };
}, []);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sandarshnaroju