-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathuseStatusBarStyle.ts
41 lines (37 loc) · 1.05 KB
/
useStatusBarStyle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {useCallback} from 'react';
import {StatusBar, StatusBarStyle, Platform} from 'react-native';
import {useFocusEffect} from '@react-navigation/native';
import changeNavigationBarColor from 'react-native-navigation-bar-color';
const isAndroid = Platform.OS === 'android';
export function useSetStatusBarStyle() {
return useCallback(
(
backgroundColor: string,
style: StatusBarStyle,
navBarLight?: boolean,
) => {
if (isAndroid) {
StatusBar.setBackgroundColor(backgroundColor);
StatusBar.setTranslucent(true);
}
StatusBar.setBarStyle(style, true);
changeNavigationBarColor(
backgroundColor,
navBarLight === undefined ? true : navBarLight,
true,
);
},
[],
);
}
export default function useStatusBarStyle(
backgroundColor: string,
style: StatusBarStyle,
) {
const setStatusBarStyle = useSetStatusBarStyle();
useFocusEffect(
useCallback(() => {
setStatusBarStyle(backgroundColor, style);
}, [setStatusBarStyle, backgroundColor, style]),
);
}