@react-native-ohos/react-native-safe-area-context 4.7.5-rc.1
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/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +11 -0
- package/harmony/safe_area/LICENSE +21 -0
- package/harmony/safe_area/NOTICE +33 -0
- package/harmony/safe_area/build-profile.json5 +9 -0
- package/harmony/safe_area/hvigorfile.ts +6 -0
- package/harmony/safe_area/index.ets +28 -0
- package/harmony/safe_area/oh-package.json5 +15 -0
- package/harmony/safe_area/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaBeanData.h +55 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.cpp +46 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.h +39 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.cpp +65 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.h +42 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.cpp +81 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.h +47 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.cpp +78 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.h +29 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.cpp +103 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.h +58 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaViewPackage.h +60 -0
- package/harmony/safe_area/src/main/cpp/TurboModuleRequest.cpp +63 -0
- package/harmony/safe_area/src/main/cpp/TurboModuleRequest.h +32 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/BaseReactNativeSafeAreaContextPackage.h +75 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaProviderComponentInstance.h +19 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaViewComponentInstance.h +19 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaProviderJSIBinder.h +28 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaViewJSIBinder.h +33 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.cpp +17 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.h +15 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ComponentDescriptors.h +21 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.cpp +57 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.h +62 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.cpp +33 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.h +99 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.cpp +18 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.h +29 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.cpp +15 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.h +20 -0
- package/harmony/safe_area/src/main/ets/Logger.ts +64 -0
- package/harmony/safe_area/src/main/ets/SafeAreaProvider.ets +128 -0
- package/harmony/safe_area/src/main/ets/SafeAreaProviderModifier.ets +121 -0
- package/harmony/safe_area/src/main/ets/SafeAreaView.ets +242 -0
- package/harmony/safe_area/src/main/ets/SafeAreaViewModifier.ets +140 -0
- package/harmony/safe_area/src/main/ets/SafeAreaViewPackage.ets +47 -0
- package/harmony/safe_area/src/main/ets/SafeViewTurboModule.ts +131 -0
- package/harmony/safe_area/src/main/ets/common/SafeAreaType.ts +70 -0
- package/harmony/safe_area/src/main/module.json5 +7 -0
- package/harmony/safe_area/src/main/resources/base/element/string.json +8 -0
- package/harmony/safe_area/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/safe_area/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/safe_area/ts.ets +26 -0
- package/harmony/safe_area.har +0 -0
- package/package.json +139 -0
- package/src/SafeArea.types.ts +47 -0
- package/src/SafeAreaView.tsx +201 -0
- package/src/index.tsx +4 -0
- package/src/specs/NativeSafeAreaContext.ts +23 -0
- package/src/specs/NativeSafeAreaProvider.ts +29 -0
- package/src/specs/NativeSafeAreaView.ts +28 -0
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-ohos/react-native-safe-area-context",
|
|
3
|
+
"version": "4.7.5-rc.1",
|
|
4
|
+
"description": "A flexible way to handle safe area, also works on Android and web.",
|
|
5
|
+
"main": "lib/commonjs/index.js",
|
|
6
|
+
"module": "lib/module/index.js",
|
|
7
|
+
"react-native": "src/index.tsx",
|
|
8
|
+
"types": "lib/typescript/index.d.ts",
|
|
9
|
+
"harmony": {
|
|
10
|
+
"alias": "react-native-safe-area-context",
|
|
11
|
+
"autolinking": {
|
|
12
|
+
"etsPackageClassName":"SafeAreaViewPackage",
|
|
13
|
+
"cppPackageClassName":"SafeAreaViewPackage",
|
|
14
|
+
"cmakeLibraryTargetName": "rnoh_safe_area",
|
|
15
|
+
"ohPackageName": "@react-native-ohos/react-native-safe-area-context"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"registry": "https://registry.npmjs.org/",
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"source": "src/index.tsx",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"lib",
|
|
27
|
+
"jest",
|
|
28
|
+
"*.podspec",
|
|
29
|
+
"react-native.config.js",
|
|
30
|
+
"!**/__tests__",
|
|
31
|
+
"!example",
|
|
32
|
+
"harmony"
|
|
33
|
+
],
|
|
34
|
+
"homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-safe-area-context#readme",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"start": "react-native start",
|
|
38
|
+
"test": "yarn format:check && yarn validate:eslint && yarn validate:typescript && yarn validate:jest",
|
|
39
|
+
"validate:eslint": "eslint \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\"",
|
|
40
|
+
"validate:typescript": "tsc --project ./ --noEmit",
|
|
41
|
+
"validate:jest": "jest",
|
|
42
|
+
"format:prettier:check": "prettier \"src/**/*.{js,ts,tsx}\" \"example/**/*.{js,ts,tsx}\" --check",
|
|
43
|
+
"format:prettier:write": "yarn format:prettier:check --write",
|
|
44
|
+
"format:clang:check": "clang-format --dry-run --Werror --glob='{ios,android,common}/**/*.{h,cpp,m,mm}'",
|
|
45
|
+
"format:clang:write": "clang-format -i --glob='{ios,android,common}/**/*.{h,hpp,cpp,m,mm}'",
|
|
46
|
+
"format:spotless:check": "cd android && ./gradlew spotlessCheck",
|
|
47
|
+
"format:spotless:write": "cd android && ./gradlew spotlessApply",
|
|
48
|
+
"format:check": "yarn format:prettier:check && yarn format:clang:check && yarn format:spotless:check",
|
|
49
|
+
"format:write": "yarn format:prettier:write && yarn format:clang:write && yarn format:spotless:write",
|
|
50
|
+
"release": "release-it"
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"react-native",
|
|
54
|
+
"react native",
|
|
55
|
+
"react-native-web",
|
|
56
|
+
"expo-web",
|
|
57
|
+
"safe area",
|
|
58
|
+
"view"
|
|
59
|
+
],
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"react": "*",
|
|
62
|
+
"react-native": "*"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@commitlint/config-conventional": "^17.6.1",
|
|
66
|
+
"@react-native-community/eslint-config": "^3.2.0",
|
|
67
|
+
"@react-native/eslint-plugin-specs": "^0.73.0",
|
|
68
|
+
"@release-it/conventional-changelog": "^5.1.1",
|
|
69
|
+
"@types/jest": "^29.5.1",
|
|
70
|
+
"@types/react": "^18.2.0",
|
|
71
|
+
"@types/react-dom": "^18.2.1",
|
|
72
|
+
"@types/react-test-renderer": "^18.0.0",
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^5.59.1",
|
|
74
|
+
"@typescript-eslint/parser": "^5.59.1",
|
|
75
|
+
"babel-plugin-module-resolver": "^5.0.0",
|
|
76
|
+
"clang-format": "^1.8.0",
|
|
77
|
+
"commitlint": "^17.6.1",
|
|
78
|
+
"eslint": "^8.39.0",
|
|
79
|
+
"eslint-config-prettier": "^8.8.0",
|
|
80
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
81
|
+
"husky": "^8.0.3",
|
|
82
|
+
"jest": "^29.5.0",
|
|
83
|
+
"metro-react-native-babel-preset": "0.76.5",
|
|
84
|
+
"prettier": "^2.8.8",
|
|
85
|
+
"react": "^18.2.0",
|
|
86
|
+
"react-dom": "^18.2.0",
|
|
87
|
+
"react-native": "0.72.1",
|
|
88
|
+
"react-native-builder-bob": "^0.20.4",
|
|
89
|
+
"react-test-renderer": "^18.2.0",
|
|
90
|
+
"release-it": "^15.10.1",
|
|
91
|
+
"typescript": "^5.0.4"
|
|
92
|
+
},
|
|
93
|
+
"dependencies": {
|
|
94
|
+
"react-native-safe-area-context": "4.7.4"
|
|
95
|
+
},
|
|
96
|
+
"repository": {
|
|
97
|
+
"type": "git",
|
|
98
|
+
"url": "https://gitcode.com/openharmony-sig/rntpc_react-native-safe-area-context.git"
|
|
99
|
+
},
|
|
100
|
+
"jest": {
|
|
101
|
+
"preset": "react-native",
|
|
102
|
+
"testEnvironment": "node",
|
|
103
|
+
"clearMocks": true,
|
|
104
|
+
"modulePathIgnorePatterns": [
|
|
105
|
+
"<rootDir>/lib/"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"commitlint": {
|
|
109
|
+
"extends": [
|
|
110
|
+
"@commitlint/config-conventional"
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"release-it": {
|
|
114
|
+
"git": {
|
|
115
|
+
"commitMessage": "chore: release ${version}",
|
|
116
|
+
"tagName": "v${version}"
|
|
117
|
+
},
|
|
118
|
+
"npm": {
|
|
119
|
+
"publish": true
|
|
120
|
+
},
|
|
121
|
+
"github": {
|
|
122
|
+
"release": true
|
|
123
|
+
},
|
|
124
|
+
"plugins": {
|
|
125
|
+
"@release-it/conventional-changelog": {
|
|
126
|
+
"preset": "angular"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"react-native-builder-bob": {
|
|
131
|
+
"source": "src",
|
|
132
|
+
"output": "lib",
|
|
133
|
+
"targets": [
|
|
134
|
+
"commonjs",
|
|
135
|
+
"module",
|
|
136
|
+
"typescript"
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { NativeSyntheticEvent, ViewProps } from 'react-native';
|
|
3
|
+
import NativeSafeAreaView from './specs/NativeSafeAreaView';
|
|
4
|
+
|
|
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>;
|
|
10
|
+
|
|
11
|
+
export interface EdgeInsets {
|
|
12
|
+
top: number;
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
left: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Rect {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Metrics {
|
|
26
|
+
insets: EdgeInsets;
|
|
27
|
+
frame: Rect;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type InsetChangedEvent = NativeSyntheticEvent<Metrics>;
|
|
31
|
+
|
|
32
|
+
export type InsetChangeNativeCallback = (event: InsetChangedEvent) => void;
|
|
33
|
+
|
|
34
|
+
export interface NativeSafeAreaProviderProps extends ViewProps {
|
|
35
|
+
children?: React.ReactNode;
|
|
36
|
+
onInsetsChange: InsetChangeNativeCallback;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface NativeSafeAreaViewProps extends ViewProps {
|
|
40
|
+
children?: React.ReactNode;
|
|
41
|
+
mode?: 'padding' | 'margin';
|
|
42
|
+
edges?: Edges;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type NativeSafeAreaViewInstance = InstanceType<
|
|
46
|
+
typeof NativeSafeAreaView
|
|
47
|
+
>;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
Edge,
|
|
4
|
+
EdgeMode,
|
|
5
|
+
EdgeRecord,
|
|
6
|
+
NativeSafeAreaViewInstance,
|
|
7
|
+
NativeSafeAreaViewProps,
|
|
8
|
+
} from './SafeArea.types';
|
|
9
|
+
import NativeSafeAreaView, { onSafeAreaValueChangeEvent } from './specs/NativeSafeAreaView';
|
|
10
|
+
import type * as ReactNative from "react-native";
|
|
11
|
+
import { useMemo, useState } from 'react';
|
|
12
|
+
|
|
13
|
+
const defaultEdges: Record<Edge, EdgeMode> = {
|
|
14
|
+
top: 'additive',
|
|
15
|
+
left: 'additive',
|
|
16
|
+
bottom: 'additive',
|
|
17
|
+
right: 'additive',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type SafeAreaViewProps = NativeSafeAreaViewProps;
|
|
21
|
+
|
|
22
|
+
let isOnChange = false;
|
|
23
|
+
let realTop = 0;
|
|
24
|
+
let realLeft = 0;
|
|
25
|
+
let realBottom = 0;
|
|
26
|
+
let realRight = 0;
|
|
27
|
+
let safeAreaTop = 0;
|
|
28
|
+
let safeAreaLeft = 0;
|
|
29
|
+
let safeAreaBottom = 0;
|
|
30
|
+
let safeAreaRight = 0;
|
|
31
|
+
|
|
32
|
+
function getEdgeValue(edgeMode: string, insetValue: number, edgeValue: number) {
|
|
33
|
+
if (edgeMode === 'off') {
|
|
34
|
+
return edgeValue;
|
|
35
|
+
} else if (edgeMode === 'maximum') {
|
|
36
|
+
return Math.max(insetValue, edgeValue);
|
|
37
|
+
} else {
|
|
38
|
+
return insetValue + edgeValue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const SafeAreaView = React.forwardRef<
|
|
43
|
+
NativeSafeAreaViewInstance,
|
|
44
|
+
SafeAreaViewProps
|
|
45
|
+
>(({ edges, ...props }, ref) => {
|
|
46
|
+
const nativeEdges = useMemo(() => {
|
|
47
|
+
if (edges == null) {
|
|
48
|
+
return defaultEdges;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const edgesObj = Array.isArray(edges)
|
|
52
|
+
? edges.reduce<EdgeRecord>((acc, edge: Edge) => {
|
|
53
|
+
acc[edge] = 'additive';
|
|
54
|
+
return acc;
|
|
55
|
+
}, {})
|
|
56
|
+
: // ts has trouble with refining readonly arrays.
|
|
57
|
+
(edges as EdgeRecord);
|
|
58
|
+
|
|
59
|
+
// make sure that we always pass all edges, required for fabric
|
|
60
|
+
const requiredEdges: Record<Edge, EdgeMode> = {
|
|
61
|
+
top: edgesObj.top ?? 'off',
|
|
62
|
+
right: edgesObj.right ?? 'off',
|
|
63
|
+
bottom: edgesObj.bottom ?? 'off',
|
|
64
|
+
left: edgesObj.left ?? 'off',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return requiredEdges;
|
|
68
|
+
}, [edges]);
|
|
69
|
+
|
|
70
|
+
const [isFirstRefresh, setIsFirstRefresh] = useState(
|
|
71
|
+
false
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
let safeAreaStyle = [props.style]
|
|
75
|
+
let rawPadding = 0;
|
|
76
|
+
let rawMargin = 0;
|
|
77
|
+
let rawPaddingTop: number | undefined = undefined;
|
|
78
|
+
let rawPaddingLeft: number | undefined = undefined;
|
|
79
|
+
let rawPaddingBottom: number | undefined = undefined;
|
|
80
|
+
let rawPaddingRight: number | undefined = undefined;
|
|
81
|
+
let rawMarginTop: number | undefined = undefined;
|
|
82
|
+
let rawMarginLeft: number | undefined = undefined;
|
|
83
|
+
let rawMarginBottom: number | undefined = undefined;
|
|
84
|
+
let rawMarginRight: number | undefined = undefined;
|
|
85
|
+
|
|
86
|
+
const safeAreaChange = (e: ReactNative.NativeSyntheticEvent<onSafeAreaValueChangeEvent>) => {
|
|
87
|
+
if (e.nativeEvent.safeAreaViewInsetsValue?.top) {
|
|
88
|
+
safeAreaTop = e.nativeEvent.safeAreaViewInsetsValue?.top;
|
|
89
|
+
}
|
|
90
|
+
if (e.nativeEvent.safeAreaViewInsetsValue?.right) {
|
|
91
|
+
safeAreaRight = e.nativeEvent.safeAreaViewInsetsValue?.right;
|
|
92
|
+
}
|
|
93
|
+
if (e.nativeEvent.safeAreaViewInsetsValue?.bottom) {
|
|
94
|
+
safeAreaBottom = e.nativeEvent.safeAreaViewInsetsValue?.bottom;
|
|
95
|
+
}
|
|
96
|
+
if (e.nativeEvent.safeAreaViewInsetsValue?.left) {
|
|
97
|
+
safeAreaLeft = e.nativeEvent.safeAreaViewInsetsValue?.left;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!isOnChange) {
|
|
101
|
+
setIsFirstRefresh(true);
|
|
102
|
+
}
|
|
103
|
+
isOnChange = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let rawProp = props.style as ReactNative.ViewStyle[];
|
|
107
|
+
let i: number;
|
|
108
|
+
if (rawProp && rawProp.length > 0) {
|
|
109
|
+
for (i = 0; i < rawProp.length; i++) {
|
|
110
|
+
if (rawProp[i]?.padding) {
|
|
111
|
+
rawPadding = rawProp[i]?.padding as number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (rawProp[i]?.margin) {
|
|
115
|
+
rawMargin = rawProp[i]?.margin as number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (rawProp[i]?.paddingTop) {
|
|
119
|
+
rawPaddingTop = rawProp[i]?.paddingTop as number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (rawProp[i]?.paddingLeft) {
|
|
123
|
+
rawPaddingLeft = rawProp[i]?.paddingLeft as number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (rawProp[i]?.paddingRight) {
|
|
127
|
+
rawPaddingRight = rawProp[i]?.paddingRight as number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (rawProp[i]?.paddingBottom) {
|
|
131
|
+
rawPaddingBottom = rawProp[i]?.paddingBottom as number;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (rawProp[i]?.marginTop) {
|
|
135
|
+
rawMarginTop = rawProp[i]?.marginTop as number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (rawProp[i]?.marginLeft) {
|
|
139
|
+
rawMarginLeft = rawProp[i]?.marginLeft as number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (rawProp[i]?.marginRight) {
|
|
143
|
+
rawMarginRight = rawProp[i]?.marginRight as number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (rawProp[i]?.marginBottom) {
|
|
147
|
+
rawMarginBottom = rawProp[i]?.marginBottom as number;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (!rawPaddingTop) {
|
|
153
|
+
rawPaddingTop = rawPadding;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!rawPaddingLeft) {
|
|
157
|
+
rawPaddingLeft = rawPadding;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!rawPaddingRight) {
|
|
161
|
+
rawPaddingRight = rawPadding;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!rawPaddingBottom) {
|
|
165
|
+
rawPaddingBottom = rawPadding;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!rawMarginTop) {
|
|
169
|
+
rawMarginTop = rawMargin;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!rawMarginLeft) {
|
|
173
|
+
rawMarginLeft = rawMargin;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (!rawMarginRight) {
|
|
177
|
+
rawMarginRight = rawMargin;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!rawMarginBottom) {
|
|
181
|
+
rawMarginBottom = rawMargin;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (isOnChange) {
|
|
185
|
+
if (props.mode === 'margin') {
|
|
186
|
+
realTop = getEdgeValue(nativeEdges.top, safeAreaTop, rawMarginTop)
|
|
187
|
+
realLeft = getEdgeValue(nativeEdges.left, safeAreaLeft, rawMarginLeft)
|
|
188
|
+
realBottom = getEdgeValue(nativeEdges.bottom, safeAreaBottom, rawMarginBottom)
|
|
189
|
+
realRight = getEdgeValue(nativeEdges.right, safeAreaRight, rawMarginRight)
|
|
190
|
+
safeAreaStyle = [props.style, { marginTop: realTop, marginLeft: realLeft, marginBottom: realBottom, marginRight: realRight }]
|
|
191
|
+
} else {
|
|
192
|
+
realTop = getEdgeValue(nativeEdges.top, safeAreaTop, rawPaddingTop)
|
|
193
|
+
realLeft = getEdgeValue(nativeEdges.left, safeAreaLeft, rawPaddingLeft)
|
|
194
|
+
realBottom = getEdgeValue(nativeEdges.bottom, safeAreaBottom, rawPaddingBottom)
|
|
195
|
+
realRight = getEdgeValue(nativeEdges.right, safeAreaRight, rawPaddingRight)
|
|
196
|
+
safeAreaStyle = [props.style, { paddingTop: realTop, paddingLeft: realLeft, paddingBottom: realBottom, paddingRight: realRight }]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return <NativeSafeAreaView {...props} style={safeAreaStyle} edges={nativeEdges} isFirstRefresh={isFirstRefresh} onSafeAreaValueChange={safeAreaChange} ref={ref} />;
|
|
201
|
+
});
|
package/src/index.tsx
ADDED
|
@@ -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, 'paperInsetsChange'>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default codegenNativeComponent<NativeProps>(
|
|
28
|
+
'RNCSafeAreaProvider',
|
|
29
|
+
) as HostComponent<NativeProps>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
2
|
+
import type { WithDefault, Float, DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
import type { ViewProps, HostComponent } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export type onSafeAreaValueChangeEvent = Readonly<{
|
|
6
|
+
safeAreaViewInsetsValue?: {
|
|
7
|
+
top?: Float;
|
|
8
|
+
left?: Float;
|
|
9
|
+
bottom?: Float
|
|
10
|
+
right?: Float
|
|
11
|
+
};
|
|
12
|
+
}>
|
|
13
|
+
|
|
14
|
+
export interface NativeProps extends ViewProps {
|
|
15
|
+
mode?: WithDefault<'padding' | 'margin', 'padding'>;
|
|
16
|
+
edges?: Readonly<{
|
|
17
|
+
top: string;
|
|
18
|
+
right: string;
|
|
19
|
+
bottom: string;
|
|
20
|
+
left: string;
|
|
21
|
+
}>;
|
|
22
|
+
isFirstRefresh: boolean;
|
|
23
|
+
onSafeAreaValueChange: DirectEventHandler<onSafeAreaValueChangeEvent>,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default codegenNativeComponent<NativeProps>('RNCSafeAreaView', {
|
|
27
|
+
interfaceOnly: true,
|
|
28
|
+
}) as HostComponent<NativeProps>;
|