@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.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +10 -0
- package/harmony/safe_area/LICENSE +21 -0
- package/harmony/safe_area/NOTICE +33 -0
- package/harmony/safe_area/README.md +270 -0
- package/harmony/safe_area/build-profile.json5 +9 -0
- package/harmony/safe_area/hvigorfile.ts +6 -0
- package/harmony/safe_area/index.ets +26 -0
- package/harmony/safe_area/oh-package.json5 +22 -0
- package/harmony/safe_area/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaBeanData.h +56 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.cpp +45 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.h +38 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.cpp +66 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.h +57 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.cpp +75 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.h +49 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.cpp +94 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.h +53 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.cpp +94 -0
- package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.h +64 -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 +33 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/BaseReactNativeSafeAreaContextPackage.h +72 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaProviderComponentInstance.h +18 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaViewComponentInstance.h +18 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaProviderJSIBinder.h +27 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaViewJSIBinder.h +30 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.cpp +16 -0
- package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.h +16 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ComponentDescriptors.h +25 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.cpp +56 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.h +59 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.cpp +36 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.h +88 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.cpp +20 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.h +39 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.cpp +18 -0
- package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.h +23 -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.ts +46 -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.ts +26 -0
- package/harmony/safe_area.har +0 -0
- package/lib/commonjs/SafeArea.types.js +6 -0
- package/lib/commonjs/SafeArea.types.js.map +1 -0
- package/lib/commonjs/SafeAreaView.js +184 -0
- package/lib/commonjs/SafeAreaView.js.map +1 -0
- package/lib/commonjs/index.js +51 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js +9 -0
- package/lib/commonjs/specs/NativeSafeAreaContext.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js +10 -0
- package/lib/commonjs/specs/NativeSafeAreaProvider.js.map +1 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js +12 -0
- package/lib/commonjs/specs/NativeSafeAreaView.js.map +1 -0
- package/lib/module/SafeArea.types.js +2 -0
- package/lib/module/SafeArea.types.js.map +1 -0
- package/lib/module/SafeAreaView.js +176 -0
- package/lib/module/SafeAreaView.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaContext.js +3 -0
- package/lib/module/specs/NativeSafeAreaContext.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaProvider.js +3 -0
- package/lib/module/specs/NativeSafeAreaProvider.js.map +1 -0
- package/lib/module/specs/NativeSafeAreaView.js +5 -0
- package/lib/module/specs/NativeSafeAreaView.js.map +1 -0
- package/lib/typescript/SafeArea.types.d.ts +36 -0
- package/lib/typescript/SafeArea.types.d.ts.map +1 -0
- package/lib/typescript/SafeAreaView.d.ts +6 -0
- package/lib/typescript/SafeAreaView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts +23 -0
- package/lib/typescript/specs/NativeSafeAreaContext.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts +22 -0
- package/lib/typescript/specs/NativeSafeAreaProvider.d.ts.map +1 -0
- package/lib/typescript/specs/NativeSafeAreaView.d.ts +24 -0
- package/lib/typescript/specs/NativeSafeAreaView.d.ts.map +1 -0
- package/package.json +139 -0
- package/src/SafeArea.types.ts +47 -0
- package/src/SafeAreaView.tsx +201 -0
- package/src/index.tsx +6 -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,128 @@
|
|
|
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
|
+
import {
|
|
26
|
+
Descriptor,
|
|
27
|
+
ComponentBuilderContext,
|
|
28
|
+
RNComponentFactory,
|
|
29
|
+
RNOHContext,
|
|
30
|
+
ViewRawProps,
|
|
31
|
+
ViewBaseProps,
|
|
32
|
+
ViewDescriptorWrapperBase,
|
|
33
|
+
RNViewManager,
|
|
34
|
+
ViewBaseDescriptor
|
|
35
|
+
} from '@rnoh/react-native-openharmony'
|
|
36
|
+
|
|
37
|
+
import { SafeAreaViewTurboModule } from "./SafeViewTurboModule"
|
|
38
|
+
import { Event, Tag } from './common/SafeAreaType';
|
|
39
|
+
import Logger from './Logger'
|
|
40
|
+
import { SafeAreaProviderModifier } from './SafeAreaProviderModifier'
|
|
41
|
+
|
|
42
|
+
export const SAFE_AREA_PROVIDER_TYPE: string = "RNCSafeAreaProvider"
|
|
43
|
+
|
|
44
|
+
export interface SafeAreaProviderProps extends ViewBaseProps {}
|
|
45
|
+
|
|
46
|
+
export interface SafeAreaProviderState {}
|
|
47
|
+
|
|
48
|
+
export interface SafeAreaProviderRawProps extends ViewRawProps {}
|
|
49
|
+
|
|
50
|
+
export type SafeAreaProviderDescriptor = Descriptor<"RNCSafeAreaProvider", SafeAreaProviderProps, SafeAreaProviderState, SafeAreaProviderRawProps>
|
|
51
|
+
|
|
52
|
+
export class SafeAreaProviderDescriptorWrapper extends ViewDescriptorWrapperBase<"RNCSafeAreaProvider", SafeAreaProviderProps, SafeAreaProviderState, SafeAreaProviderRawProps> {
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Component
|
|
56
|
+
export struct SafeAreaProvider {
|
|
57
|
+
ctx!: RNOHContext
|
|
58
|
+
tag: number = 0
|
|
59
|
+
@BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
|
|
60
|
+
private componentManager!: RNViewManager
|
|
61
|
+
@State descriptor: SafeAreaProviderDescriptor = {} as SafeAreaProviderDescriptor
|
|
62
|
+
@State descriptorWrapper: SafeAreaProviderDescriptorWrapper | undefined = undefined
|
|
63
|
+
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
64
|
+
private unregisterComponentManager?: () => void = undefined
|
|
65
|
+
|
|
66
|
+
onInsetsChange() {
|
|
67
|
+
const safeAreaViewTurboModule = this.ctx.rnInstance.getTurboModule<SafeAreaViewTurboModule>("RNCSafeAreaContext")
|
|
68
|
+
const safeAreaInsets = safeAreaViewTurboModule.getSafeAreaInsets();
|
|
69
|
+
safeAreaInsets.then((data: Event) => {
|
|
70
|
+
this.ctx.rnInstance.emitComponentEvent(this.descriptor.tag, SAFE_AREA_PROVIDER_TYPE, {
|
|
71
|
+
type: "onInsetsChange",
|
|
72
|
+
insets: data.insets,
|
|
73
|
+
frame: {
|
|
74
|
+
x: this.descriptor.layoutMetrics.frame.origin.x,
|
|
75
|
+
y: this.descriptor.layoutMetrics.frame.origin.y,
|
|
76
|
+
width: this.descriptor.layoutMetrics.frame.size.width,
|
|
77
|
+
height: this.descriptor.layoutMetrics.frame.size.height
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
aboutToAppear() {
|
|
84
|
+
this.descriptor = this.ctx.descriptorRegistry.getDescriptor<SafeAreaProviderDescriptor>(this.tag)
|
|
85
|
+
if (this.descriptor) {
|
|
86
|
+
this.setDescriptor(this.descriptor)
|
|
87
|
+
}
|
|
88
|
+
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
89
|
+
(newDescriptor) => {
|
|
90
|
+
this.setDescriptor(newDescriptor as SafeAreaProviderDescriptor)
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
this.initComponent();
|
|
94
|
+
this.onInsetsChange()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
aboutToDisappear() {
|
|
98
|
+
this.unregisterDescriptorChangesListener?.()
|
|
99
|
+
this.unregisterComponentManager?.()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
initComponent() {
|
|
103
|
+
if (!this.componentManager) {
|
|
104
|
+
this.componentManager = new RNViewManager(this.tag, this.ctx)
|
|
105
|
+
}
|
|
106
|
+
this.unregisterComponentManager = this.ctx.componentManagerRegistry.registerComponentManager(this.tag, this.componentManager)
|
|
107
|
+
const parentTag = this.descriptor.parentTag;
|
|
108
|
+
this.componentManager.setParentTag(parentTag);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private setDescriptor(descriptor: SafeAreaProviderDescriptor) {
|
|
112
|
+
this.descriptorWrapper = new SafeAreaProviderDescriptorWrapper(descriptor)
|
|
113
|
+
Logger.info('descriptorWrapper' + JSON.stringify(this.descriptorWrapper))
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
build() {
|
|
117
|
+
Stack() {
|
|
118
|
+
ForEach(this.descriptorWrapper?.childrenTags, (childrenTag: Tag) => {
|
|
119
|
+
RNComponentFactory({
|
|
120
|
+
ctx: this.ctx,
|
|
121
|
+
tag: childrenTag,
|
|
122
|
+
buildCustomComponent: this.buildCustomComponent
|
|
123
|
+
})
|
|
124
|
+
}, (tag: Tag) => tag.toString())
|
|
125
|
+
}
|
|
126
|
+
.attributeModifier(SafeAreaProviderModifier.getInstance().setDescriptor(this.descriptorWrapper))
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
import { TransformMatrix } from '@rnoh/react-native-openharmony';
|
|
26
|
+
import { SafeAreaProviderDescriptorWrapper } from './SafeAreaProvider';
|
|
27
|
+
import matrix4 from '@ohos.matrix4';
|
|
28
|
+
|
|
29
|
+
export class SafeAreaProviderModifier implements AttributeModifier<StackAttribute> {
|
|
30
|
+
private constructor() {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private static instance: SafeAreaProviderModifier;
|
|
34
|
+
protected descriptorWrapper: SafeAreaProviderDescriptorWrapper | undefined = undefined
|
|
35
|
+
|
|
36
|
+
public static getInstance(): SafeAreaProviderModifier {
|
|
37
|
+
if (!SafeAreaProviderModifier.instance) {
|
|
38
|
+
SafeAreaProviderModifier.instance = new SafeAreaProviderModifier();
|
|
39
|
+
}
|
|
40
|
+
return SafeAreaProviderModifier.instance;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setDescriptor(descriptorWrapper: SafeAreaProviderDescriptorWrapper | undefined): SafeAreaProviderModifier {
|
|
44
|
+
this.descriptorWrapper = descriptorWrapper;
|
|
45
|
+
return SafeAreaProviderModifier.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
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
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
|
+
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) 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
|
+
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,46 @@
|
|
|
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
|
+
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
|
+
|
|
29
|
+
class SafeAreaTurboModulesFactory extends TurboModulesFactory {
|
|
30
|
+
createTurboModule(name: string): TurboModule | null {
|
|
31
|
+
if (name === 'RNCSafeAreaContext') {
|
|
32
|
+
return new SafeAreaViewTurboModule(this.ctx);
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
hasTurboModule(name: string): boolean {
|
|
38
|
+
return name === 'RNCSafeAreaContext';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class SafeAreaViewPackage extends RNPackage {
|
|
43
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
44
|
+
return new SafeAreaTurboModulesFactory(ctx);
|
|
45
|
+
}
|
|
46
|
+
}
|