@react-native-ohos/react-native-safe-area-context 5.1.1-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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +10 -0
  4. package/harmony/safe_area/LICENSE +21 -0
  5. package/harmony/safe_area/NOTICE +33 -0
  6. package/harmony/safe_area/README.md +270 -0
  7. package/harmony/safe_area/build-profile.json5 +9 -0
  8. package/harmony/safe_area/hvigorfile.ts +6 -0
  9. package/harmony/safe_area/index.ets +26 -0
  10. package/harmony/safe_area/oh-package.json5 +22 -0
  11. package/harmony/safe_area/src/main/cpp/CMakeLists.txt +9 -0
  12. package/harmony/safe_area/src/main/cpp/SafeAreaBeanData.h +56 -0
  13. package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.cpp +45 -0
  14. package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.h +38 -0
  15. package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.cpp +66 -0
  16. package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.h +57 -0
  17. package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.cpp +75 -0
  18. package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.h +49 -0
  19. package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.cpp +94 -0
  20. package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.h +53 -0
  21. package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.cpp +94 -0
  22. package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.h +64 -0
  23. package/harmony/safe_area/src/main/cpp/SafeAreaViewPackage.h +60 -0
  24. package/harmony/safe_area/src/main/cpp/TurboModuleRequest.cpp +63 -0
  25. package/harmony/safe_area/src/main/cpp/TurboModuleRequest.h +33 -0
  26. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/BaseReactNativeSafeAreaContextPackage.h +72 -0
  27. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaProviderComponentInstance.h +18 -0
  28. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaViewComponentInstance.h +18 -0
  29. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaProviderJSIBinder.h +27 -0
  30. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaViewJSIBinder.h +30 -0
  31. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.cpp +16 -0
  32. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.h +16 -0
  33. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ComponentDescriptors.h +25 -0
  34. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.cpp +56 -0
  35. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.h +59 -0
  36. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.cpp +36 -0
  37. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.h +88 -0
  38. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.cpp +20 -0
  39. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.h +39 -0
  40. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.cpp +18 -0
  41. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.h +23 -0
  42. package/harmony/safe_area/src/main/ets/Logger.ts +64 -0
  43. package/harmony/safe_area/src/main/ets/SafeAreaProvider.ets +128 -0
  44. package/harmony/safe_area/src/main/ets/SafeAreaProviderModifier.ets +121 -0
  45. package/harmony/safe_area/src/main/ets/SafeAreaView.ets +242 -0
  46. package/harmony/safe_area/src/main/ets/SafeAreaViewModifier.ets +140 -0
  47. package/harmony/safe_area/src/main/ets/SafeAreaViewPackage.ts +46 -0
  48. package/harmony/safe_area/src/main/ets/SafeViewTurboModule.ts +131 -0
  49. package/harmony/safe_area/src/main/ets/common/SafeAreaType.ts +70 -0
  50. package/harmony/safe_area/src/main/module.json5 +7 -0
  51. package/harmony/safe_area/src/main/resources/base/element/string.json +8 -0
  52. package/harmony/safe_area/src/main/resources/en_US/element/string.json +8 -0
  53. package/harmony/safe_area/src/main/resources/zh_CN/element/string.json +8 -0
  54. package/harmony/safe_area/ts.ts +26 -0
  55. package/harmony/safe_area.har +0 -0
  56. package/lib/commonjs/SafeArea.types.js +6 -0
  57. package/lib/commonjs/SafeArea.types.js.map +1 -0
  58. package/lib/commonjs/SafeAreaView.js +184 -0
  59. package/lib/commonjs/SafeAreaView.js.map +1 -0
  60. package/lib/commonjs/index.js +51 -0
  61. package/lib/commonjs/index.js.map +1 -0
  62. package/lib/commonjs/specs/NativeSafeAreaContext.js +9 -0
  63. package/lib/commonjs/specs/NativeSafeAreaContext.js.map +1 -0
  64. package/lib/commonjs/specs/NativeSafeAreaProvider.js +10 -0
  65. package/lib/commonjs/specs/NativeSafeAreaProvider.js.map +1 -0
  66. package/lib/commonjs/specs/NativeSafeAreaView.js +12 -0
  67. package/lib/commonjs/specs/NativeSafeAreaView.js.map +1 -0
  68. package/lib/module/SafeArea.types.js +2 -0
  69. package/lib/module/SafeArea.types.js.map +1 -0
  70. package/lib/module/SafeAreaView.js +176 -0
  71. package/lib/module/SafeAreaView.js.map +1 -0
  72. package/lib/module/index.js +7 -0
  73. package/lib/module/index.js.map +1 -0
  74. package/lib/module/specs/NativeSafeAreaContext.js +3 -0
  75. package/lib/module/specs/NativeSafeAreaContext.js.map +1 -0
  76. package/lib/module/specs/NativeSafeAreaProvider.js +3 -0
  77. package/lib/module/specs/NativeSafeAreaProvider.js.map +1 -0
  78. package/lib/module/specs/NativeSafeAreaView.js +5 -0
  79. package/lib/module/specs/NativeSafeAreaView.js.map +1 -0
  80. package/lib/typescript/SafeArea.types.d.ts +36 -0
  81. package/lib/typescript/SafeArea.types.d.ts.map +1 -0
  82. package/lib/typescript/SafeAreaView.d.ts +6 -0
  83. package/lib/typescript/SafeAreaView.d.ts.map +1 -0
  84. package/lib/typescript/index.d.ts +5 -0
  85. package/lib/typescript/index.d.ts.map +1 -0
  86. package/lib/typescript/specs/NativeSafeAreaContext.d.ts +23 -0
  87. package/lib/typescript/specs/NativeSafeAreaContext.d.ts.map +1 -0
  88. package/lib/typescript/specs/NativeSafeAreaProvider.d.ts +22 -0
  89. package/lib/typescript/specs/NativeSafeAreaProvider.d.ts.map +1 -0
  90. package/lib/typescript/specs/NativeSafeAreaView.d.ts +24 -0
  91. package/lib/typescript/specs/NativeSafeAreaView.d.ts.map +1 -0
  92. package/package.json +139 -0
  93. package/src/SafeArea.types.ts +47 -0
  94. package/src/SafeAreaView.tsx +201 -0
  95. package/src/index.tsx +6 -0
  96. package/src/specs/NativeSafeAreaContext.ts +23 -0
  97. package/src/specs/NativeSafeAreaProvider.ts +29 -0
  98. package/src/specs/NativeSafeAreaView.ts +28 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Th3rd Wave
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "Name": "react-native-safe-area-context",
4
+ "License": "MIT License",
5
+ "License File": "LICENSE",
6
+ "Version Number": "5.1.0",
7
+ "Owner" : "xiafeng@huawei.com",
8
+ "Upstream URL": "https://github.com/th3rdwave/react-native-safe-area-context",
9
+ "Description": "A flexible way to handle safe area insets in JS. Also works on Android and Web!"
10
+ }
11
+ ]
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @react-native-oh-tpl/react-native-safe-area-context
2
+ This project is based on [react-native-safe-area-context](https://github.com/th3rdwave/react-native-safe-area-context)
3
+ ## Documentation
4
+ [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-safe-area-context.md)
5
+
6
+ [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-safe-area-context.md)
7
+
8
+ ## License
9
+ This library is licensed under [The MIT License (MIT)](https://github.com/th3rdwave/react-native-safe-area-context/blob/main/LICENSE).
10
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Th3rd Wave
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,33 @@
1
+ OPEN SOURCE SOFTWARE NOTICE
2
+
3
+ Please note we provide an open source software notice for the third party open source software along with this software and/or this software component (in the following just “this SOFTWARE”). The open source software licenses are granted by the respective right holders.
4
+
5
+ Warranty Disclaimer
6
+ THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
7
+
8
+ Copyright Notice and License Texts
9
+
10
+ ----------------------------------------------------------------------
11
+ Software: react-native-safe-area-context V5.1.0
12
+
13
+ MIT License
14
+
15
+ Copyright (c) 2019 Th3rd Wave
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
@@ -0,0 +1,270 @@
1
+ > 模板版本:v0.0.1
2
+
3
+ <p align="center">
4
+ <h1 align="center"> <code>react-native-safe-area-context</code> </h1>
5
+ </p>
6
+ <p align="center">
7
+ <a href="https://github.com/th3rdwave/react-native-safe-area-context">
8
+ <img src="https://img.shields.io/badge/platforms-android%20%7C%20ios%20%7C%20web%20%7C%20macos%20%7C%20windows%20%7C%20harmony-lightgrey.svg" alt="Supported platforms" />
9
+ </a>
10
+ <a href="https://github.com/th3rdwave/react-native-safe-area-context/blob/main/LICENSE">
11
+ <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
12
+ </a>
13
+ </p>
14
+
15
+ ## 安装与使用
16
+
17
+ 进入到工程目录并输入以下命令:
18
+
19
+ <!-- tabs:start -->
20
+
21
+ **正在 npm 发布中,当前请先从仓库[Release](https://github.com/react-native-oh-library/react-native-safe-area-context/releases)中获取库 tgz,通过使用本地依赖来安装本库。**
22
+
23
+ #### **yarn**
24
+
25
+ ```bash
26
+ yarn add xxx
27
+ ```
28
+
29
+ #### **npm**
30
+
31
+ ```bash
32
+ npm install xxx
33
+ ```
34
+
35
+ <!-- tabs:end -->
36
+
37
+ 下面的代码展示了这个库的基本使用场景:
38
+
39
+ ```js
40
+ import React from "react";
41
+ import { Text, View } from "react-native";
42
+ import {
43
+ SafeAreaProvider,
44
+ SafeAreaView,
45
+ initialWindowMetrics,
46
+ } from "react-native-safe-area-context";
47
+
48
+ const App = () => {
49
+ return (
50
+ <SafeAreaProvider initialMetrics={initialWindowMetrics}>
51
+ <SafeAreaView style={{ flex: 1, backgroundColor: "red" }}>
52
+ <View style={{ flex: 1 }}>
53
+ <Text>hello</Text>
54
+ </View>
55
+ </SafeAreaView>
56
+ </SafeAreaProvider>
57
+ );
58
+ };
59
+
60
+ export default App;
61
+ ```
62
+
63
+ ## Link
64
+
65
+ 目前鸿蒙暂不支持 AutoLink,所以 Link 步骤需要手动配置。
66
+
67
+ 首先需要使用 DevEco Studio 打开项目里的鸿蒙工程 `harmony`
68
+
69
+ ### 引入原生端代码
70
+
71
+ 目前有两种方法:
72
+
73
+ 1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
74
+ 2. 直接链接源码。
75
+
76
+ 方法一:通过 har 包引入
77
+ 打开 `entry/oh-package.json5`,添加以下依赖
78
+
79
+ ```json
80
+ "dependencies": {
81
+ "rnoh": "file:../rnoh",
82
+ "rnoh-safe-area": "file:../../node_modules/react-native-safe-area-context/harmony/safe_area.har"
83
+ }
84
+ ```
85
+
86
+ 点击右上角的 `sync` 按钮
87
+
88
+ 或者在终端执行:
89
+
90
+ ```bash
91
+ cd entry
92
+ ohpm install
93
+ ```
94
+
95
+ 方法二:直接链接源码
96
+ 打开 `entry/oh-package.json5`,添加以下依赖
97
+
98
+ ```json
99
+ "dependencies": {
100
+ "rnoh": "file:../rnoh",
101
+ "rnoh-safe-area": "file:../../node_modules/react-native-safe-area-context/harmony/safe_area"
102
+ }
103
+ ```
104
+
105
+ 打开终端,执行:
106
+
107
+ ```bash
108
+ cd entry
109
+ ohpm install --no-link
110
+ ```
111
+
112
+ ### 配置 CMakeLists 和引入 SafeAreaViewPackage
113
+
114
+ 打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
115
+
116
+ ```diff
117
+ project(rnapp)
118
+ cmake_minimum_required(VERSION 3.4.1)
119
+ set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
120
+ set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
121
+ set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
122
+
123
+ add_subdirectory("${RNOH_CPP_DIR}" ./rn)
124
+
125
+ # RNOH_BEGIN: add_package_subdirectories
126
+ add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
127
+ + add_subdirectory("${OH_MODULE_DIR}/rnoh-safe-area/src/main/cpp" ./safe_area)
128
+ # RNOH_END: add_package_subdirectories
129
+
130
+ add_library(rnoh_app SHARED
131
+ "./PackageProvider.cpp"
132
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
133
+ )
134
+
135
+ target_link_libraries(rnoh_app PUBLIC rnoh)
136
+
137
+ # RNOH_BEGIN: link_packages
138
+ target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
139
+ + target_link_libraries(rnoh_app PUBLIC rnoh_safe_area)
140
+ # RNOH_END: link_packages
141
+ ```
142
+
143
+ 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
144
+
145
+ ```diff
146
+ #include "RNOH/PackageProvider.h"
147
+ #include "SamplePackage.h"
148
+ + #include "SafeAreaViewPackage.h"
149
+
150
+ using namespace rnoh;
151
+
152
+ std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
153
+ return {
154
+ std::make_shared<SamplePackage>(ctx),
155
+ + std::make_shared<SafeAreaViewPackage>(ctx)
156
+ };
157
+ }
158
+ ```
159
+
160
+ ### 在 ArkTs 侧引入 react-native-safe-area-context 组件
161
+
162
+ 打开 `entry/src/main/ets/pages/index.ets`,添加:
163
+
164
+ ```diff
165
+ import {
166
+ RNApp,
167
+ ComponentBuilderContext,
168
+ RNAbility,
169
+ AnyJSBundleProvider,
170
+ MetroJSBundleProvider,
171
+ ResourceJSBundleProvider,
172
+ } from 'rnoh'
173
+ import { SampleView, SAMPLE_VIEW_TYPE, PropsDisplayer } from "rnoh-sample-package"
174
+ import { createRNPackages } from '../RNPackagesFactory'
175
+ + import { SAFE_AREA_TYPE, RNCSafeAreaView, SAFE_AREA_PROVIDER_TYPE, SafeAreaProvider } from "rnoh-safe-area"
176
+
177
+ @Builder
178
+ function CustomComponentBuilder(ctx: ComponentBuilderContext) {
179
+ if (ctx.descriptor.type === SAMPLE_VIEW_TYPE) {
180
+ SampleView({
181
+ ctx: ctx.rnohContext,
182
+ tag: ctx.descriptor.tag,
183
+ buildCustomComponent: CustomComponentBuilder
184
+ })
185
+ }
186
+ + else if (ctx.descriptor.type === SAFE_AREA_TYPE) {
187
+ + RNCSafeAreaView({
188
+ + ctx: ctx.rnohContext,
189
+ + tag: ctx.descriptor.tag,
190
+ + buildCustomComponent: CustomComponentBuilder
191
+ + })
192
+ + }
193
+ + else if (ctx.descriptor.type === SAFE_AREA_PROVIDER_TYPE) {
194
+ + SafeAreaProvider({
195
+ + ctx: ctx.rnohContext,
196
+ + tag: ctx.descriptor.tag,
197
+ + buildCustomComponent: CustomComponentBuilder
198
+ + })
199
+ + }
200
+ ...
201
+ }
202
+ ...
203
+ ```
204
+
205
+ ### 在 ArkTs 侧引入 SafeAreaViewPackage
206
+
207
+ 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
208
+
209
+ ```diff
210
+ import type {RNPackageContext, RNPackage} from 'rnoh/ts';
211
+ import {SamplePackage} from 'rnoh-sample-package/ts';
212
+ + import {SafeAreaViewPackage} from 'rnoh-safe-area/ts';
213
+
214
+ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
215
+ return [
216
+ new SamplePackage(ctx),
217
+ + new SafeAreaViewPackage(ctx)
218
+ ];
219
+ }
220
+ ```
221
+
222
+ ### 运行
223
+
224
+ 点击右上角的 `sync` 按钮
225
+
226
+ 或者在终端执行:
227
+
228
+ ```bash
229
+ cd entry
230
+ ohpm install
231
+ ```
232
+
233
+ 然后编译、运行即可。
234
+
235
+ ## 兼容性
236
+
237
+ 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
238
+
239
+ 请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-safe-area-context Releases](https://github.com/react-native-oh-library/react-native-safe-area-context/releases)
240
+
241
+ ## 属性
242
+
243
+ **组件 SafeAreaProvider**
244
+
245
+ You should add `SafeAreaProvider` in your app root component. You may need to add it in other places like the root of modals and routes when using react-native-screens.
246
+
247
+ Note that providers should not be inside a View that is animated with Animated or inside a ScrollView since it can cause very frequent updates.
248
+
249
+ | 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
250
+ | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- | -------- | -------- |
251
+ | `Props` | Accepts all View props. Has a default style of {flex: 1}. | object | no | All | yes |
252
+ | `initialMetrics` | Can be used to provide the initial value for frame and insets, this allows rendering immediatly. See optimization for more information on how to use this prop. | object | no | All | yes |
253
+
254
+ **组件 SafeAreaView**
255
+
256
+ `SafeAreaView` is a regular View component with the safe area insets applied as padding or margin.
257
+
258
+ | 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
259
+ | ------- | ----------------------------------------------------------------------------------------------- | ------ | -------- | -------- | -------- |
260
+ | `Props` | Accepts all View props. Has a default style of {flex: 1}. | object | no | All | yes |
261
+ | `edges` | Sets the edges to apply the safe area insets to. Defaults to all. | array | no | All | yes |
262
+ | `mode` | Optional, padding (default) or margin. Apply the safe area to either the padding or the margin. | string | no | All | yes |
263
+
264
+ ## 遗留问题
265
+
266
+ ## 其他
267
+
268
+ ## 开源协议
269
+
270
+ 本项目基于 [The MIT License (MIT)](https://github.com/th3rdwave/react-native-safe-area-context/blob/main/LICENSE) ,请自由地享受和参与开源。
@@ -0,0 +1,9 @@
1
+ {
2
+ "apiType": "stageMode",
3
+ "targets": [
4
+ {
5
+ "name": "default",
6
+ "runtimeOS": "HarmonyOS"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,6 @@
1
+ import { harTasks } from '@ohos/hvigor-ohos-plugin';
2
+
3
+ export default {
4
+ system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
6
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ export * from "./ts"
25
+ export * from "./src/main/ets/SafeAreaView"
26
+ export * from "./src/main/ets/SafeAreaProvider"
@@ -0,0 +1,22 @@
1
+ {
2
+ "license": "ISC",
3
+ "types": "",
4
+ "devDependencies": {},
5
+ "author": "",
6
+ "name": "@react-native-ohos/react-native-safe-area-context",
7
+ "description": "Please describe the basic information.",
8
+ "main": "index.ets",
9
+ "version": "5.1.1-rc.1",
10
+ "dependencies": {
11
+ "@rnoh/react-native-openharmony": "file:../../node_modules/@react-native-oh/react-native-harmony/harmony/react_native_openharmony.har"
12
+ },
13
+ "metadata": {
14
+ "sourceRoots": [
15
+ "./src/main"
16
+ ],
17
+ "debug": true
18
+ },
19
+ "compatibleSdkVersion": 12,
20
+ "compatibleSdkType": "HarmonyOS",
21
+ "obfuscated": false
22
+ }
@@ -0,0 +1,9 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ set(CMAKE_VERBOSE_MAKEFILE on)
3
+
4
+ set(rnoh_safe_area_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated")
5
+ file(GLOB_RECURSE rnoh_safe_area_generated_SRC "${rnoh_safe_area_generated_dir}/**/*.cpp")
6
+ file(GLOB rnoh_safe_area_SRC CONFIGURE_DEPENDS *.cpp)
7
+ add_library(rnoh_safe_area SHARED ${rnoh_safe_area_generated_SRC} ${rnoh_safe_area_SRC})
8
+ target_include_directories(rnoh_safe_area PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rnoh_safe_area_generated_dir})
9
+ target_link_libraries(rnoh_safe_area PUBLIC rnoh)
@@ -0,0 +1,56 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #ifndef HARMONY_SAFEAREABEANDATA_H
26
+ #define HARMONY_SAFEAREABEANDATA_H
27
+ #include <string>
28
+ namespace safeArea {
29
+ struct EdgeInsets {
30
+ double_t top;
31
+ double_t right;
32
+ double_t bottom;
33
+ double_t left;
34
+ };
35
+
36
+ struct Edge {
37
+ std::string top;
38
+ std::string right;
39
+ std::string bottom;
40
+ std::string left;
41
+ };
42
+
43
+ struct Frame {
44
+ double_t x;
45
+ double_t y;
46
+ double_t width;
47
+ double_t height;
48
+ };
49
+
50
+ struct Event {
51
+ EdgeInsets insets;
52
+ Frame frame;
53
+ };
54
+ } // namespace safeArea
55
+
56
+ #endif // HARMONY_SAFEAREABEANDATA_H
@@ -0,0 +1,45 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #include "SafeAreaColumnNode.h"
25
+
26
+ #include <glog/logging.h>
27
+ #include <memory>
28
+ #include "RNOH/arkui/NativeNodeApi.h"
29
+
30
+ namespace rnoh {
31
+
32
+ SafeAreaColumnNode::SafeAreaColumnNode()
33
+ : ArkUINode(NativeNodeApi::getInstance()->createNode(ArkUI_NodeType::ARKUI_NODE_COLUMN)) {}
34
+
35
+ SafeAreaColumnNode::~SafeAreaColumnNode() {}
36
+
37
+ void SafeAreaColumnNode::insertChild(ArkUINode &child, std::size_t index) {
38
+ maybeThrow(NativeNodeApi::getInstance()->insertChildAt(m_nodeHandle, child.getArkUINodeHandle(),
39
+ static_cast<int32_t>(index)));
40
+ }
41
+
42
+ void SafeAreaColumnNode::removeChild(ArkUINode &child) {
43
+ maybeThrow(NativeNodeApi::getInstance()->removeChild(m_nodeHandle, child.getArkUINodeHandle()));
44
+ }
45
+ } // namespace rnoh
@@ -0,0 +1,38 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #pragma once
25
+
26
+ #include "RNOH/arkui/ArkUINode.h"
27
+
28
+ namespace rnoh {
29
+ class SafeAreaColumnNode : public ArkUINode {
30
+ public:
31
+ SafeAreaColumnNode();
32
+ ~SafeAreaColumnNode() override;
33
+
34
+ void insertChild(ArkUINode &child, std::size_t index);
35
+ void removeChild(ArkUINode &child);
36
+ };
37
+
38
+ } // namespace rnoh
@@ -0,0 +1,66 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "SafeAreaManagerMap.h"
26
+
27
+ SafeAreaManagerMap::SafeAreaManagerMap()
28
+ {
29
+ }
30
+
31
+ SafeAreaManagerMap &SafeAreaManagerMap::getInstance()
32
+ {
33
+ static SafeAreaManagerMap instance;
34
+ return instance;
35
+ }
36
+
37
+ void SafeAreaManagerMap::SetHasSafeAreaProviderByNodeHandle(ArkUI_NodeHandle nodeHandle, bool isHasSafeAreaProvider)
38
+ {
39
+ if (!nodeHandle) {
40
+ return;
41
+ }
42
+ hasSafeAreaProviderMap_[nodeHandle] = isHasSafeAreaProvider;
43
+ }
44
+
45
+ bool SafeAreaManagerMap::GetHasSafeAreaProviderByNodeHandle(ArkUI_NodeHandle nodeHandle)
46
+ {
47
+ if (!nodeHandle) {
48
+ return false;
49
+ }
50
+ auto it = hasSafeAreaProviderMap_.find(nodeHandle);
51
+ if (it != hasSafeAreaProviderMap_.end()) {
52
+ return hasSafeAreaProviderMap_.at(nodeHandle);
53
+ }
54
+ return false;
55
+ }
56
+
57
+ void SafeAreaManagerMap::RemoveSafeAreaProviderByNodeHandle(ArkUI_NodeHandle nodeHandle)
58
+ {
59
+ if (!nodeHandle) {
60
+ return;
61
+ }
62
+ auto it = hasSafeAreaProviderMap_.find(nodeHandle);
63
+ if (it != hasSafeAreaProviderMap_.end()) {
64
+ hasSafeAreaProviderMap_.erase(nodeHandle);
65
+ }
66
+ }