Is there a way to detect if the AppState went from background to inactive?

Viewed 92

I know that you can detect the state from foreground -> inactive and inactive -> background from the code below but I'm not too sure if I can detect when the app is in background -> inactive. (swipe up) Is it even possible to detect this?

useEffect(() => {
    const subscription = AppState.addEventListener("change", nextAppState => {
      if (
        appState.current.match(/inactive|background/) &&
        nextAppState === "active"
      ) {
        console.log("App has come to the foreground!");
      }

      appState.current = nextAppState;
      setAppStateVisible(appState.current);
      console.log("AppState", appState.current);
    });

    return () => {
      subscription.remove();
    };
  }, []);
0 Answers
Related