@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,62 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateEventEmitterH.js
|
|
9
|
+
*/
|
|
10
|
+
#ifndef SAFEAREAVIEWEVENTEMITTERS_H
|
|
11
|
+
#define SAFEAREAVIEWEVENTEMITTERS_H
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace facebook {
|
|
18
|
+
namespace react {
|
|
19
|
+
class RNCSafeAreaViewEventEmitter : public ViewEventEmitter {
|
|
20
|
+
public:
|
|
21
|
+
using ViewEventEmitter::ViewEventEmitter;
|
|
22
|
+
|
|
23
|
+
struct OnSafeAreaValueChangeSafeAreaViewInsetsValue {
|
|
24
|
+
Float top;
|
|
25
|
+
Float left;
|
|
26
|
+
Float bottom;
|
|
27
|
+
Float right;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
struct OnSafeAreaValueChange {
|
|
31
|
+
OnSafeAreaValueChangeSafeAreaViewInsetsValue safeAreaViewInsetsValue;
|
|
32
|
+
};
|
|
33
|
+
void onSafeAreaValueChange(OnSafeAreaValueChange value) const;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
class RNCSafeAreaProviderEventEmitter : public ViewEventEmitter {
|
|
37
|
+
public:
|
|
38
|
+
using ViewEventEmitter::ViewEventEmitter;
|
|
39
|
+
|
|
40
|
+
struct OnInsetsChangeInsets {
|
|
41
|
+
double top;
|
|
42
|
+
double right;
|
|
43
|
+
double bottom;
|
|
44
|
+
double left;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
struct OnInsetsChangeFrame {
|
|
48
|
+
double x;
|
|
49
|
+
double y;
|
|
50
|
+
double width;
|
|
51
|
+
double height;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
struct OnInsetsChange {
|
|
55
|
+
OnInsetsChangeInsets insets;
|
|
56
|
+
OnInsetsChangeFrame frame;
|
|
57
|
+
};
|
|
58
|
+
void onInsetsChange(OnInsetsChange value) const;
|
|
59
|
+
};
|
|
60
|
+
} // namespace react
|
|
61
|
+
} // namespace facebook
|
|
62
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GeneratePropsCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include <react/renderer/components/react_native_safe_area_context/Props.h>
|
|
12
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
13
|
+
#include <react/renderer/core/propsConversions.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook {
|
|
16
|
+
namespace react {
|
|
17
|
+
|
|
18
|
+
RNCSafeAreaViewProps::RNCSafeAreaViewProps(
|
|
19
|
+
const PropsParserContext &context,
|
|
20
|
+
const RNCSafeAreaViewProps &sourceProps,
|
|
21
|
+
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
|
|
22
|
+
|
|
23
|
+
mode(convertRawProp(context, rawProps, "mode", sourceProps.mode, {RNCSafeAreaViewMode::Padding})),
|
|
24
|
+
edges(convertRawProp(context, rawProps, "edges", sourceProps.edges, {})),
|
|
25
|
+
isFirstRefresh(convertRawProp(context, rawProps, "isFirstRefresh", sourceProps.isFirstRefresh, {false}))
|
|
26
|
+
{}
|
|
27
|
+
RNCSafeAreaProviderProps::RNCSafeAreaProviderProps(
|
|
28
|
+
const PropsParserContext &context,
|
|
29
|
+
const RNCSafeAreaProviderProps &sourceProps,
|
|
30
|
+
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps)
|
|
31
|
+
{}
|
|
32
|
+
} // namespace react
|
|
33
|
+
} // namespace facebook
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GeneratePropsH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
13
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
14
|
+
#include <react/renderer/core/propsConversions.h>
|
|
15
|
+
|
|
16
|
+
namespace facebook {
|
|
17
|
+
namespace react {
|
|
18
|
+
|
|
19
|
+
enum class RNCSafeAreaViewMode { Padding, Margin };
|
|
20
|
+
|
|
21
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, RNCSafeAreaViewMode &result)
|
|
22
|
+
{
|
|
23
|
+
auto string = (std::string)value;
|
|
24
|
+
if (string == "padding") {
|
|
25
|
+
result = RNCSafeAreaViewMode::Padding;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (string == "margin") {
|
|
29
|
+
result = RNCSafeAreaViewMode::Margin;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
abort();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static inline std::string toString(const RNCSafeAreaViewMode &value)
|
|
36
|
+
{
|
|
37
|
+
switch (value) {
|
|
38
|
+
case RNCSafeAreaViewMode::Padding: return "padding";
|
|
39
|
+
case RNCSafeAreaViewMode::Margin: return "margin";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
struct RNCSafeAreaViewEdgesStruct {
|
|
43
|
+
std::string top;
|
|
44
|
+
std::string right;
|
|
45
|
+
std::string bottom;
|
|
46
|
+
std::string left;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static inline void fromRawValue(const PropsParserContext& context,
|
|
50
|
+
const RawValue &value, RNCSafeAreaViewEdgesStruct &result)
|
|
51
|
+
{
|
|
52
|
+
auto map = (butter::map<std::string, RawValue>)value;
|
|
53
|
+
auto tmp_top = map.find("top");
|
|
54
|
+
if (tmp_top != map.end()) {
|
|
55
|
+
fromRawValue(context, tmp_top->second, result.top);
|
|
56
|
+
}
|
|
57
|
+
auto tmp_right = map.find("right");
|
|
58
|
+
if (tmp_right != map.end()) {
|
|
59
|
+
fromRawValue(context, tmp_right->second, result.right);
|
|
60
|
+
}
|
|
61
|
+
auto tmp_bottom = map.find("bottom");
|
|
62
|
+
if (tmp_bottom != map.end()) {
|
|
63
|
+
fromRawValue(context, tmp_bottom->second, result.bottom);
|
|
64
|
+
}
|
|
65
|
+
auto tmp_left = map.find("left");
|
|
66
|
+
if (tmp_left != map.end()) {
|
|
67
|
+
fromRawValue(context, tmp_left->second, result.left);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static inline std::string toString(const RNCSafeAreaViewEdgesStruct &value)
|
|
72
|
+
{
|
|
73
|
+
return "[Object RNCSafeAreaViewEdgesStruct]";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class RNCSafeAreaViewProps final : public ViewProps {
|
|
77
|
+
public:
|
|
78
|
+
RNCSafeAreaViewProps() = default;
|
|
79
|
+
RNCSafeAreaViewProps(const PropsParserContext& context,
|
|
80
|
+
const RNCSafeAreaViewProps &sourceProps, const RawProps &rawProps);
|
|
81
|
+
|
|
82
|
+
#pragma mark - Props
|
|
83
|
+
|
|
84
|
+
RNCSafeAreaViewMode mode{RNCSafeAreaViewMode::Padding};
|
|
85
|
+
RNCSafeAreaViewEdgesStruct edges{};
|
|
86
|
+
bool isFirstRefresh{false};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
class RNCSafeAreaProviderProps final : public ViewProps {
|
|
90
|
+
public:
|
|
91
|
+
RNCSafeAreaProviderProps() = default;
|
|
92
|
+
RNCSafeAreaProviderProps(const PropsParserContext& context,
|
|
93
|
+
const RNCSafeAreaProviderProps &sourceProps,
|
|
94
|
+
const RawProps &rawProps);
|
|
95
|
+
|
|
96
|
+
#pragma mark - Props
|
|
97
|
+
};
|
|
98
|
+
} // namespace react
|
|
99
|
+
} // namespace facebook
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateShadowNodeCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include <react/renderer/components/react_native_safe_area_context/ShadowNodes.h>
|
|
12
|
+
|
|
13
|
+
namespace facebook {
|
|
14
|
+
namespace react {
|
|
15
|
+
const char RNCSafeAreaProviderComponentName[] = "RNCSafeAreaProvider";
|
|
16
|
+
const char RNCSafeAreaViewComponentName[] = "RNCSafeAreaView";
|
|
17
|
+
} // namespace react
|
|
18
|
+
} // namespace facebook
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateShadowNodeH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include <react/renderer/components/react_native_safe_area_context/EventEmitters.h>
|
|
14
|
+
#include <react/renderer/components/react_native_safe_area_context/Props.h>
|
|
15
|
+
#include <react/renderer/components/react_native_safe_area_context/States.h>
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <jsi/jsi.h>
|
|
18
|
+
|
|
19
|
+
namespace facebook {
|
|
20
|
+
namespace react {
|
|
21
|
+
JSI_EXPORT extern const char RNCSafeAreaProviderComponentName[32];
|
|
22
|
+
JSI_EXPORT extern const char RNCSafeAreaViewComponentName[32];
|
|
23
|
+
using RNCSafeAreaProviderShadowNode =
|
|
24
|
+
ConcreteViewShadowNode<RNCSafeAreaProviderComponentName,
|
|
25
|
+
RNCSafeAreaProviderProps, RNCSafeAreaProviderEventEmitter>;
|
|
26
|
+
using RNCSafeAreaViewShadowNode = ConcreteViewShadowNode<RNCSafeAreaViewComponentName, RNCSafeAreaViewProps,
|
|
27
|
+
RNCSafeAreaViewEventEmitter>;
|
|
28
|
+
} // namespace react
|
|
29
|
+
} // namespace facebook
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateStateCpp.js
|
|
9
|
+
*/
|
|
10
|
+
#include <react/renderer/components/react_native_safe_area_context/States.h>
|
|
11
|
+
|
|
12
|
+
namespace facebook {
|
|
13
|
+
namespace react {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateStateH.js
|
|
8
|
+
*/
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#ifdef ANDROID
|
|
12
|
+
#include <folly/dynamic.h>
|
|
13
|
+
#include <react/renderer/mapbuffer/MapBuffer.h>
|
|
14
|
+
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
namespace facebook {
|
|
18
|
+
namespace react {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 hilog from '@ohos.hilog';
|
|
26
|
+
|
|
27
|
+
class Logger {
|
|
28
|
+
private domain: number;
|
|
29
|
+
private prefix: string;
|
|
30
|
+
private format: string = '%{public}s, %{public}s';
|
|
31
|
+
private isDebug: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param Prefix Identifies the log tag.
|
|
37
|
+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
|
38
|
+
*/
|
|
39
|
+
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
|
|
40
|
+
this.prefix = prefix;
|
|
41
|
+
this.domain = domain;
|
|
42
|
+
this.isDebug = isDebug;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
debug(...args: string[]): void {
|
|
46
|
+
if (this.isDebug) {
|
|
47
|
+
hilog.debug(this.domain, this.prefix, this.format, args);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
info(...args: string[]): void {
|
|
52
|
+
hilog.info(this.domain, this.prefix, this.format, args);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
warn(...args: string[]): void {
|
|
56
|
+
hilog.warn(this.domain, this.prefix, this.format, args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
error(...args: string[]): void {
|
|
60
|
+
hilog.error(this.domain, this.prefix, this.format, args);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default new Logger('[RNOH]SafeAreaProvider', 0xFF00, true)
|
|
@@ -0,0 +1,128 @@
|
|
|
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 {
|
|
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) 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 { 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
|
+
}
|