Created
February 19, 2022 20:15
-
-
Save Stringsaeed/7e2d957ab43a3cf56def692695d7741d to your computer and use it in GitHub Desktop.
react native with react navigation focuse effect for status bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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