kadiraydinli / react-native-system-navigation-bar

React Native lets you customize the navigation bar for Android.
https://www.npmjs.com/package/react-native-system-navigation-bar
MIT License
270 stars 19 forks source link

How to not miss system bar settings after hiding app? #62

Closed Robgen49 closed 3 months ago

Robgen49 commented 3 months ago

Description

Android

when im hiding app and open it after that again, system bar takes default settings (not stickyImmersive)

i tried to set settings App.tsx this way:

....
import SystemNavigationBar from 'react-native-system-navigation-bar';
SystemNavigationBar.stickyImmersive();
....
function App(): ....

react-native-system-navigation-bar version

2.6.4

React Native version

0.74.3

Snack, code example, screenshot, or link to a repository

5273935388555209233 5273935388555209232 5273935388555209231 5273935388555209230

Robgen49 commented 3 months ago

Ohhh im so sorry i think its not an issue

just use AppState this way:

  SystemNavigationBar.stickyImmersive(); // set value that you need like initial when app is starting first time

  const appState = useRef(AppState.currentState); 

  useEffect(() => {
    const subscription = AppState.addEventListener('change', nextAppState => {
      if (
        appState.current.match(/inactive|background/) &&
        nextAppState === 'active'
      ) {
        SystemNavigationBar.stickyImmersive(); // set value what you need everytime you hide and open app 
      }
      appState.current = nextAppState;
    });

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