@amazon-devices/react-native-safe-area-context 2.0.1759135970 → 8.0.9000000000-rn-83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -302
- package/SystemBundles/920f0b3a0c43cc93db1621b4c3a47e06a0d4ed32175c793e9934ad9c764fbc25.bundle +7374 -0
- package/SystemBundles/920f0b3a0c43cc93db1621b4c3a47e06a0d4ed32175c793e9934ad9c764fbc25.map +2780 -0
- package/SystemModules/amzn__react-native-safe-area-context-8.modules.txt +7 -0
- package/SystemModules/amzn__react-native-safe-area-context-8.private.modules.txt +61 -0
- package/SystemModules/keplerscript-system-bundle-config.json +3 -3
- package/android/build.gradle +103 -25
- package/android/gradle.properties +1 -0
- package/android/spotless.gradle +24 -0
- package/android/src/fabric/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.kt +25 -0
- package/android/src/fabric/java/com/th3rdwave/safeareacontext/UIManagerHelperCompat.kt +14 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.kt +3 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/Rect.kt +3 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextModule.kt +32 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.kt +41 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProvider.kt +47 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProviderManager.kt +41 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt +102 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt +155 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.kt +16 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewLocalData.kt +7 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.kt +73 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.kt +6 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewShadowNode.kt +170 -0
- package/android/src/main/java/com/th3rdwave/safeareacontext/SerializationUtils.kt +39 -0
- package/android/src/main/jni/CMakeLists.txt +87 -0
- package/android/src/main/jni/safeareacontext.h +17 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaProviderManagerDelegate.java +31 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaProviderManagerInterface.java +16 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaViewManagerDelegate.java +41 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/RNCSafeAreaViewManagerInterface.java +20 -0
- package/android/src/paper/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.kt +29 -0
- package/android/src/paper/java/com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec.java +56 -0
- package/android/src/paper/java/com/th3rdwave/safeareacontext/UIManagerHelperCompat.kt +20 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewComponentDescriptor.h +25 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.cpp +131 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.h +36 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.cpp +23 -0
- package/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.h +56 -0
- package/ios/Fabric/RNCSafeAreaProviderComponentView.h +13 -0
- package/ios/Fabric/RNCSafeAreaProviderComponentView.mm +129 -0
- package/ios/Fabric/RNCSafeAreaViewComponentView.h +11 -0
- package/ios/Fabric/RNCSafeAreaViewComponentView.mm +153 -0
- package/ios/RNCSafeAreaContext.h +9 -0
- package/ios/RNCSafeAreaContext.mm +85 -0
- package/ios/{SafeAreaView/RNCSafeAreaProvider.h → RNCSafeAreaProvider.h} +4 -0
- package/ios/RNCSafeAreaProvider.m +102 -0
- package/ios/RNCSafeAreaProviderManager.m +20 -0
- package/ios/{SafeAreaView/RNCSafeAreaShadowView.m → RNCSafeAreaShadowView.m} +50 -36
- package/ios/RNCSafeAreaUtils.h +22 -0
- package/ios/RNCSafeAreaUtils.m +41 -0
- package/ios/{SafeAreaView/RNCSafeAreaView.h → RNCSafeAreaView.h} +8 -4
- package/ios/RNCSafeAreaView.m +168 -0
- package/ios/RNCSafeAreaViewEdgeMode.h +12 -0
- package/ios/RNCSafeAreaViewEdgeMode.m +16 -0
- package/ios/RNCSafeAreaViewEdges.h +15 -0
- package/ios/RNCSafeAreaViewEdges.m +36 -0
- package/ios/{SafeAreaView/RNCSafeAreaViewLocalData.h → RNCSafeAreaViewLocalData.h} +12 -1
- package/ios/{SafeAreaView/RNCSafeAreaViewLocalData.m → RNCSafeAreaViewLocalData.m} +4 -0
- package/ios/{SafeAreaView/RNCSafeAreaViewManager.m → RNCSafeAreaViewManager.m} +5 -1
- package/ios/RNCSafeAreaViewMode.m +15 -0
- package/ios/{SafeAreaView.xcodeproj → RNSafeAreaContext.xcodeproj}/project.pbxproj +70 -56
- package/jest/mock.tsx +59 -0
- package/kepler-compatibility.json +2 -2
- package/lib/commonjs/CompatNativeSafeAreaProvider.js +7 -8
- package/lib/commonjs/CompatNativeSafeAreaProvider.js.map +1 -1
- package/lib/commonjs/InitialWindow.js.map +1 -1
- package/lib/commonjs/InitialWindow.kepler.js +1 -1
- package/lib/commonjs/InitialWindow.kepler.js.map +1 -1
- package/lib/commonjs/InitialWindow.native.js +4 -4
- package/lib/commonjs/InitialWindow.native.js.map +1 -1
- package/lib/commonjs/NativeSafeAreaProvider.js +7 -125
- package/lib/commonjs/NativeSafeAreaProvider.js.map +1 -1
- package/lib/commonjs/NativeSafeAreaProvider.kepler.js +6 -2
- package/lib/commonjs/NativeSafeAreaProvider.kepler.js.map +1 -1
- package/lib/commonjs/NativeSafeAreaProvider.web.js +135 -0
- package/lib/commonjs/NativeSafeAreaProvider.web.js.map +1 -0
- package/lib/commonjs/NativeSafeAreaProvider.windows.js +6 -2
- package/lib/commonjs/NativeSafeAreaProvider.windows.js.map +1 -1
- package/lib/commonjs/SafeArea.types.js.map +1 -1
- package/lib/commonjs/SafeAreaContext.js +56 -36
- package/lib/commonjs/SafeAreaContext.js.map +1 -1
- package/lib/commonjs/SafeAreaView.js +40 -73
- package/lib/commonjs/SafeAreaView.js.map +1 -1
- package/lib/commonjs/SafeAreaView.kepler.js.map +1 -1
- package/lib/commonjs/SafeAreaView.web.js +91 -0
- package/lib/commonjs/SafeAreaView.web.js.map +1 -0
- package/lib/commonjs/SafeAreaView.windows.js.map +1 -1
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js +9 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js +10 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js +12 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js.map +1 -0
- package/lib/module/CompatNativeSafeAreaProvider.js +8 -5
- package/lib/module/CompatNativeSafeAreaProvider.js.map +1 -1
- package/lib/module/InitialWindow.js +2 -0
- package/lib/module/InitialWindow.js.map +1 -1
- package/lib/module/InitialWindow.kepler.js +3 -1
- package/lib/module/InitialWindow.kepler.js.map +1 -1
- package/lib/module/InitialWindow.native.js +5 -4
- package/lib/module/InitialWindow.native.js.map +1 -1
- package/lib/module/NativeSafeAreaProvider.js +3 -122
- package/lib/module/NativeSafeAreaProvider.js.map +1 -1
- package/lib/module/NativeSafeAreaProvider.kepler.js +3 -2
- package/lib/module/NativeSafeAreaProvider.kepler.js.map +1 -1
- package/lib/module/NativeSafeAreaProvider.web.js +130 -0
- package/lib/module/NativeSafeAreaProvider.web.js.map +1 -0
- package/lib/module/NativeSafeAreaProvider.windows.js +3 -2
- package/lib/module/NativeSafeAreaProvider.windows.js.map +1 -1
- package/lib/module/SafeArea.types.js +2 -0
- package/lib/module/SafeArea.types.js.map +1 -1
- package/lib/module/SafeAreaContext.js +57 -33
- package/lib/module/SafeAreaContext.js.map +1 -1
- package/lib/module/SafeAreaView.js +38 -69
- package/lib/module/SafeAreaView.js.map +1 -1
- package/lib/module/SafeAreaView.kepler.js +2 -0
- package/lib/module/SafeAreaView.kepler.js.map +1 -1
- package/lib/module/SafeAreaView.web.js +86 -0
- package/lib/module/SafeAreaView.web.js.map +1 -0
- package/lib/module/SafeAreaView.windows.js +2 -0
- package/lib/module/SafeAreaView.windows.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeSafeAreaContext.js +5 -0
- package/lib/module/specs/NativeSafeAreaContext.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaProvider.js +5 -0
- package/lib/module/specs/NativeSafeAreaProvider.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaView.js +7 -0
- package/lib/module/specs/NativeSafeAreaView.js.map +1 -0
- package/lib/typescript/CompatNativeSafeAreaProvider.d.ts +4 -0
- package/lib/typescript/CompatNativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/{src/InitialWindow.d.ts → InitialWindow.d.ts} +2 -1
- package/lib/typescript/InitialWindow.d.ts.map +1 -0
- package/lib/typescript/{src/InitialWindow.kepler.d.ts → InitialWindow.kepler.d.ts} +1 -0
- package/lib/typescript/InitialWindow.kepler.d.ts.map +1 -0
- package/lib/typescript/{src/InitialWindow.native.d.ts → InitialWindow.native.d.ts} +2 -1
- package/lib/typescript/InitialWindow.native.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.d.ts +3 -0
- package/lib/typescript/NativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.kepler.d.ts +2 -0
- package/lib/typescript/NativeSafeAreaProvider.kepler.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.web.d.ts +4 -0
- package/lib/typescript/NativeSafeAreaProvider.web.d.ts.map +1 -0
- package/lib/typescript/NativeSafeAreaProvider.windows.d.ts +2 -0
- package/lib/typescript/NativeSafeAreaProvider.windows.d.ts.map +1 -0
- package/lib/typescript/SafeArea.types.d.ts +36 -0
- package/lib/typescript/SafeArea.types.d.ts.map +1 -0
- package/lib/typescript/{src/SafeAreaContext.d.ts → SafeAreaContext.d.ts} +9 -6
- package/lib/typescript/SafeAreaContext.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.d.ts +5 -0
- package/lib/typescript/SafeAreaView.d.ts.map +1 -0
- package/lib/typescript/{src/SafeAreaView.kepler.d.ts → SafeAreaView.kepler.d.ts} +1 -0
- package/lib/typescript/SafeAreaView.kepler.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.web.d.ts +4 -0
- package/lib/typescript/SafeAreaView.web.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.windows.d.ts +3 -0
- package/lib/typescript/SafeAreaView.windows.d.ts.map +1 -0
- package/lib/typescript/{src/index.d.ts → index.d.ts} +1 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts +23 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts +22 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaView.d.ts +14 -0
- package/lib/typescript/specs/NativeSafeAreaView.d.ts.map +1 -0
- package/oss-attribution/attribution.txt +0 -0
- package/oss-attribution/licenseInfos.json +1 -0
- package/package.json +137 -1
- package/react-native-safe-area-context.podspec +26 -4
- package/react-native.config.js +8 -0
- package/src/CompatNativeSafeAreaProvider.tsx +2 -3
- package/src/InitialWindow.kepler.ts +1 -1
- package/src/InitialWindow.native.ts +5 -11
- package/src/InitialWindow.ts +1 -1
- package/src/NativeSafeAreaProvider.kepler.tsx +1 -3
- package/src/NativeSafeAreaProvider.tsx +2 -128
- package/src/NativeSafeAreaProvider.web.tsx +127 -0
- package/src/NativeSafeAreaProvider.windows.tsx +1 -3
- package/src/SafeArea.types.ts +15 -11
- package/src/SafeAreaContext.tsx +66 -43
- package/src/SafeAreaView.tsx +47 -82
- package/src/SafeAreaView.web.tsx +123 -0
- package/src/SafeAreaView.windows.tsx +2 -1
- package/src/index.tsx +2 -0
- package/src/specs/NativeSafeAreaContext.ts +23 -0
- package/src/specs/NativeSafeAreaProvider.ts +29 -0
- package/src/specs/NativeSafeAreaView.ts +17 -0
- package/SystemBundles/e3c0cdeab56b8b622d4f0fd5a80812eafe199fa2287d0e3a09c5e573a1035350.bundle +0 -11031
- package/SystemBundles/e3c0cdeab56b8b622d4f0fd5a80812eafe199fa2287d0e3a09c5e573a1035350.map +0 -1
- package/SystemModules/amzn__react-native-safe-area-context-2.modules.txt +0 -55
- package/SystemModules/amzn__react-native-safe-area-context-2.private.modules.txt +0 -91
- package/THIRD_PARTY_NOTICES.txt +0 -24
- package/android/src/main/java/com/th3rdwave/safeareacontext/EdgeInsets.java +0 -22
- package/android/src/main/java/com/th3rdwave/safeareacontext/InsetsChangeEvent.java +0 -33
- package/android/src/main/java/com/th3rdwave/safeareacontext/Rect.java +0 -22
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextPackage.java +0 -31
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProvider.java +0 -66
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaProviderManager.java +0 -94
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.java +0 -82
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.java +0 -159
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewEdges.java +0 -8
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewLocalData.java +0 -27
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.java +0 -72
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewMode.java +0 -6
- package/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewShadowNode.java +0 -201
- package/android/src/main/java/com/th3rdwave/safeareacontext/SerializationUtils.java +0 -52
- package/ios/SafeAreaView/RCTView+SafeAreaCompat.h +0 -16
- package/ios/SafeAreaView/RCTView+SafeAreaCompat.m +0 -57
- package/ios/SafeAreaView/RNCSafeAreaProvider.m +0 -65
- package/ios/SafeAreaView/RNCSafeAreaProviderManager.m +0 -61
- package/ios/SafeAreaView/RNCSafeAreaView.m +0 -118
- package/ios/SafeAreaView/RNCSafeAreaViewEdges.h +0 -9
- package/ios/SafeAreaView/RNCSafeAreaViewEdges.m +0 -13
- package/ios/SafeAreaView/RNCSafeAreaViewMode.m +0 -11
- package/lib/commonjs/NativeSafeAreaProvider.macos.js +0 -9
- package/lib/commonjs/NativeSafeAreaProvider.macos.js.map +0 -1
- package/lib/commonjs/NativeSafeAreaProvider.native.js +0 -9
- package/lib/commonjs/NativeSafeAreaProvider.native.js.map +0 -1
- package/lib/commonjs/SafeAreaView.macos.js +0 -9
- package/lib/commonjs/SafeAreaView.macos.js.map +0 -1
- package/lib/commonjs/SafeAreaView.native.js +0 -9
- package/lib/commonjs/SafeAreaView.native.js.map +0 -1
- package/lib/commonjs/useWindowDimensions.js +0 -32
- package/lib/commonjs/useWindowDimensions.js.map +0 -1
- package/lib/module/NativeSafeAreaProvider.macos.js +0 -3
- package/lib/module/NativeSafeAreaProvider.macos.js.map +0 -1
- package/lib/module/NativeSafeAreaProvider.native.js +0 -3
- package/lib/module/NativeSafeAreaProvider.native.js.map +0 -1
- package/lib/module/SafeAreaView.macos.js +0 -3
- package/lib/module/SafeAreaView.macos.js.map +0 -1
- package/lib/module/SafeAreaView.native.js +0 -3
- package/lib/module/SafeAreaView.native.js.map +0 -1
- package/lib/module/useWindowDimensions.js +0 -26
- package/lib/module/useWindowDimensions.js.map +0 -1
- package/lib/typescript/src/CompatNativeSafeAreaProvider.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.kepler.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.macos.d.ts +0 -2
- package/lib/typescript/src/NativeSafeAreaProvider.native.d.ts +0 -3
- package/lib/typescript/src/NativeSafeAreaProvider.windows.d.ts +0 -2
- package/lib/typescript/src/SafeArea.types.d.ts +0 -31
- package/lib/typescript/src/SafeAreaView.d.ts +0 -2
- package/lib/typescript/src/SafeAreaView.macos.d.ts +0 -2
- package/lib/typescript/src/SafeAreaView.native.d.ts +0 -2
- package/lib/typescript/src/SafeAreaView.windows.d.ts +0 -2
- package/lib/typescript/src/useWindowDimensions.d.ts +0 -8
- package/src/NativeSafeAreaProvider.macos.tsx +0 -3
- package/src/NativeSafeAreaProvider.native.tsx +0 -6
- package/src/SafeAreaView.macos.tsx +0 -3
- package/src/SafeAreaView.native.tsx +0 -6
- package/src/useWindowDimensions.tsx +0 -35
- /package/ios/{SafeAreaView/RNCSafeAreaProviderManager.h → RNCSafeAreaProviderManager.h} +0 -0
- /package/ios/{SafeAreaView/RNCSafeAreaShadowView.h → RNCSafeAreaShadowView.h} +0 -0
- /package/ios/{SafeAreaView/RNCSafeAreaViewManager.h → RNCSafeAreaViewManager.h} +0 -0
- /package/ios/{SafeAreaView/RNCSafeAreaViewMode.h → RNCSafeAreaViewMode.h} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
import type { NativeSafeAreaProviderProps } from './SafeArea.types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* TODO:
|
|
9
|
+
* Currently insets and frame are based on the window and are not
|
|
10
|
+
* relative to the provider view. This is inconsistent with iOS and Android.
|
|
11
|
+
* However in most cases if the provider view covers the screen this is not
|
|
12
|
+
* an issue.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const CSSTransitions: Record<string, string> = {
|
|
16
|
+
WebkitTransition: 'webkitTransitionEnd',
|
|
17
|
+
Transition: 'transitionEnd',
|
|
18
|
+
MozTransition: 'transitionend',
|
|
19
|
+
MSTransition: 'msTransitionEnd',
|
|
20
|
+
OTransition: 'oTransitionEnd',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function NativeSafeAreaProvider({
|
|
24
|
+
children,
|
|
25
|
+
style,
|
|
26
|
+
onInsetsChange,
|
|
27
|
+
}: NativeSafeAreaProviderProps) {
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
// Skip for SSR.
|
|
30
|
+
if (typeof document === 'undefined') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const element = createContextElement();
|
|
35
|
+
document.body.appendChild(element);
|
|
36
|
+
const onEnd = () => {
|
|
37
|
+
const { paddingTop, paddingBottom, paddingLeft, paddingRight } =
|
|
38
|
+
window.getComputedStyle(element);
|
|
39
|
+
|
|
40
|
+
const insets = {
|
|
41
|
+
top: paddingTop ? parseInt(paddingTop, 10) : 0,
|
|
42
|
+
bottom: paddingBottom ? parseInt(paddingBottom, 10) : 0,
|
|
43
|
+
left: paddingLeft ? parseInt(paddingLeft, 10) : 0,
|
|
44
|
+
right: paddingRight ? parseInt(paddingRight, 10) : 0,
|
|
45
|
+
};
|
|
46
|
+
const frame = {
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0,
|
|
49
|
+
width: document.documentElement.offsetWidth,
|
|
50
|
+
height: document.documentElement.offsetHeight,
|
|
51
|
+
};
|
|
52
|
+
// @ts-ignore: missing properties
|
|
53
|
+
onInsetsChange({ nativeEvent: { insets, frame } });
|
|
54
|
+
};
|
|
55
|
+
element.addEventListener(getSupportedTransitionEvent(), onEnd);
|
|
56
|
+
onEnd();
|
|
57
|
+
return () => {
|
|
58
|
+
document.body.removeChild(element);
|
|
59
|
+
element.removeEventListener(getSupportedTransitionEvent(), onEnd);
|
|
60
|
+
};
|
|
61
|
+
}, [onInsetsChange]);
|
|
62
|
+
|
|
63
|
+
return <View style={style}>{children}</View>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let _supportedTransitionEvent: string | null | undefined = null;
|
|
67
|
+
function getSupportedTransitionEvent(): string {
|
|
68
|
+
if (_supportedTransitionEvent != null) {
|
|
69
|
+
return _supportedTransitionEvent;
|
|
70
|
+
}
|
|
71
|
+
const element = document.createElement('invalidtype');
|
|
72
|
+
|
|
73
|
+
_supportedTransitionEvent = CSSTransitions.Transition;
|
|
74
|
+
for (const key in CSSTransitions) {
|
|
75
|
+
if (element.style[key as keyof CSSStyleDeclaration] !== undefined) {
|
|
76
|
+
_supportedTransitionEvent = CSSTransitions[key];
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return _supportedTransitionEvent as string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type CssEnv = 'constant' | 'env';
|
|
84
|
+
|
|
85
|
+
let _supportedEnv: CssEnv | null = null;
|
|
86
|
+
function getSupportedEnv(): CssEnv {
|
|
87
|
+
if (_supportedEnv !== null) {
|
|
88
|
+
return _supportedEnv;
|
|
89
|
+
}
|
|
90
|
+
const { CSS } = window;
|
|
91
|
+
if (
|
|
92
|
+
CSS &&
|
|
93
|
+
CSS.supports &&
|
|
94
|
+
CSS.supports('top: constant(safe-area-inset-top)')
|
|
95
|
+
) {
|
|
96
|
+
_supportedEnv = 'constant';
|
|
97
|
+
} else {
|
|
98
|
+
_supportedEnv = 'env';
|
|
99
|
+
}
|
|
100
|
+
return _supportedEnv;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getInset(side: string): string {
|
|
104
|
+
return `${getSupportedEnv()}(safe-area-inset-${side})`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function createContextElement(): HTMLElement {
|
|
108
|
+
const element = document.createElement('div');
|
|
109
|
+
const { style } = element;
|
|
110
|
+
style.position = 'fixed';
|
|
111
|
+
style.left = '0';
|
|
112
|
+
style.top = '0';
|
|
113
|
+
style.width = '0';
|
|
114
|
+
style.height = '0';
|
|
115
|
+
style.zIndex = '-1';
|
|
116
|
+
style.overflow = 'hidden';
|
|
117
|
+
style.visibility = 'hidden';
|
|
118
|
+
// Bacon: Anything faster than this and the callback will be invoked too early with the wrong insets
|
|
119
|
+
style.transitionDuration = '0.05s';
|
|
120
|
+
style.transitionProperty = 'padding';
|
|
121
|
+
style.transitionDelay = '0s';
|
|
122
|
+
style.paddingTop = getInset('top');
|
|
123
|
+
style.paddingBottom = getInset('bottom');
|
|
124
|
+
style.paddingLeft = getInset('left');
|
|
125
|
+
style.paddingRight = getInset('right');
|
|
126
|
+
return element;
|
|
127
|
+
}
|
package/src/SafeArea.types.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ViewProps,
|
|
5
|
-
ViewStyle,
|
|
6
|
-
} from 'react-native';
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { NativeSyntheticEvent, ViewProps } from 'react-native';
|
|
3
|
+
import NativeSafeAreaView from './specs/NativeSafeAreaView';
|
|
7
4
|
|
|
8
5
|
export type Edge = 'top' | 'right' | 'bottom' | 'left';
|
|
6
|
+
export type EdgeMode = 'off' | 'additive' | 'maximum';
|
|
7
|
+
|
|
8
|
+
export type EdgeRecord = Partial<Record<Edge, EdgeMode>>;
|
|
9
|
+
export type Edges = readonly Edge[] | Readonly<EdgeRecord>;
|
|
9
10
|
|
|
10
11
|
export interface EdgeInsets {
|
|
11
12
|
top: number;
|
|
@@ -30,14 +31,17 @@ export type InsetChangedEvent = NativeSyntheticEvent<Metrics>;
|
|
|
30
31
|
|
|
31
32
|
export type InsetChangeNativeCallback = (event: InsetChangedEvent) => void;
|
|
32
33
|
|
|
33
|
-
export interface NativeSafeAreaProviderProps {
|
|
34
|
+
export interface NativeSafeAreaProviderProps extends ViewProps {
|
|
34
35
|
children?: React.ReactNode;
|
|
35
|
-
style?: StyleProp<ViewStyle>;
|
|
36
36
|
onInsetsChange: InsetChangeNativeCallback;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export
|
|
39
|
+
export interface NativeSafeAreaViewProps extends ViewProps {
|
|
40
40
|
children?: React.ReactNode;
|
|
41
41
|
mode?: 'padding' | 'margin';
|
|
42
|
-
edges?:
|
|
43
|
-
}
|
|
42
|
+
edges?: Edges;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type NativeSafeAreaViewInstance = InstanceType<
|
|
46
|
+
typeof NativeSafeAreaView
|
|
47
|
+
>;
|
package/src/SafeAreaContext.tsx
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Dimensions,
|
|
3
|
-
import NativeSafeAreaProvider from './NativeSafeAreaProvider';
|
|
4
|
-
import {
|
|
2
|
+
import { Dimensions, StyleSheet, type ViewProps } from 'react-native';
|
|
3
|
+
import { NativeSafeAreaProvider } from './NativeSafeAreaProvider';
|
|
4
|
+
import type {
|
|
5
|
+
EdgeInsets,
|
|
6
|
+
InsetChangedEvent,
|
|
7
|
+
Metrics,
|
|
8
|
+
Rect,
|
|
9
|
+
} from './SafeArea.types';
|
|
10
|
+
|
|
11
|
+
const isDev = process.env.NODE_ENV !== 'production';
|
|
5
12
|
|
|
6
13
|
export const SafeAreaInsetsContext = React.createContext<EdgeInsets | null>(
|
|
7
14
|
null,
|
|
8
15
|
);
|
|
9
|
-
|
|
16
|
+
if (isDev) {
|
|
17
|
+
SafeAreaInsetsContext.displayName = 'SafeAreaInsetsContext';
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
export const SafeAreaFrameContext = React.createContext<Rect | null>(null);
|
|
12
|
-
|
|
21
|
+
if (isDev) {
|
|
22
|
+
SafeAreaFrameContext.displayName = 'SafeAreaFrameContext';
|
|
23
|
+
}
|
|
13
24
|
|
|
14
|
-
export interface
|
|
25
|
+
export interface SafeAreaProviderProps extends ViewProps {
|
|
15
26
|
children?: React.ReactNode;
|
|
16
27
|
initialMetrics?: Metrics | null;
|
|
17
28
|
/**
|
|
18
29
|
* @deprecated
|
|
19
30
|
*/
|
|
20
31
|
initialSafeAreaInsets?: EdgeInsets | null;
|
|
21
|
-
style?: StyleProp<ViewStyle>;
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
export function SafeAreaProvider({
|
|
@@ -26,7 +36,8 @@ export function SafeAreaProvider({
|
|
|
26
36
|
initialMetrics,
|
|
27
37
|
initialSafeAreaInsets,
|
|
28
38
|
style,
|
|
29
|
-
|
|
39
|
+
...others
|
|
40
|
+
}: SafeAreaProviderProps) {
|
|
30
41
|
const parentInsets = useParentSafeAreaInsets();
|
|
31
42
|
const parentFrame = useParentSafeAreaFrame();
|
|
32
43
|
const [insets, setInsets] = React.useState<EdgeInsets | null>(
|
|
@@ -42,40 +53,46 @@ export function SafeAreaProvider({
|
|
|
42
53
|
height: Dimensions.get('window').height,
|
|
43
54
|
},
|
|
44
55
|
);
|
|
45
|
-
const onInsetsChange = React.useCallback(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} = event;
|
|
56
|
+
const onInsetsChange = React.useCallback((event: InsetChangedEvent) => {
|
|
57
|
+
const {
|
|
58
|
+
nativeEvent: { frame: nextFrame, insets: nextInsets },
|
|
59
|
+
} = event;
|
|
50
60
|
|
|
61
|
+
setFrame((curFrame) => {
|
|
51
62
|
if (
|
|
52
63
|
// Backwards compat with old native code that won't send frame.
|
|
53
64
|
nextFrame &&
|
|
54
|
-
(nextFrame.height !==
|
|
55
|
-
nextFrame.width !==
|
|
56
|
-
nextFrame.x !==
|
|
57
|
-
nextFrame.y !==
|
|
65
|
+
(nextFrame.height !== curFrame.height ||
|
|
66
|
+
nextFrame.width !== curFrame.width ||
|
|
67
|
+
nextFrame.x !== curFrame.x ||
|
|
68
|
+
nextFrame.y !== curFrame.y)
|
|
58
69
|
) {
|
|
59
|
-
|
|
70
|
+
return nextFrame;
|
|
71
|
+
} else {
|
|
72
|
+
return curFrame;
|
|
60
73
|
}
|
|
74
|
+
});
|
|
61
75
|
|
|
76
|
+
setInsets((curInsets) => {
|
|
62
77
|
if (
|
|
63
|
-
!
|
|
64
|
-
nextInsets.bottom !==
|
|
65
|
-
nextInsets.left !==
|
|
66
|
-
nextInsets.right !==
|
|
67
|
-
nextInsets.top !==
|
|
78
|
+
!curInsets ||
|
|
79
|
+
nextInsets.bottom !== curInsets.bottom ||
|
|
80
|
+
nextInsets.left !== curInsets.left ||
|
|
81
|
+
nextInsets.right !== curInsets.right ||
|
|
82
|
+
nextInsets.top !== curInsets.top
|
|
68
83
|
) {
|
|
69
|
-
|
|
84
|
+
return nextInsets;
|
|
85
|
+
} else {
|
|
86
|
+
return curInsets;
|
|
70
87
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
);
|
|
88
|
+
});
|
|
89
|
+
}, []);
|
|
74
90
|
|
|
75
91
|
return (
|
|
76
92
|
<NativeSafeAreaProvider
|
|
77
93
|
style={[styles.fill, style]}
|
|
78
94
|
onInsetsChange={onInsetsChange}
|
|
95
|
+
{...others}
|
|
79
96
|
>
|
|
80
97
|
{insets != null ? (
|
|
81
98
|
<SafeAreaFrameContext.Provider value={frame}>
|
|
@@ -100,34 +117,40 @@ function useParentSafeAreaFrame(): Rect | null {
|
|
|
100
117
|
return React.useContext(SafeAreaFrameContext);
|
|
101
118
|
}
|
|
102
119
|
|
|
120
|
+
const NO_INSETS_ERROR =
|
|
121
|
+
'No safe area value available. Make sure you are rendering `<SafeAreaProvider>` at the top of your app.';
|
|
122
|
+
|
|
103
123
|
export function useSafeAreaInsets(): EdgeInsets {
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
throw new Error(
|
|
107
|
-
'No safe area insets value available. Make sure you are rendering `<SafeAreaProvider>` at the top of your app.',
|
|
108
|
-
);
|
|
124
|
+
const insets = React.useContext(SafeAreaInsetsContext);
|
|
125
|
+
if (insets == null) {
|
|
126
|
+
throw new Error(NO_INSETS_ERROR);
|
|
109
127
|
}
|
|
110
|
-
return
|
|
128
|
+
return insets;
|
|
111
129
|
}
|
|
112
130
|
|
|
113
131
|
export function useSafeAreaFrame(): Rect {
|
|
114
132
|
const frame = React.useContext(SafeAreaFrameContext);
|
|
115
133
|
if (frame == null) {
|
|
116
|
-
throw new Error(
|
|
117
|
-
'No safe area frame value available. Make sure you are rendering `<SafeAreaProvider>` at the top of your app.',
|
|
118
|
-
);
|
|
134
|
+
throw new Error(NO_INSETS_ERROR);
|
|
119
135
|
}
|
|
120
136
|
return frame;
|
|
121
137
|
}
|
|
122
138
|
|
|
139
|
+
export type WithSafeAreaInsetsProps = {
|
|
140
|
+
insets: EdgeInsets;
|
|
141
|
+
};
|
|
142
|
+
|
|
123
143
|
export function withSafeAreaInsets<T>(
|
|
124
|
-
WrappedComponent: React.ComponentType<
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
144
|
+
WrappedComponent: React.ComponentType<
|
|
145
|
+
(React.PropsWithoutRef<T> | T) & WithSafeAreaInsetsProps
|
|
146
|
+
>,
|
|
147
|
+
): React.ForwardRefExoticComponent<
|
|
148
|
+
React.PropsWithoutRef<T> & React.RefAttributes<unknown>
|
|
149
|
+
> {
|
|
150
|
+
return React.forwardRef<unknown, T>((props, ref) => {
|
|
151
|
+
const insets = useSafeAreaInsets();
|
|
152
|
+
return <WrappedComponent {...props} insets={insets} ref={ref} />;
|
|
153
|
+
});
|
|
131
154
|
}
|
|
132
155
|
|
|
133
156
|
/**
|
package/src/SafeAreaView.tsx
CHANGED
|
@@ -1,85 +1,50 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
right: RIGHT,
|
|
18
|
-
bottom: BOTTOM,
|
|
19
|
-
left: LEFT,
|
|
2
|
+
import type {
|
|
3
|
+
Edge,
|
|
4
|
+
EdgeMode,
|
|
5
|
+
EdgeRecord,
|
|
6
|
+
NativeSafeAreaViewInstance,
|
|
7
|
+
NativeSafeAreaViewProps,
|
|
8
|
+
} from './SafeArea.types';
|
|
9
|
+
import NativeSafeAreaView from './specs/NativeSafeAreaView';
|
|
10
|
+
import { useMemo } from 'react';
|
|
11
|
+
|
|
12
|
+
const defaultEdges: Record<Edge, EdgeMode> = {
|
|
13
|
+
top: 'additive',
|
|
14
|
+
left: 'additive',
|
|
15
|
+
bottom: 'additive',
|
|
16
|
+
right: 'additive',
|
|
20
17
|
};
|
|
21
18
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const marginStyle = {
|
|
55
|
-
marginTop: marginTop + insetTop,
|
|
56
|
-
marginRight: marginRight + insetRight,
|
|
57
|
-
marginBottom: marginBottom + insetBottom,
|
|
58
|
-
marginLeft: marginLeft + insetLeft,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return [style, marginStyle];
|
|
62
|
-
} else {
|
|
63
|
-
const {
|
|
64
|
-
padding = 0,
|
|
65
|
-
paddingVertical = padding,
|
|
66
|
-
paddingHorizontal = padding,
|
|
67
|
-
paddingTop = paddingVertical,
|
|
68
|
-
paddingRight = paddingHorizontal,
|
|
69
|
-
paddingBottom = paddingVertical,
|
|
70
|
-
paddingLeft = paddingHorizontal,
|
|
71
|
-
} = flatStyle;
|
|
72
|
-
|
|
73
|
-
const paddingStyle = {
|
|
74
|
-
paddingTop: paddingTop + insetTop,
|
|
75
|
-
paddingRight: paddingRight + insetRight,
|
|
76
|
-
paddingBottom: paddingBottom + insetBottom,
|
|
77
|
-
paddingLeft: paddingLeft + insetLeft,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return [style, paddingStyle];
|
|
81
|
-
}
|
|
82
|
-
}, [style, insets, mode, edgeBitmask]);
|
|
83
|
-
|
|
84
|
-
return <View style={appliedStyle} {...rest} />;
|
|
85
|
-
}
|
|
19
|
+
export type SafeAreaViewProps = NativeSafeAreaViewProps;
|
|
20
|
+
|
|
21
|
+
export const SafeAreaView = React.forwardRef<
|
|
22
|
+
NativeSafeAreaViewInstance,
|
|
23
|
+
SafeAreaViewProps
|
|
24
|
+
>(({ edges, ...props }, ref) => {
|
|
25
|
+
const nativeEdges = useMemo(() => {
|
|
26
|
+
if (edges == null) {
|
|
27
|
+
return defaultEdges;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const edgesObj = Array.isArray(edges)
|
|
31
|
+
? edges.reduce<EdgeRecord>((acc, edge: Edge) => {
|
|
32
|
+
acc[edge] = 'additive';
|
|
33
|
+
return acc;
|
|
34
|
+
}, {})
|
|
35
|
+
: // ts has trouble with refining readonly arrays.
|
|
36
|
+
(edges as EdgeRecord);
|
|
37
|
+
|
|
38
|
+
// make sure that we always pass all edges, required for fabric
|
|
39
|
+
const requiredEdges: Record<Edge, EdgeMode> = {
|
|
40
|
+
top: edgesObj.top ?? 'off',
|
|
41
|
+
right: edgesObj.right ?? 'off',
|
|
42
|
+
bottom: edgesObj.bottom ?? 'off',
|
|
43
|
+
left: edgesObj.left ?? 'off',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return requiredEdges;
|
|
47
|
+
}, [edges]);
|
|
48
|
+
|
|
49
|
+
return <NativeSafeAreaView {...props} edges={nativeEdges} ref={ref} />;
|
|
50
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
Edge,
|
|
5
|
+
EdgeMode,
|
|
6
|
+
EdgeRecord,
|
|
7
|
+
NativeSafeAreaViewInstance,
|
|
8
|
+
NativeSafeAreaViewProps,
|
|
9
|
+
} from './SafeArea.types';
|
|
10
|
+
import { useSafeAreaInsets } from './SafeAreaContext';
|
|
11
|
+
|
|
12
|
+
const defaultEdges: Record<Edge, EdgeMode> = {
|
|
13
|
+
top: 'additive',
|
|
14
|
+
left: 'additive',
|
|
15
|
+
bottom: 'additive',
|
|
16
|
+
right: 'additive',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function getEdgeValue(
|
|
20
|
+
inset: number,
|
|
21
|
+
current: number,
|
|
22
|
+
mode: EdgeMode | undefined,
|
|
23
|
+
) {
|
|
24
|
+
switch (mode) {
|
|
25
|
+
case 'off':
|
|
26
|
+
return current;
|
|
27
|
+
case 'maximum':
|
|
28
|
+
return Math.max(current, inset);
|
|
29
|
+
case 'additive':
|
|
30
|
+
default:
|
|
31
|
+
return current + inset;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const SafeAreaView = React.forwardRef<
|
|
36
|
+
NativeSafeAreaViewInstance,
|
|
37
|
+
NativeSafeAreaViewProps
|
|
38
|
+
>(({ style = {}, mode, edges, ...rest }, ref) => {
|
|
39
|
+
const insets = useSafeAreaInsets();
|
|
40
|
+
|
|
41
|
+
const edgesRecord = React.useMemo(() => {
|
|
42
|
+
if (edges == null) {
|
|
43
|
+
return defaultEdges;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return Array.isArray(edges)
|
|
47
|
+
? edges.reduce<EdgeRecord>((acc, edge: Edge) => {
|
|
48
|
+
acc[edge] = 'additive';
|
|
49
|
+
return acc;
|
|
50
|
+
}, {})
|
|
51
|
+
: // ts has trouble with refining readonly arrays.
|
|
52
|
+
(edges as EdgeRecord);
|
|
53
|
+
}, [edges]);
|
|
54
|
+
|
|
55
|
+
const appliedStyle = React.useMemo(() => {
|
|
56
|
+
const flatStyle = StyleSheet.flatten(style) as Record<string, number>;
|
|
57
|
+
|
|
58
|
+
if (mode === 'margin') {
|
|
59
|
+
const {
|
|
60
|
+
margin = 0,
|
|
61
|
+
marginVertical = margin,
|
|
62
|
+
marginHorizontal = margin,
|
|
63
|
+
marginTop = marginVertical,
|
|
64
|
+
marginRight = marginHorizontal,
|
|
65
|
+
marginBottom = marginVertical,
|
|
66
|
+
marginLeft = marginHorizontal,
|
|
67
|
+
} = flatStyle;
|
|
68
|
+
|
|
69
|
+
const marginStyle = {
|
|
70
|
+
marginTop: getEdgeValue(insets.top, marginTop, edgesRecord.top),
|
|
71
|
+
marginRight: getEdgeValue(insets.right, marginRight, edgesRecord.right),
|
|
72
|
+
marginBottom: getEdgeValue(
|
|
73
|
+
insets.bottom,
|
|
74
|
+
marginBottom,
|
|
75
|
+
edgesRecord.bottom,
|
|
76
|
+
),
|
|
77
|
+
marginLeft: getEdgeValue(insets.left, marginLeft, edgesRecord.left),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return [style, marginStyle];
|
|
81
|
+
} else {
|
|
82
|
+
const {
|
|
83
|
+
padding = 0,
|
|
84
|
+
paddingVertical = padding,
|
|
85
|
+
paddingHorizontal = padding,
|
|
86
|
+
paddingTop = paddingVertical,
|
|
87
|
+
paddingRight = paddingHorizontal,
|
|
88
|
+
paddingBottom = paddingVertical,
|
|
89
|
+
paddingLeft = paddingHorizontal,
|
|
90
|
+
} = flatStyle;
|
|
91
|
+
|
|
92
|
+
const paddingStyle = {
|
|
93
|
+
paddingTop: getEdgeValue(insets.top, paddingTop, edgesRecord.top),
|
|
94
|
+
paddingRight: getEdgeValue(
|
|
95
|
+
insets.right,
|
|
96
|
+
paddingRight,
|
|
97
|
+
edgesRecord.right,
|
|
98
|
+
),
|
|
99
|
+
paddingBottom: getEdgeValue(
|
|
100
|
+
insets.bottom,
|
|
101
|
+
paddingBottom,
|
|
102
|
+
edgesRecord.bottom,
|
|
103
|
+
),
|
|
104
|
+
paddingLeft: getEdgeValue(insets.left, paddingLeft, edgesRecord.left),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return [style, paddingStyle];
|
|
108
|
+
}
|
|
109
|
+
}, [
|
|
110
|
+
edgesRecord.bottom,
|
|
111
|
+
edgesRecord.left,
|
|
112
|
+
edgesRecord.right,
|
|
113
|
+
edgesRecord.top,
|
|
114
|
+
insets.bottom,
|
|
115
|
+
insets.left,
|
|
116
|
+
insets.right,
|
|
117
|
+
insets.top,
|
|
118
|
+
mode,
|
|
119
|
+
style,
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
return <View style={appliedStyle} {...rest} ref={ref} />;
|
|
123
|
+
});
|
package/src/index.tsx
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TurboModule, TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import type { Double } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
getConstants: () => {
|
|
6
|
+
initialWindowMetrics?: {
|
|
7
|
+
insets: {
|
|
8
|
+
top: Double;
|
|
9
|
+
right: Double;
|
|
10
|
+
bottom: Double;
|
|
11
|
+
left: Double;
|
|
12
|
+
};
|
|
13
|
+
frame: {
|
|
14
|
+
x: Double;
|
|
15
|
+
y: Double;
|
|
16
|
+
width: Double;
|
|
17
|
+
height: Double;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default TurboModuleRegistry.get<Spec>('RNCSafeAreaContext');
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DirectEventHandler,
|
|
3
|
+
Double,
|
|
4
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
5
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
6
|
+
import type { ViewProps, HostComponent } from 'react-native';
|
|
7
|
+
|
|
8
|
+
export type Event = Readonly<{
|
|
9
|
+
insets: Readonly<{
|
|
10
|
+
top: Double;
|
|
11
|
+
right: Double;
|
|
12
|
+
bottom: Double;
|
|
13
|
+
left: Double;
|
|
14
|
+
}>;
|
|
15
|
+
frame: Readonly<{
|
|
16
|
+
x: Double;
|
|
17
|
+
y: Double;
|
|
18
|
+
width: Double;
|
|
19
|
+
height: Double;
|
|
20
|
+
}>;
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
export interface NativeProps extends ViewProps {
|
|
24
|
+
onInsetsChange?: DirectEventHandler<Event>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default codegenNativeComponent<NativeProps>(
|
|
28
|
+
'RNCSafeAreaProvider',
|
|
29
|
+
) as HostComponent<NativeProps>;
|