-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathreact-native-safe-area-context.native.tsx
More file actions
39 lines (33 loc) · 1.1 KB
/
react-native-safe-area-context.native.tsx
File metadata and controls
39 lines (33 loc) · 1.1 KB
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
import { useContext, useMemo, type PropsWithChildren } from "react";
import { VariableContext } from "react-native-css/style-collection";
import {
SafeAreaProvider as OriginalSafeAreaProvider,
useSafeAreaInsets,
type SafeAreaProviderProps,
} from "react-native-safe-area-context";
export * from "react-native-safe-area-context";
export function SafeAreaProvider({
children,
...props
}: SafeAreaProviderProps) {
return (
<OriginalSafeAreaProvider {...props}>
<SafeAreaEnv>{children}</SafeAreaEnv>
</OriginalSafeAreaProvider>
);
}
function SafeAreaEnv({ children }: PropsWithChildren) {
const insets = useSafeAreaInsets();
const parentVars = useContext(VariableContext);
const value = useMemo(
() => ({
...parentVars,
"--react-native-css-safe-area-inset-bottom": insets.bottom,
"--react-native-css-safe-area-inset-left": insets.left,
"--react-native-css-safe-area-inset-right": insets.right,
"--react-native-css-safe-area-inset-top": insets.top,
}),
[parentVars, insets],
);
return <VariableContext value={value}>{children}</VariableContext>;
}