@react-native-ohos/react-native-safe-area-context 5.1.1-rc.1 → 5.1.1-rc.4
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 +3 -3
- package/harmony/safe_area/oh-package.json5 +1 -1
- package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.cpp +50 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.h +12 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.cpp +2 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.cpp +35 -4
- package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.h +6 -0
- package/harmony/safe_area.har +0 -0
- package/lib/commonjs/SafeAreaView.js +23 -1
- package/lib/commonjs/SafeAreaView.js.map +1 -1
- package/lib/commonjs/index.js +23 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeSafeAreaContext.js +23 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js.map +1 -1
- package/lib/commonjs/specs/NativeSafeAreaProvider.js +23 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js.map +1 -1
- package/lib/commonjs/specs/NativeSafeAreaView.js +23 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js.map +1 -1
- package/lib/module/SafeAreaView.js +23 -0
- package/lib/module/SafeAreaView.js.map +1 -1
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeSafeAreaContext.js +23 -0
- package/lib/module/specs/NativeSafeAreaContext.js.map +1 -1
- package/lib/module/specs/NativeSafeAreaProvider.js +24 -0
- package/lib/module/specs/NativeSafeAreaProvider.js.map +1 -1
- package/lib/module/specs/NativeSafeAreaView.js +23 -0
- package/lib/module/specs/NativeSafeAreaView.js.map +1 -1
- package/lib/typescript/SafeArea.types.d.ts +23 -0
- package/lib/typescript/SafeArea.types.d.ts.map +1 -1
- package/lib/typescript/SafeAreaView.d.ts +23 -0
- package/lib/typescript/SafeAreaView.d.ts.map +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts +23 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts.map +1 -1
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts +23 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts.map +1 -1
- package/lib/typescript/specs/NativeSafeAreaView.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/SafeArea.types.ts +23 -0
- package/src/SafeAreaView.tsx +23 -0
- package/src/index.tsx +23 -0
- package/src/specs/NativeSafeAreaContext.ts +23 -0
- package/src/specs/NativeSafeAreaProvider.ts +23 -0
- package/src/specs/NativeSafeAreaView.ts +23 -0
- package/harmony/safe_area/LICENSE +0 -21
- package/harmony/safe_area/NOTICE +0 -33
- package/harmony/safe_area/README.md +0 -270
|
@@ -1,270 +0,0 @@
|
|
|
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) ,请自由地享受和参与开源。
|