@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
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 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
|
+
import matrix4 from '@ohos.matrix4'
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
Descriptor,
|
|
29
|
+
ComponentBuilderContext,
|
|
30
|
+
RNOHContext,
|
|
31
|
+
ViewBaseProps,
|
|
32
|
+
Tag,
|
|
33
|
+
RNComponentFactory,
|
|
34
|
+
ViewRawProps,
|
|
35
|
+
RNViewManager,
|
|
36
|
+
ViewDescriptorWrapperBase,
|
|
37
|
+
TransformMatrix,
|
|
38
|
+
CompactValue,
|
|
39
|
+
Edges,
|
|
40
|
+
Point
|
|
41
|
+
} from '@rnoh/react-native-openharmony'
|
|
42
|
+
|
|
43
|
+
import { SafeAreaViewModifier } from './SafeAreaViewModifier'
|
|
44
|
+
import { SafeAreaViewTurboModule } from "./SafeViewTurboModule"
|
|
45
|
+
import { EdgeInsets, AvoidArea, Event, EdgesMode } from './common/SafeAreaType';
|
|
46
|
+
import Logger from './Logger'
|
|
47
|
+
|
|
48
|
+
export const SAFE_AREA_VIEW_TYPE: string = "RNCSafeAreaView"
|
|
49
|
+
|
|
50
|
+
export type DimensionValue = number | 'auto' | `${number}%` | null;
|
|
51
|
+
|
|
52
|
+
export interface SafeAreaViewProps extends ViewBaseProps {
|
|
53
|
+
edges: EdgesMode,
|
|
54
|
+
mode: string,
|
|
55
|
+
margin: EdgeInsets,
|
|
56
|
+
padding: EdgeInsets,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SafeAreaViewState {}
|
|
60
|
+
|
|
61
|
+
export interface SafeAreaViewRawProps extends ViewRawProps {
|
|
62
|
+
mode: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type SafeAreaViewDescriptor = Descriptor<"RNCSafeAreaView", SafeAreaViewProps, SafeAreaViewState, SafeAreaViewRawProps>;
|
|
66
|
+
|
|
67
|
+
export class SafeAreaViewManager extends RNViewManager {
|
|
68
|
+
protected offsetX: number = 0;
|
|
69
|
+
protected offsetY: number = 0;
|
|
70
|
+
|
|
71
|
+
constructor(
|
|
72
|
+
tag: Tag,
|
|
73
|
+
ctx: RNOHContext,
|
|
74
|
+
offsetX: number,
|
|
75
|
+
offsetY: number
|
|
76
|
+
) {
|
|
77
|
+
super(tag, ctx);
|
|
78
|
+
this.offsetX = offsetX
|
|
79
|
+
this.offsetY = offsetY
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setOffsetX(offsetX: number) {
|
|
83
|
+
this.offsetX = offsetX
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setOffsetY(offsetY: number) {
|
|
87
|
+
this.offsetY = offsetY
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public computeChildPoint(point: Point, childTag: Tag): Point {
|
|
91
|
+
return super.computeChildPoint({ x: point.x + this.offsetX, y: point.y + this.offsetY }, childTag);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class SafeAreaViewDescriptorWrapper extends ViewDescriptorWrapperBase<"RNCSafeAreaView", SafeAreaViewProps, SafeAreaViewState, SafeAreaViewRawProps> {
|
|
96
|
+
public edgeInsets: EdgeInsets = { top: 0,
|
|
97
|
+
right: 0,
|
|
98
|
+
bottom: 0,
|
|
99
|
+
left: 0 }
|
|
100
|
+
|
|
101
|
+
public get mode(): string | undefined {
|
|
102
|
+
return this.rawProps.mode
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public SetEdgeInsets(edges: EdgeInsets) {
|
|
106
|
+
this.edgeInsets = edges
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public getEdgeInsets() {
|
|
110
|
+
return this.edgeInsets
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public get margin(): Edges<CompactValue> {
|
|
114
|
+
const resolvedEdges = this.resolveEdges({
|
|
115
|
+
all: this.rawProps.margin,
|
|
116
|
+
top: this.rawProps.marginTop,
|
|
117
|
+
left: this.rawProps.marginLeft,
|
|
118
|
+
right: this.rawProps.marginRight,
|
|
119
|
+
bottom: this.rawProps.marginBottom,
|
|
120
|
+
start: this.rawProps.marginStart,
|
|
121
|
+
end: this.rawProps.marginEnd,
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
top: new CompactValue(resolvedEdges.top as DimensionValue, this.height),
|
|
126
|
+
left: new CompactValue(resolvedEdges.left as DimensionValue, this.width),
|
|
127
|
+
right: new CompactValue(resolvedEdges.right as DimensionValue, this.width),
|
|
128
|
+
bottom: new CompactValue(resolvedEdges.bottom as DimensionValue, this.height),
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@Component
|
|
134
|
+
export struct SafeAreaView {
|
|
135
|
+
ctx!: RNOHContext
|
|
136
|
+
tag: number = 0
|
|
137
|
+
@BuilderParam public buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
|
|
138
|
+
private componentManager!: SafeAreaViewManager
|
|
139
|
+
@State descriptor: SafeAreaViewDescriptor = {} as SafeAreaViewDescriptor
|
|
140
|
+
@State descriptorWrapper: SafeAreaViewDescriptorWrapper | undefined = undefined
|
|
141
|
+
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
142
|
+
private unregisterComponentManager?: () => void = undefined
|
|
143
|
+
@State avoidArea: AvoidArea = {} as AvoidArea
|
|
144
|
+
@State edgeInsets: EdgeInsets = { top: 0, right: 0, bottom: 0, left: 0 }
|
|
145
|
+
|
|
146
|
+
getEdgeValue(edgeMode: string | undefined, insetValue: number, edgeValue: number): number {
|
|
147
|
+
if (edgeMode == 'off') {
|
|
148
|
+
return 0;
|
|
149
|
+
} else if (edgeMode == 'maximum') {
|
|
150
|
+
//insetValue 安全区域 edgeValue原区域
|
|
151
|
+
return edgeValue > insetValue ? edgeValue - insetValue : insetValue - edgeValue
|
|
152
|
+
} else {
|
|
153
|
+
return insetValue;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
updateInsets() {
|
|
158
|
+
const safeAreaViewTurboModule = this.ctx.rnInstance.getTurboModule<SafeAreaViewTurboModule>("RNCSafeAreaContext")
|
|
159
|
+
const safeAreaInsets = safeAreaViewTurboModule.getSafeAreaInsets();
|
|
160
|
+
let edges: EdgesMode = { top: 'additive', right: 'additive', bottom: 'additive', left: 'additive' };
|
|
161
|
+
edges = this.descriptor.props.edges
|
|
162
|
+
safeAreaInsets.then((data: Event) => {
|
|
163
|
+
if (data.insets) {
|
|
164
|
+
let edgesData = this.descriptorWrapper?.mode && this.descriptorWrapper?.mode === 'margin' ? this.descriptor.props.margin : this.descriptor.props.padding
|
|
165
|
+
this.edgeInsets = {
|
|
166
|
+
top: this.getEdgeValue(edges.top, data.insets.top, edgesData?.top),
|
|
167
|
+
right: this.getEdgeValue(edges.right, data.insets.right, edgesData?.right),
|
|
168
|
+
bottom: this.getEdgeValue(edges.bottom, data.insets.bottom, edgesData?.bottom),
|
|
169
|
+
left: this.getEdgeValue(edges.left, data.insets.left, edgesData?.left)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
Logger.info("edgeInsets " + JSON.stringify(this.edgeInsets))
|
|
173
|
+
})
|
|
174
|
+
.catch((e: string | Error) => {
|
|
175
|
+
Logger.error('updateInsets error', JSON.stringify(e));
|
|
176
|
+
this.edgeInsets = {
|
|
177
|
+
top: 0,
|
|
178
|
+
right: 0,
|
|
179
|
+
bottom: 0,
|
|
180
|
+
left: 0
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
.finally(() => {
|
|
184
|
+
if (this.descriptorWrapper) {
|
|
185
|
+
this.descriptorWrapper.SetEdgeInsets(this.edgeInsets)
|
|
186
|
+
}
|
|
187
|
+
let offsetY = this.edgeInsets.bottom - this.edgeInsets.top
|
|
188
|
+
let offsetX = this.edgeInsets.right - this.edgeInsets.left
|
|
189
|
+
this.componentManager.setOffsetY(offsetY)
|
|
190
|
+
this.componentManager.setOffsetX(offsetX)
|
|
191
|
+
this.componentManager.markBoundingBoxAsDirty()
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
aboutToAppear() {
|
|
196
|
+
this.descriptor = this.ctx.descriptorRegistry.getDescriptor<SafeAreaViewDescriptor>(this.tag)
|
|
197
|
+
if (this.descriptor) {
|
|
198
|
+
this.setDescriptor(this.descriptor)
|
|
199
|
+
}
|
|
200
|
+
this.updateInsets()
|
|
201
|
+
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
202
|
+
(newDescriptor) => {
|
|
203
|
+
this.setDescriptor(newDescriptor as SafeAreaViewDescriptor)
|
|
204
|
+
this.updateInsets()
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
this.initComponent()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
aboutToDisappear() {
|
|
211
|
+
this.unregisterDescriptorChangesListener?.()
|
|
212
|
+
this.unregisterComponentManager?.()
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
initComponent() {
|
|
216
|
+
if (!this.componentManager) {
|
|
217
|
+
this.componentManager = new SafeAreaViewManager(this.tag, this.ctx, 0, 0)
|
|
218
|
+
}
|
|
219
|
+
this.unregisterComponentManager = this.ctx.componentManagerRegistry.registerComponentManager(this.tag, this.componentManager)
|
|
220
|
+
const parentTag = this.descriptor.parentTag;
|
|
221
|
+
this.componentManager.setParentTag(parentTag);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private setDescriptor(descriptor: SafeAreaViewDescriptor) {
|
|
225
|
+
this.descriptorWrapper = new SafeAreaViewDescriptorWrapper(descriptor)
|
|
226
|
+
this.descriptor = descriptor
|
|
227
|
+
Logger.info('descriptorWrapper' + JSON.stringify(this.descriptorWrapper))
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
build() {
|
|
231
|
+
Stack() {
|
|
232
|
+
ForEach(this.descriptorWrapper?.childrenTags, (childrenTag: Tag) => {
|
|
233
|
+
RNComponentFactory({
|
|
234
|
+
ctx: this.ctx,
|
|
235
|
+
tag: childrenTag,
|
|
236
|
+
buildCustomComponent: this.buildCustomComponent
|
|
237
|
+
})
|
|
238
|
+
}, (tag: Tag) => tag.toString())
|
|
239
|
+
}
|
|
240
|
+
.attributeModifier(SafeAreaViewModifier.getInstance().setDescriptor(this.descriptorWrapper))
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 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
|
+
import { TransformMatrix } from '@rnoh/react-native-openharmony'
|
|
26
|
+
import { SafeAreaViewDescriptorWrapper } from './SafeAreaView'
|
|
27
|
+
import matrix4 from '@ohos.matrix4'
|
|
28
|
+
|
|
29
|
+
export class SafeAreaViewModifier implements AttributeModifier<StackAttribute> {
|
|
30
|
+
private constructor() {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private static instance: SafeAreaViewModifier;
|
|
34
|
+
protected descriptorWrapper: SafeAreaViewDescriptorWrapper | undefined = undefined
|
|
35
|
+
|
|
36
|
+
public static getInstance(): SafeAreaViewModifier {
|
|
37
|
+
if (!SafeAreaViewModifier.instance) {
|
|
38
|
+
SafeAreaViewModifier.instance = new SafeAreaViewModifier();
|
|
39
|
+
}
|
|
40
|
+
return SafeAreaViewModifier.instance;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setDescriptor(descriptorWrapper: SafeAreaViewDescriptorWrapper | undefined): SafeAreaViewModifier {
|
|
44
|
+
this.descriptorWrapper = descriptorWrapper;
|
|
45
|
+
return SafeAreaViewModifier.instance;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getHitTestMode() {
|
|
49
|
+
switch (this.descriptorWrapper?.pointerEvents) {
|
|
50
|
+
case "none":
|
|
51
|
+
return HitTestMode.None
|
|
52
|
+
case "box-none":
|
|
53
|
+
return HitTestMode.None
|
|
54
|
+
case "box-only":
|
|
55
|
+
return HitTestMode.Block
|
|
56
|
+
default:
|
|
57
|
+
return HitTestMode.Default
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getBorderStyle(): BorderStyle {
|
|
62
|
+
switch (this.descriptorWrapper?.borderStyle) {
|
|
63
|
+
case "dashed":
|
|
64
|
+
return BorderStyle.Dashed
|
|
65
|
+
case "dotted":
|
|
66
|
+
return BorderStyle.Dotted
|
|
67
|
+
default:
|
|
68
|
+
return BorderStyle.Solid
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getTransform(): undefined | matrix4.Matrix4Transit {
|
|
73
|
+
const descriptorWrapper = this.descriptorWrapper
|
|
74
|
+
if (!descriptorWrapper) {
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
const rawTransformationMatrix = descriptorWrapper.rawTransformationMatrix.slice()
|
|
78
|
+
rawTransformationMatrix[12] = vp2px(rawTransformationMatrix[12]);
|
|
79
|
+
rawTransformationMatrix[13] = vp2px(rawTransformationMatrix[13]);
|
|
80
|
+
rawTransformationMatrix[14] = vp2px(rawTransformationMatrix[14]);
|
|
81
|
+
return matrix4.init(rawTransformationMatrix as TransformMatrix)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
applyNormalAttribute(instance: StackAttribute): void {
|
|
85
|
+
instance.width(this.descriptorWrapper?.width)
|
|
86
|
+
instance.height(this.descriptorWrapper?.height)
|
|
87
|
+
instance.position(this.descriptorWrapper?.positionRelativeToParent)
|
|
88
|
+
|
|
89
|
+
if (this.descriptorWrapper?.backgroundColor !== '#00000000') {
|
|
90
|
+
instance.backgroundColor(this.descriptorWrapper?.backgroundColor)
|
|
91
|
+
}
|
|
92
|
+
if (JSON.stringify(this.descriptorWrapper?.borderWidth) !== '{}') {
|
|
93
|
+
instance.borderWidth(this.descriptorWrapper?.borderWidth)
|
|
94
|
+
}
|
|
95
|
+
if (JSON.stringify(this.descriptorWrapper?.borderColor) !== '{"top":"#00000000","left":"#00000000","right":"#00000000","bottom":"#00000000"}') {
|
|
96
|
+
instance.borderColor(this.descriptorWrapper?.borderColor)
|
|
97
|
+
}
|
|
98
|
+
if (JSON.stringify(this.descriptorWrapper?.borderRadius) !== '{}') {
|
|
99
|
+
instance.borderRadius(this.descriptorWrapper?.borderRadius)
|
|
100
|
+
}
|
|
101
|
+
if (this.descriptorWrapper?.borderStyle === 'dashed' || this.descriptorWrapper?.borderStyle === 'dotted') {
|
|
102
|
+
instance.borderStyle(this.getBorderStyle())
|
|
103
|
+
}
|
|
104
|
+
if (this.descriptorWrapper?.opacity !== 1) {
|
|
105
|
+
instance.opacity(this.descriptorWrapper?.opacity)
|
|
106
|
+
}
|
|
107
|
+
// if (this.descriptorWrapper?.transformStringify !== '[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]') {
|
|
108
|
+
// instance.transform(this.getTransform())
|
|
109
|
+
// }
|
|
110
|
+
if (this.descriptorWrapper?.isClipping) {
|
|
111
|
+
instance.clip(this.descriptorWrapper?.isClipping)
|
|
112
|
+
}
|
|
113
|
+
let hitTestBehavior: HitTestMode = this.getHitTestMode();
|
|
114
|
+
if (hitTestBehavior !== HitTestMode.Default) {
|
|
115
|
+
instance.hitTestBehavior(hitTestBehavior)
|
|
116
|
+
}
|
|
117
|
+
if (this.descriptorWrapper?.shadow) {
|
|
118
|
+
instance.shadow(this.descriptorWrapper?.shadow)
|
|
119
|
+
}
|
|
120
|
+
if (this.descriptorWrapper?.mode) {
|
|
121
|
+
if (this.descriptorWrapper?.mode === 'margin') {
|
|
122
|
+
instance.margin({
|
|
123
|
+
top: this.descriptorWrapper?.edgeInsets.top,
|
|
124
|
+
right: this.descriptorWrapper?.edgeInsets.right,
|
|
125
|
+
bottom: this.descriptorWrapper?.edgeInsets.bottom,
|
|
126
|
+
left: this.descriptorWrapper?.edgeInsets.left
|
|
127
|
+
})
|
|
128
|
+
instance.padding(0)
|
|
129
|
+
} else {
|
|
130
|
+
instance.padding({
|
|
131
|
+
top: this.descriptorWrapper?.edgeInsets.top,
|
|
132
|
+
right: this.descriptorWrapper?.edgeInsets.right,
|
|
133
|
+
bottom: this.descriptorWrapper?.edgeInsets.bottom,
|
|
134
|
+
left: this.descriptorWrapper?.edgeInsets.left
|
|
135
|
+
})
|
|
136
|
+
instance.margin(0)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 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
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
27
|
+
import { SafeAreaViewTurboModule } from './SafeViewTurboModule';
|
|
28
|
+
import { RNOHPackage } from "@rnoh/react-native-openharmony";
|
|
29
|
+
|
|
30
|
+
class SafeAreaTurboModulesFactory extends TurboModulesFactory {
|
|
31
|
+
createTurboModule(name: string): TurboModule | null {
|
|
32
|
+
if (name === 'RNCSafeAreaContext') {
|
|
33
|
+
return new SafeAreaViewTurboModule(this.ctx);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
hasTurboModule(name: string): boolean {
|
|
39
|
+
return name === 'RNCSafeAreaContext';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class SafeAreaViewPackage extends RNOHPackage {
|
|
44
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
45
|
+
return new SafeAreaTurboModulesFactory(ctx);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 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
|
+
|
|
26
|
+
import window from '@ohos.window';
|
|
27
|
+
import type { TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
28
|
+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
29
|
+
import type { EdgeInsets, Event, Frame } from './common/SafeAreaType';
|
|
30
|
+
import Logger from './Logger';
|
|
31
|
+
|
|
32
|
+
const TAG: string = '[RNOH]SafeAreaViewTurboModule'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export class SafeAreaViewTurboModule extends TurboModule {
|
|
36
|
+
private windowInstance: window.Window = null;
|
|
37
|
+
|
|
38
|
+
constructor(protected ctx: TurboModuleContext) {
|
|
39
|
+
super(ctx);
|
|
40
|
+
if (!this.windowInstance) {
|
|
41
|
+
window.getLastWindow(this.ctx.uiAbilityContext, (err, data) => {
|
|
42
|
+
if (err.code) {
|
|
43
|
+
Logger.debug(TAG, 'Failed to obtain the top window. Cause: ' + JSON.stringify(err));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.windowInstance = data
|
|
47
|
+
})
|
|
48
|
+
this.sleep(10);
|
|
49
|
+
}
|
|
50
|
+
Logger.debug(TAG, '[RNOH]:SafeAreaViewTurboModule constructor');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
sleep(delay: number) {
|
|
54
|
+
var start = new Date().getTime();
|
|
55
|
+
while ((new Date().getTime() - start) < delay) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getConstants(): {} {
|
|
61
|
+
Logger.debug(TAG, 'RNCSafeAreaContext getConstants:' + this.windowInstance);
|
|
62
|
+
let frame: Frame = {
|
|
63
|
+
x: 0,
|
|
64
|
+
y: 0,
|
|
65
|
+
width: 0,
|
|
66
|
+
height: 0
|
|
67
|
+
}
|
|
68
|
+
let insets: EdgeInsets = {
|
|
69
|
+
top: 0,
|
|
70
|
+
right: 0,
|
|
71
|
+
bottom: 0,
|
|
72
|
+
left: 0
|
|
73
|
+
}
|
|
74
|
+
if (this.windowInstance != null) {
|
|
75
|
+
const windowInfo = this.windowInstance.getWindowProperties()
|
|
76
|
+
const avoidArea = this.windowInstance.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
|
|
77
|
+
const avoidAreaBottom = this.windowInstance.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
|
|
78
|
+
frame = {
|
|
79
|
+
x: px2vp(windowInfo.windowRect.left),
|
|
80
|
+
y: px2vp(windowInfo.windowRect.top),
|
|
81
|
+
width: px2vp(windowInfo.windowRect.width),
|
|
82
|
+
height: px2vp(windowInfo.windowRect.height)
|
|
83
|
+
}
|
|
84
|
+
insets = {
|
|
85
|
+
top: px2vp(avoidArea.topRect.height),
|
|
86
|
+
right: px2vp(avoidArea.rightRect.height),
|
|
87
|
+
bottom: px2vp(avoidAreaBottom.bottomRect.height),
|
|
88
|
+
left: px2vp(avoidArea.leftRect.height)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { "initialWindowMetrics": { frame, insets } }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getSafeAreaInsets(): Promise<Event> {
|
|
95
|
+
return new Promise(async (resolve, reject) => {
|
|
96
|
+
try {
|
|
97
|
+
const windowInstance = await window.getLastWindow(this.ctx.uiAbilityContext);
|
|
98
|
+
const windowInfo = windowInstance.getWindowProperties()
|
|
99
|
+
Logger.debug(TAG, JSON.stringify(windowInfo));
|
|
100
|
+
const frame: Frame = {
|
|
101
|
+
x: px2vp(windowInfo.windowRect.left),
|
|
102
|
+
y: px2vp(windowInfo.windowRect.top),
|
|
103
|
+
width: px2vp(windowInfo.windowRect.width),
|
|
104
|
+
height: px2vp(windowInfo.windowRect.height)
|
|
105
|
+
}
|
|
106
|
+
if (!windowInfo.isLayoutFullScreen) {
|
|
107
|
+
const insets: EdgeInsets = {
|
|
108
|
+
top: 0,
|
|
109
|
+
right: 0,
|
|
110
|
+
bottom: 0,
|
|
111
|
+
left: 0
|
|
112
|
+
}
|
|
113
|
+
resolve({ insets, frame })
|
|
114
|
+
} else {
|
|
115
|
+
let type = window.AvoidAreaType.TYPE_SYSTEM;
|
|
116
|
+
let avoidArea = windowInstance.getWindowAvoidArea(type);
|
|
117
|
+
const avoidAreaBottom = this.windowInstance.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
|
|
118
|
+
const insets: EdgeInsets = {
|
|
119
|
+
top: px2vp(avoidArea.topRect.height),
|
|
120
|
+
right: px2vp(avoidArea.rightRect.height),
|
|
121
|
+
bottom: px2vp(avoidAreaBottom.bottomRect.height),
|
|
122
|
+
left: px2vp(avoidArea.leftRect.height)
|
|
123
|
+
}
|
|
124
|
+
resolve({ insets, frame })
|
|
125
|
+
}
|
|
126
|
+
} catch (exception) {
|
|
127
|
+
reject(exception)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 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
|
+
export type EdgesMode = {
|
|
26
|
+
top?: string
|
|
27
|
+
right?: string
|
|
28
|
+
bottom?: string
|
|
29
|
+
left?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type EdgeInsets = {
|
|
33
|
+
top: number
|
|
34
|
+
right: number
|
|
35
|
+
bottom: number
|
|
36
|
+
left: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Frame = {
|
|
40
|
+
x: number
|
|
41
|
+
y: number
|
|
42
|
+
width: number
|
|
43
|
+
height: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type Event = {
|
|
47
|
+
insets: EdgeInsets
|
|
48
|
+
frame: Frame
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type Rect = {
|
|
52
|
+
top?: number
|
|
53
|
+
right?: number
|
|
54
|
+
bottom?: number
|
|
55
|
+
left?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type AvoidArea = {
|
|
59
|
+
margin?: Rect | number
|
|
60
|
+
padding?: Rect | number
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type AvoidAreaProps = {
|
|
64
|
+
edges: string
|
|
65
|
+
mode: string
|
|
66
|
+
margin: string
|
|
67
|
+
padding: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type Tag = number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 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
|
+
export * from "./src/main/ets/SafeAreaViewPackage"
|
|
26
|
+
export * from "./src/main/ets/SafeViewTurboModule"
|