|
@@ -7,23 +7,29 @@ export const SafeAreaContext = React.createContext<EdgeInsets | null>(null);
|
7
|
7
|
|
8
|
8
|
export interface SafeAreaViewProps {
|
9
|
9
|
children?: React.ReactNode;
|
|
10
|
+ initialSafeAreaInsets?: EdgeInsets | null;
|
10
|
11
|
}
|
11
|
12
|
|
12
|
|
-export function SafeAreaProvider({ children }: SafeAreaViewProps) {
|
|
13
|
+export function SafeAreaProvider({
|
|
14
|
+ children,
|
|
15
|
+ initialSafeAreaInsets,
|
|
16
|
+}: SafeAreaViewProps) {
|
13
|
17
|
let parentInsets = useParentSafeArea();
|
14
|
|
- const [insets, setInsets] = React.useState<EdgeInsets | null>(null);
|
|
18
|
+ const [insets, setInsets] = React.useState<EdgeInsets | null | undefined>(
|
|
19
|
+ initialSafeAreaInsets,
|
|
20
|
+ );
|
15
|
21
|
const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
|
16
|
22
|
setInsets(event.nativeEvent.insets);
|
17
|
23
|
}, []);
|
18
|
24
|
|
19
|
25
|
// If a provider is nested inside of another provider then we can just use
|
20
|
26
|
// the parent insets, without rendering another native safe area view
|
21
|
|
- if (parentInsets) {
|
|
27
|
+ if (parentInsets != null) {
|
22
|
28
|
return <View style={styles.fill}>{children}</View>;
|
23
|
29
|
} else {
|
24
|
30
|
return (
|
25
|
31
|
<NativeSafeAreaView style={styles.fill} onInsetsChange={onInsetsChange}>
|
26
|
|
- {insets !== null ? (
|
|
32
|
+ {insets != null ? (
|
27
|
33
|
<SafeAreaContext.Provider value={insets}>
|
28
|
34
|
{children}
|
29
|
35
|
</SafeAreaContext.Provider>
|