@react-native-ohos/react-native-safe-area-context 5.1.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +10 -0
  4. package/harmony/safe_area/LICENSE +21 -0
  5. package/harmony/safe_area/NOTICE +33 -0
  6. package/harmony/safe_area/README.md +270 -0
  7. package/harmony/safe_area/build-profile.json5 +9 -0
  8. package/harmony/safe_area/hvigorfile.ts +6 -0
  9. package/harmony/safe_area/index.ets +26 -0
  10. package/harmony/safe_area/oh-package.json5 +22 -0
  11. package/harmony/safe_area/src/main/cpp/CMakeLists.txt +9 -0
  12. package/harmony/safe_area/src/main/cpp/SafeAreaBeanData.h +56 -0
  13. package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.cpp +45 -0
  14. package/harmony/safe_area/src/main/cpp/SafeAreaColumnNode.h +38 -0
  15. package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.cpp +66 -0
  16. package/harmony/safe_area/src/main/cpp/SafeAreaManagerMap.h +57 -0
  17. package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.cpp +75 -0
  18. package/harmony/safe_area/src/main/cpp/SafeAreaProviderComponentInstance.h +49 -0
  19. package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.cpp +94 -0
  20. package/harmony/safe_area/src/main/cpp/SafeAreaStackNode.h +53 -0
  21. package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.cpp +94 -0
  22. package/harmony/safe_area/src/main/cpp/SafeAreaViewComponentInstance.h +64 -0
  23. package/harmony/safe_area/src/main/cpp/SafeAreaViewPackage.h +60 -0
  24. package/harmony/safe_area/src/main/cpp/TurboModuleRequest.cpp +63 -0
  25. package/harmony/safe_area/src/main/cpp/TurboModuleRequest.h +33 -0
  26. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/BaseReactNativeSafeAreaContextPackage.h +72 -0
  27. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaProviderComponentInstance.h +18 -0
  28. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/BaseRNCSafeAreaViewComponentInstance.h +18 -0
  29. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaProviderJSIBinder.h +27 -0
  30. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/components/RNCSafeAreaViewJSIBinder.h +30 -0
  31. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.cpp +16 -0
  32. package/harmony/safe_area/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCSafeAreaContext.h +16 -0
  33. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ComponentDescriptors.h +25 -0
  34. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.cpp +56 -0
  35. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/EventEmitters.h +59 -0
  36. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.cpp +36 -0
  37. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/Props.h +88 -0
  38. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.cpp +20 -0
  39. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/ShadowNodes.h +39 -0
  40. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.cpp +18 -0
  41. package/harmony/safe_area/src/main/cpp/generated/react/renderer/components/react_native_safe_area_context/States.h +23 -0
  42. package/harmony/safe_area/src/main/ets/Logger.ts +64 -0
  43. package/harmony/safe_area/src/main/ets/SafeAreaProvider.ets +128 -0
  44. package/harmony/safe_area/src/main/ets/SafeAreaProviderModifier.ets +121 -0
  45. package/harmony/safe_area/src/main/ets/SafeAreaView.ets +242 -0
  46. package/harmony/safe_area/src/main/ets/SafeAreaViewModifier.ets +140 -0
  47. package/harmony/safe_area/src/main/ets/SafeAreaViewPackage.ts +46 -0
  48. package/harmony/safe_area/src/main/ets/SafeViewTurboModule.ts +131 -0
  49. package/harmony/safe_area/src/main/ets/common/SafeAreaType.ts +70 -0
  50. package/harmony/safe_area/src/main/module.json5 +7 -0
  51. package/harmony/safe_area/src/main/resources/base/element/string.json +8 -0
  52. package/harmony/safe_area/src/main/resources/en_US/element/string.json +8 -0
  53. package/harmony/safe_area/src/main/resources/zh_CN/element/string.json +8 -0
  54. package/harmony/safe_area/ts.ts +26 -0
  55. package/harmony/safe_area.har +0 -0
  56. package/lib/commonjs/SafeArea.types.js +6 -0
  57. package/lib/commonjs/SafeArea.types.js.map +1 -0
  58. package/lib/commonjs/SafeAreaView.js +184 -0
  59. package/lib/commonjs/SafeAreaView.js.map +1 -0
  60. package/lib/commonjs/index.js +51 -0
  61. package/lib/commonjs/index.js.map +1 -0
  62. package/lib/commonjs/specs/NativeSafeAreaContext.js +9 -0
  63. package/lib/commonjs/specs/NativeSafeAreaContext.js.map +1 -0
  64. package/lib/commonjs/specs/NativeSafeAreaProvider.js +10 -0
  65. package/lib/commonjs/specs/NativeSafeAreaProvider.js.map +1 -0
  66. package/lib/commonjs/specs/NativeSafeAreaView.js +12 -0
  67. package/lib/commonjs/specs/NativeSafeAreaView.js.map +1 -0
  68. package/lib/module/SafeArea.types.js +2 -0
  69. package/lib/module/SafeArea.types.js.map +1 -0
  70. package/lib/module/SafeAreaView.js +176 -0
  71. package/lib/module/SafeAreaView.js.map +1 -0
  72. package/lib/module/index.js +7 -0
  73. package/lib/module/index.js.map +1 -0
  74. package/lib/module/specs/NativeSafeAreaContext.js +3 -0
  75. package/lib/module/specs/NativeSafeAreaContext.js.map +1 -0
  76. package/lib/module/specs/NativeSafeAreaProvider.js +3 -0
  77. package/lib/module/specs/NativeSafeAreaProvider.js.map +1 -0
  78. package/lib/module/specs/NativeSafeAreaView.js +5 -0
  79. package/lib/module/specs/NativeSafeAreaView.js.map +1 -0
  80. package/lib/typescript/SafeArea.types.d.ts +36 -0
  81. package/lib/typescript/SafeArea.types.d.ts.map +1 -0
  82. package/lib/typescript/SafeAreaView.d.ts +6 -0
  83. package/lib/typescript/SafeAreaView.d.ts.map +1 -0
  84. package/lib/typescript/index.d.ts +5 -0
  85. package/lib/typescript/index.d.ts.map +1 -0
  86. package/lib/typescript/specs/NativeSafeAreaContext.d.ts +23 -0
  87. package/lib/typescript/specs/NativeSafeAreaContext.d.ts.map +1 -0
  88. package/lib/typescript/specs/NativeSafeAreaProvider.d.ts +22 -0
  89. package/lib/typescript/specs/NativeSafeAreaProvider.d.ts.map +1 -0
  90. package/lib/typescript/specs/NativeSafeAreaView.d.ts +24 -0
  91. package/lib/typescript/specs/NativeSafeAreaView.d.ts.map +1 -0
  92. package/package.json +139 -0
  93. package/src/SafeArea.types.ts +47 -0
  94. package/src/SafeAreaView.tsx +201 -0
  95. package/src/index.tsx +6 -0
  96. package/src/specs/NativeSafeAreaContext.ts +23 -0
  97. package/src/specs/NativeSafeAreaProvider.ts +29 -0
  98. package/src/specs/NativeSafeAreaView.ts +28 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #ifndef HARMONY_SAFEAREAMANAGERMAP_H
26
+ #define HARMONY_SAFEAREAMANAGERMAP_H
27
+
28
+ #include <arkui/native_type.h>
29
+ #include <unordered_map>
30
+
31
+ class SafeAreaManagerMap {
32
+
33
+ private:
34
+
35
+ SafeAreaManagerMap();
36
+
37
+ SafeAreaManagerMap(const SafeAreaManagerMap &) = delete;
38
+
39
+ SafeAreaManagerMap &operator=(const SafeAreaManagerMap &) = delete;
40
+
41
+ SafeAreaManagerMap(SafeAreaManagerMap &&) = delete;
42
+
43
+ SafeAreaManagerMap &operator=(SafeAreaManagerMap &&) = delete;
44
+
45
+ std::unordered_map<ArkUI_NodeHandle, bool> hasSafeAreaProviderMap_;
46
+
47
+ public:
48
+ static SafeAreaManagerMap &getInstance();
49
+
50
+ void SetHasSafeAreaProviderByNodeHandle(ArkUI_NodeHandle nodeHandle, bool isHasSafeAreaProvider);
51
+
52
+ bool GetHasSafeAreaProviderByNodeHandle(ArkUI_NodeHandle nodeHandle);
53
+
54
+ void RemoveSafeAreaProviderByNodeHandle(ArkUI_NodeHandle nodeHandle);
55
+ };
56
+
57
+ #endif //HARMONY_SAFEAREAMANAGERMAP_H
@@ -0,0 +1,75 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include <sys/param.h>
26
+ #include "SafeAreaProviderComponentInstance.h"
27
+ #include "TurboModuleRequest.h"
28
+ #include "SafeAreaManagerMap.h"
29
+
30
+ namespace rnoh {
31
+
32
+ SafeAreaProviderComponentInstance::SafeAreaProviderComponentInstance(Context context)
33
+ : BaseRNCSafeAreaProviderComponentInstance(std::move(context)) {
34
+ SafeAreaManagerMap::getInstance().SetHasSafeAreaProviderByNodeHandle(m_stackNode.getArkUINodeHandle(), true);
35
+ }
36
+
37
+ void SafeAreaProviderComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
38
+ std::size_t index) {
39
+ super::onChildInserted(childComponentInstance, index);
40
+ m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
41
+ }
42
+
43
+ void SafeAreaProviderComponentInstance::onChildRemoved(ComponentInstance::Shared const &childComponentInstance) {
44
+ super::onChildRemoved(childComponentInstance);
45
+ m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
46
+ };
47
+
48
+ SafeAreaStackNode &SafeAreaProviderComponentInstance::getLocalRootArkUINode() { return m_stackNode; }
49
+
50
+ void SafeAreaProviderComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
51
+ super::onPropsChanged(props);
52
+ }
53
+
54
+ void SafeAreaProviderComponentInstance::onEventEmitterChanged(SharedConcreteEventEmitter const &eventEmitter) {
55
+ auto newEventEmitter = std::dynamic_pointer_cast<const ConcreteEventEmitter>(eventEmitter);
56
+ if (!newEventEmitter) {
57
+ return;
58
+ }
59
+ TurboModuleRequest request;
60
+ safeArea::Event data = request.getTurboModuleData(this->m_deps);
61
+ double x = getLayoutMetrics().frame.origin.x;
62
+ double y = getLayoutMetrics().frame.origin.y;
63
+ double width = getLayoutMetrics().frame.size.width;
64
+ double height = getLayoutMetrics().frame.size.height;
65
+ double providerTop = MAX(data.insets.top - y, 0);
66
+ double providerRight = MAX(MIN(x + width - data.frame.width, 0) + data.insets.right, 0);
67
+ double providerBottom = MAX(MIN(y + height - data.frame.height, 0) + data.insets.bottom, 0);
68
+ double providerLeft = MAX(data.insets.left - x, 0);
69
+ facebook::react::RNCSafeAreaProviderEventEmitter::OnInsetsChangeInsets insets = {providerTop, providerRight,
70
+ providerBottom, providerLeft};
71
+ facebook::react::RNCSafeAreaProviderEventEmitter::OnInsetsChangeFrame frame = {x, y, width, height};
72
+ facebook::react::RNCSafeAreaProviderEventEmitter::OnInsetsChange insetsChange = {insets, frame};
73
+ newEventEmitter->onInsetsChange(insetsChange);
74
+ }
75
+ } // namespace rnoh
@@ -0,0 +1,49 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #pragma once
25
+ #include "RNOH/CppComponentInstance.h"
26
+ #include "SafeAreaStackNode.h"
27
+ #include "generated/RNOH/generated/components/BaseRNCSafeAreaProviderComponentInstance.h"
28
+ #include "generated/react/renderer/components/react_native_safe_area_context/EventEmitters.h"
29
+ namespace rnoh {
30
+ class SafeAreaProviderComponentInstance : public BaseRNCSafeAreaProviderComponentInstance {
31
+
32
+ using super = BaseRNCSafeAreaProviderComponentInstance;
33
+
34
+ private:
35
+ SafeAreaStackNode m_stackNode;
36
+ public:
37
+ SafeAreaProviderComponentInstance(Context context);
38
+
39
+ void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
40
+
41
+ void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;
42
+
43
+ SafeAreaStackNode &getLocalRootArkUINode() override;
44
+
45
+ void onPropsChanged(SharedConcreteProps const &props) override;
46
+
47
+ void onEventEmitterChanged(SharedConcreteEventEmitter const &eventEmitter) override;
48
+ };
49
+ } // namespace rnoh
@@ -0,0 +1,94 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #include "SafeAreaStackNode.h"
25
+
26
+ #include <glog/logging.h>
27
+ #include <memory>
28
+ #include "RNOH/arkui/NativeNodeApi.h"
29
+ #include "SafeAreaManagerMap.h"
30
+
31
+ namespace rnoh {
32
+
33
+ SafeAreaStackNode::SafeAreaStackNode()
34
+ : ArkUINode(NativeNodeApi::getInstance()->createNode(
35
+ ArkUI_NodeType::ARKUI_NODE_STACK)),
36
+ m_stackNodeDelegate(nullptr) {
37
+ maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(
38
+ m_nodeHandle, NODE_ON_CLICK, NODE_ON_CLICK, this));
39
+ maybeThrow(NativeNodeApi::getInstance()->registerNodeEvent(
40
+ m_nodeHandle, NODE_EVENT_ON_APPEAR, NODE_EVENT_ON_APPEAR, this));
41
+ }
42
+
43
+ void SafeAreaStackNode::insertChild(ArkUINode& child, std::size_t index) {
44
+ maybeThrow(NativeNodeApi::getInstance()->insertChildAt(
45
+ m_nodeHandle, child.getArkUINodeHandle(), static_cast<int32_t>(index)));
46
+ }
47
+
48
+ void SafeAreaStackNode::removeChild(ArkUINode& child) {
49
+ maybeThrow(NativeNodeApi::getInstance()->removeChild(
50
+ m_nodeHandle, child.getArkUINodeHandle()));
51
+ }
52
+
53
+ void SafeAreaStackNode::setStackNodeDelegate(SafeAreaStackNodeDelegate* SafeAreaStackNodeDelegate) {
54
+ m_stackNodeDelegate = SafeAreaStackNodeDelegate;
55
+ }
56
+
57
+ void SafeAreaStackNode::onNodeEvent(
58
+ ArkUI_NodeEventType eventType,
59
+ EventArgs& eventArgs) {
60
+ if (eventType == ArkUI_NodeEventType::NODE_ON_CLICK &&
61
+ eventArgs[3].i32 != 2) {
62
+ onClick();
63
+ }
64
+
65
+ if (eventType == ArkUI_NodeEventType::NODE_EVENT_ON_APPEAR) {
66
+ if(m_stackNodeDelegate != nullptr) {
67
+ m_stackNodeDelegate->onAppear();
68
+ }
69
+ }
70
+
71
+ }
72
+
73
+ void SafeAreaStackNode::onClick() {
74
+ if (m_stackNodeDelegate != nullptr) {
75
+ m_stackNodeDelegate->onClick();
76
+ }
77
+ }
78
+
79
+ SafeAreaStackNode::~SafeAreaStackNode() {
80
+ NativeNodeApi::getInstance()->unregisterNodeEvent(
81
+ m_nodeHandle, NODE_ON_CLICK);
82
+ NativeNodeApi::getInstance()->unregisterNodeEvent(
83
+ m_nodeHandle, NODE_EVENT_ON_APPEAR);
84
+ SafeAreaManagerMap::getInstance().RemoveSafeAreaProviderByNodeHandle(m_nodeHandle);
85
+ }
86
+
87
+ SafeAreaStackNode& SafeAreaStackNode::setAlign(int32_t align) {
88
+ ArkUI_NumberValue value[] = {{.i32 = align}};
89
+ ArkUI_AttributeItem item = {.value = value, .size = 1};
90
+ maybeThrow(NativeNodeApi::getInstance()->setAttribute(
91
+ m_nodeHandle, NODE_STACK_ALIGN_CONTENT, &item));
92
+ return *this;
93
+ }
94
+ } // namespace rnoh
@@ -0,0 +1,53 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #pragma once
25
+
26
+ #include "RNOH/arkui/ArkUINode.h"
27
+
28
+ namespace rnoh {
29
+ class SafeAreaStackNodeDelegate {
30
+ public:
31
+ virtual ~SafeAreaStackNodeDelegate() = default;
32
+ virtual void onClick() {};
33
+ virtual void onAppear(){};
34
+ };
35
+
36
+ class SafeAreaStackNode : public ArkUINode {
37
+ protected:
38
+ SafeAreaStackNodeDelegate* m_stackNodeDelegate;
39
+
40
+ public:
41
+ SafeAreaStackNode();
42
+ ~SafeAreaStackNode() override;
43
+
44
+ void insertChild(ArkUINode& child, std::size_t index);
45
+ void removeChild(ArkUINode& child);
46
+ void onNodeEvent(ArkUI_NodeEventType eventType, EventArgs& eventArgs)
47
+ override;
48
+ void onClick();
49
+ void setStackNodeDelegate(SafeAreaStackNodeDelegate* safeAreaStackNodeDelegate);
50
+ SafeAreaStackNode& setAlign(int32_t align);
51
+ };
52
+
53
+ } // namespace rnoh
@@ -0,0 +1,94 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #include "SafeAreaViewComponentInstance.h"
25
+ #include "TurboModuleRequest.h"
26
+ #include "SafeAreaManagerMap.h"
27
+
28
+ namespace rnoh {
29
+
30
+ SafeAreaViewComponentInstance::SafeAreaViewComponentInstance(Context context)
31
+ : BaseRNCSafeAreaViewComponentInstance(std::move(context)) {
32
+ m_safeAreaViewStackNode.setStackNodeDelegate(this);
33
+ }
34
+
35
+ void SafeAreaViewComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
36
+ std::size_t index) {
37
+ super::onChildInserted(childComponentInstance, index);
38
+ m_safeAreaViewStackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
39
+ }
40
+
41
+ void SafeAreaViewComponentInstance::onChildRemoved(ComponentInstance::Shared const &childComponentInstance) {
42
+ super::onChildRemoved(childComponentInstance);
43
+ m_safeAreaViewStackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
44
+ };
45
+
46
+ SafeAreaStackNode &SafeAreaViewComponentInstance::getLocalRootArkUINode() { return m_safeAreaViewStackNode; }
47
+
48
+ void SafeAreaViewComponentInstance::updateInsert(SharedConcreteProps p) {
49
+ auto parentNodeHandle = findParentNodeHandle(m_safeAreaViewStackNode.getArkUINodeHandle());
50
+ DLOG(INFO) << "SafeAreaViewComponentInstance findParentNodeHandle " << parentNodeHandle.nodeHandle << " hasSafeAreaProvider " << parentNodeHandle.hasSafeAreaProvider;
51
+ if (parentNodeHandle.hasSafeAreaProvider) {
52
+ TurboModuleRequest request;
53
+ safeArea::Event data = request.getTurboModuleData(this->m_deps);
54
+ facebook::react::RNCSafeAreaViewEventEmitter::OnSafeAreaValueChange inset = {data.insets.top, data.insets.right,
55
+ data.insets.bottom, data.insets.left};
56
+ m_eventEmitter->onSafeAreaValueChange(inset);
57
+ }
58
+ else {
59
+ facebook::react::RNCSafeAreaViewEventEmitter::OnSafeAreaValueChange inset = {0, 0, 0, 0};
60
+ m_eventEmitter->onSafeAreaValueChange(inset);
61
+ }
62
+ }
63
+
64
+ SafeAreaViewComponentInstance::ParentNodeInfo SafeAreaViewComponentInstance::findParentNodeHandle(ArkUI_NodeHandle nodehandle) {
65
+ ParentNodeInfo parentNodeInfo;
66
+ if(!nodehandle) return parentNodeInfo;
67
+ auto parentNode = OH_ArkUI_NodeUtils_GetParentInPageTree(nodehandle);
68
+ bool hasSafeAreaProvider = SafeAreaManagerMap::getInstance().GetHasSafeAreaProviderByNodeHandle(parentNode);
69
+ parentNodeInfo.hasSafeAreaProvider = hasSafeAreaProvider;
70
+ parentNodeInfo.nodeHandle = parentNode;
71
+ if (!hasSafeAreaProvider && parentNode) {
72
+ return findParentNodeHandle(parentNode);
73
+ }
74
+ return parentNodeInfo;
75
+ }
76
+
77
+ void SafeAreaViewComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
78
+ super::onPropsChanged(props);
79
+ this->m_SharedConcreteProps = props;
80
+ if(this->m_isFirstShow) {
81
+ return;
82
+ }
83
+ updateInsert(props);
84
+ }
85
+
86
+ void SafeAreaViewComponentInstance::onAppear(){
87
+ if(this->m_isFirstShow && this->m_SharedConcreteProps) {
88
+ updateInsert(this->m_SharedConcreteProps);
89
+ this->m_isFirstShow = false;
90
+ }
91
+ }
92
+
93
+
94
+ } // namespace rnoh
@@ -0,0 +1,64 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #pragma once
25
+ #include "RNOH/CppComponentInstance.h"
26
+ #include "SafeAreaBeanData.h"
27
+ #include "SafeAreaColumnNode.h"
28
+ #include "SafeAreaStackNode.h"
29
+ #include "SafeAreaProviderComponentInstance.h"
30
+ #include "generated/RNOH/generated/components/BaseRNCSafeAreaViewComponentInstance.h"
31
+ #include "generated/react/renderer/components/react_native_safe_area_context/EventEmitters.h"
32
+
33
+ namespace rnoh {
34
+ class SafeAreaViewComponentInstance : public BaseRNCSafeAreaViewComponentInstance,SafeAreaStackNodeDelegate {
35
+
36
+ using super = BaseRNCSafeAreaViewComponentInstance;
37
+
38
+ struct ParentNodeInfo {
39
+ ArkUI_NodeHandle nodeHandle = nullptr;
40
+ bool hasSafeAreaProvider = false;
41
+ };
42
+
43
+ private:
44
+ SafeAreaStackNode m_safeAreaViewStackNode;
45
+ bool m_isFirstShow = true;
46
+ SharedConcreteProps m_SharedConcreteProps;
47
+ public:
48
+ SafeAreaViewComponentInstance(Context context);
49
+
50
+ void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
51
+
52
+ void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;
53
+
54
+ void onPropsChanged(SharedConcreteProps const &props) override;
55
+
56
+ SafeAreaStackNode &getLocalRootArkUINode() override;
57
+
58
+ void updateInsert(SharedConcreteProps p);
59
+
60
+ void onAppear() override;
61
+
62
+ ParentNodeInfo findParentNodeHandle(ArkUI_NodeHandle nodehandle);
63
+ };
64
+ } // namespace rnoh
@@ -0,0 +1,60 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "RNOH/Package.h"
26
+ #include "generated/RNOH/generated/BaseReactNativeSafeAreaContextPackage.h"
27
+ #include "SafeAreaViewComponentInstance.h"
28
+ #include "SafeAreaProviderComponentInstance.h"
29
+
30
+ using namespace rnoh;
31
+ using namespace facebook;
32
+
33
+ namespace rnoh {
34
+
35
+ class SafeAreaPackageComponentInstanceFactoryDelegate : public ComponentInstanceFactoryDelegate {
36
+ public:
37
+ using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
38
+
39
+ ComponentInstance::Shared create(ComponentInstance::Context ctx) override {
40
+ if (ctx.componentName == "RNCSafeAreaProvider") {
41
+ return std::make_shared<SafeAreaProviderComponentInstance>(std::move(ctx));
42
+ } else if (ctx.componentName == "RNCSafeAreaView") {
43
+ return std::make_shared<SafeAreaViewComponentInstance>(std::move(ctx));
44
+ }
45
+ return nullptr;
46
+ }
47
+ };
48
+
49
+ class SafeAreaViewPackage : public BaseReactNativeSafeAreaContextPackage {
50
+ using Super = BaseReactNativeSafeAreaContextPackage;
51
+
52
+ public:
53
+ SafeAreaViewPackage(Package::Context ctx) : Super(ctx) {}
54
+
55
+ ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate() override {
56
+ return std::make_shared<SafeAreaPackageComponentInstanceFactoryDelegate>();
57
+ }
58
+
59
+ };
60
+ } // namespace rnoh
@@ -0,0 +1,63 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2025 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "TurboModuleRequest.h"
26
+
27
+ safeArea::Event TurboModuleRequest::getTurboModuleData(rnoh::ComponentInstance::Dependencies::Shared deps) {
28
+ safeArea::Event data = {{0, 0, 0, 0}, {0, 0, 0, 0}};
29
+ auto rnInstancePtr = deps->rnInstance.lock();
30
+ folly::dynamic result1;
31
+ if (rnInstancePtr != nullptr) {
32
+ auto turboModule = rnInstancePtr->getTurboModule("RNCSafeAreaContext");
33
+ auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
34
+ result1 = arkTsTurboModule->callSync("getConstants", {});
35
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: x:"
36
+ << result1["initialWindowMetrics"]["frame"]["x"].asDouble();
37
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: y:"
38
+ << result1["initialWindowMetrics"]["frame"]["y"].asDouble();
39
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: width:"
40
+ << result1["initialWindowMetrics"]["frame"]["width"].asDouble();
41
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: height:"
42
+ << result1["initialWindowMetrics"]["frame"]["height"].asDouble();
43
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: top:"
44
+ << result1["initialWindowMetrics"]["insets"]["top"].asDouble();
45
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: right:"
46
+ << result1["initialWindowMetrics"]["insets"]["right"].asDouble();
47
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: bottom:"
48
+ << result1["initialWindowMetrics"]["insets"]["bottom"].asDouble();
49
+ DLOG(INFO) << "[safeArea] <SafeAreaViewComponentInstance::setProps> initialWindowMetrics: left:"
50
+ << result1["initialWindowMetrics"]["insets"]["left"].asDouble();
51
+ double_t frameX = result1["initialWindowMetrics"]["frame"]["x"].asDouble();
52
+ double_t frameY = result1["initialWindowMetrics"]["frame"]["y"].asDouble();
53
+ double_t frameWidth = result1["initialWindowMetrics"]["frame"]["width"].asDouble();
54
+ double_t frameHeight = result1["initialWindowMetrics"]["frame"]["height"].asDouble();
55
+ double_t insetsTop = result1["initialWindowMetrics"]["insets"]["top"].asDouble();
56
+ double_t insetsRight = result1["initialWindowMetrics"]["insets"]["right"].asDouble();
57
+ double_t insetsBottom = result1["initialWindowMetrics"]["insets"]["bottom"].asDouble();
58
+ double_t insetsLeft = result1["initialWindowMetrics"]["insets"]["left"].asDouble();
59
+
60
+ data = {{insetsTop, insetsRight, insetsBottom, insetsLeft}, {frameX, frameY, frameWidth, frameHeight}};
61
+ }
62
+ return data;
63
+ };
@@ -0,0 +1,33 @@
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
+ #ifndef HARMONY_TURBOMODULEREQUEST_H
25
+ #define HARMONY_TURBOMODULEREQUEST_H
26
+ #include "RNOH/CppComponentInstance.h"
27
+ #include "SafeAreaBeanData.h"
28
+ class TurboModuleRequest {
29
+ public:
30
+ safeArea::Event getTurboModuleData(rnoh::ComponentInstance::Dependencies::Shared deps);
31
+ };
32
+
33
+ #endif // HARMONY_TURBOMODULEREQUEST_H