Skip to content

Instantly share code, notes, and snippets.

@Stringsaeed
Created February 19, 2022 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stringsaeed/7e2d957ab43a3cf56def692695d7741d to your computer and use it in GitHub Desktop.
Save Stringsaeed/7e2d957ab43a3cf56def692695d7741d to your computer and use it in GitHub Desktop.
react native with react navigation focuse effect for status bar
import {useCallback} from 'react';
import {useFocusEffect} from '@react-navigation/native';
import {ColorValue, StatusBar, StatusBarStyle, Platform} from 'react-native';
const useFocusStatusBar = (
barStyle: StatusBarStyle = 'dark-content',
translucent: boolean = true,
backgroundColor: ColorValue = 'transparent',
): void => {
useFocusEffect(
useCallback(() => {
StatusBar.setBarStyle(barStyle);
if (Platform.OS === 'android') {
StatusBar.setTranslucent(translucent);
StatusBar.setHidden(false);
StatusBar.setBackgroundColor(backgroundColor);
}
}, [backgroundColor, barStyle, translucent]),
);
};
export default useFocusStatusBar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment