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

Time:04-08

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.

CodePudding user response:

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);
  };
}, []);
  • Related