@react-native-ohos/react-native-keyboard-controller 1.12.8-beta.9

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 (251) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +19 -0
  4. package/harmony/keyboard_controller/BuildProfile.ets +17 -0
  5. package/harmony/keyboard_controller/Index.ets +30 -0
  6. package/harmony/keyboard_controller/ResourceTable.txt +9 -0
  7. package/harmony/keyboard_controller/build-profile.json5 +31 -0
  8. package/harmony/keyboard_controller/consumer-rules.txt +0 -0
  9. package/harmony/keyboard_controller/hvigorfile.ts +6 -0
  10. package/harmony/keyboard_controller/obfuscation-rules.txt +18 -0
  11. package/harmony/keyboard_controller/oh-package-lock.json5 +19 -0
  12. package/harmony/keyboard_controller/oh-package.json5 +11 -0
  13. package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
  14. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
  15. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +111 -0
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +98 -0
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +274 -0
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +101 -0
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +64 -0
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +85 -0
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +110 -0
  22. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +84 -0
  23. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +60 -0
  24. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +46 -0
  25. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +48 -0
  26. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +64 -0
  27. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +77 -0
  28. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +45 -0
  29. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +49 -0
  30. package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.cpp +186 -0
  31. package/harmony/keyboard_controller/src/main/cpp/ViewHierarchyNavigator.h +112 -0
  32. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +64 -0
  33. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +77 -0
  34. package/harmony/keyboard_controller/src/main/ets/Logger.ts +67 -0
  35. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +70 -0
  36. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +245 -0
  37. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +119 -0
  38. package/harmony/keyboard_controller/src/main/ets/Type.ts +62 -0
  39. package/harmony/keyboard_controller/src/main/module.json +29 -0
  40. package/harmony/keyboard_controller/src/main/module.json5 +11 -0
  41. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
  42. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
  43. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
  44. package/harmony/keyboard_controller/ts.ets +30 -0
  45. package/harmony/keyboard_controller.har +0 -0
  46. package/lib/commonjs/animated.js +188 -0
  47. package/lib/commonjs/animated.js.map +1 -0
  48. package/lib/commonjs/bindings.js +38 -0
  49. package/lib/commonjs/bindings.js.map +1 -0
  50. package/lib/commonjs/bindings.native.js +37 -0
  51. package/lib/commonjs/bindings.native.js.map +1 -0
  52. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +66 -0
  53. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
  54. package/lib/commonjs/components/KeyboardAvoidingView/index.js +102 -0
  55. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
  56. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +255 -0
  57. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
  58. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
  59. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  60. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
  61. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
  62. package/lib/commonjs/components/KeyboardStickyView/index.js +40 -0
  63. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
  64. package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
  65. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
  66. package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
  67. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
  68. package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
  69. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
  70. package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
  71. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
  72. package/lib/commonjs/components/KeyboardToolbar/index.js +152 -0
  73. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
  74. package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
  75. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
  76. package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
  77. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
  78. package/lib/commonjs/components/index.js +42 -0
  79. package/lib/commonjs/components/index.js.map +1 -0
  80. package/lib/commonjs/constants.js +27 -0
  81. package/lib/commonjs/constants.js.map +1 -0
  82. package/lib/commonjs/context.js +42 -0
  83. package/lib/commonjs/context.js.map +1 -0
  84. package/lib/commonjs/hooks/index.js +104 -0
  85. package/lib/commonjs/hooks/index.js.map +1 -0
  86. package/lib/commonjs/hooks/useWindowDimensions/index.android.js +29 -0
  87. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
  88. package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
  89. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
  90. package/lib/commonjs/index.js +116 -0
  91. package/lib/commonjs/index.js.map +1 -0
  92. package/lib/commonjs/internal.js +73 -0
  93. package/lib/commonjs/internal.js.map +1 -0
  94. package/lib/commonjs/monkey-patch.android.js +57 -0
  95. package/lib/commonjs/monkey-patch.android.js.map +1 -0
  96. package/lib/commonjs/monkey-patch.js +11 -0
  97. package/lib/commonjs/monkey-patch.js.map +1 -0
  98. package/lib/commonjs/reanimated.js +12 -0
  99. package/lib/commonjs/reanimated.js.map +1 -0
  100. package/lib/commonjs/reanimated.native.js +88 -0
  101. package/lib/commonjs/reanimated.native.js.map +1 -0
  102. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
  103. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  104. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
  105. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  106. package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
  107. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
  108. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
  109. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
  110. package/lib/commonjs/types.js +6 -0
  111. package/lib/commonjs/types.js.map +1 -0
  112. package/lib/commonjs/utils.js +9 -0
  113. package/lib/commonjs/utils.js.map +1 -0
  114. package/lib/module/animated.js +180 -0
  115. package/lib/module/animated.js.map +1 -0
  116. package/lib/module/bindings.js +32 -0
  117. package/lib/module/bindings.js.map +1 -0
  118. package/lib/module/bindings.native.js +31 -0
  119. package/lib/module/bindings.native.js.map +1 -0
  120. package/lib/module/components/KeyboardAvoidingView/hooks.js +59 -0
  121. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
  122. package/lib/module/components/KeyboardAvoidingView/index.js +95 -0
  123. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
  124. package/lib/module/components/KeyboardAwareScrollView/index.js +248 -0
  125. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
  126. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
  127. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  128. package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
  129. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
  130. package/lib/module/components/KeyboardStickyView/index.js +33 -0
  131. package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
  132. package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
  133. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
  134. package/lib/module/components/KeyboardToolbar/Button.js +62 -0
  135. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
  136. package/lib/module/components/KeyboardToolbar/colors.js +15 -0
  137. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
  138. package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
  139. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
  140. package/lib/module/components/KeyboardToolbar/index.js +140 -0
  141. package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
  142. package/lib/module/components/KeyboardToolbar/types.js +2 -0
  143. package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
  144. package/lib/module/components/hooks/useColorScheme.js +4 -0
  145. package/lib/module/components/hooks/useColorScheme.js.map +1 -0
  146. package/lib/module/components/index.js +5 -0
  147. package/lib/module/components/index.js.map +1 -0
  148. package/lib/module/constants.js +21 -0
  149. package/lib/module/constants.js.map +1 -0
  150. package/lib/module/context.js +35 -0
  151. package/lib/module/context.js.map +1 -0
  152. package/lib/module/hooks/index.js +68 -0
  153. package/lib/module/hooks/index.js.map +1 -0
  154. package/lib/module/hooks/useWindowDimensions/index.android.js +22 -0
  155. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
  156. package/lib/module/hooks/useWindowDimensions/index.js +2 -0
  157. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
  158. package/lib/module/index.js +10 -0
  159. package/lib/module/index.js.map +1 -0
  160. package/lib/module/internal.js +66 -0
  161. package/lib/module/internal.js.map +1 -0
  162. package/lib/module/monkey-patch.android.js +47 -0
  163. package/lib/module/monkey-patch.android.js.map +1 -0
  164. package/lib/module/monkey-patch.js +5 -0
  165. package/lib/module/monkey-patch.js.map +1 -0
  166. package/lib/module/reanimated.js +6 -0
  167. package/lib/module/reanimated.js.map +1 -0
  168. package/lib/module/reanimated.native.js +78 -0
  169. package/lib/module/reanimated.native.js.map +1 -0
  170. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
  171. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  172. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
  173. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  174. package/lib/module/specs/NativeKeyboardController.js +3 -0
  175. package/lib/module/specs/NativeKeyboardController.js.map +1 -0
  176. package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
  177. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
  178. package/lib/module/types.js +2 -0
  179. package/lib/module/types.js.map +1 -0
  180. package/lib/module/utils.js +2 -0
  181. package/lib/module/utils.js.map +1 -0
  182. package/lib/typescript/animated.d.ts +31 -0
  183. package/lib/typescript/bindings.d.ts +12 -0
  184. package/lib/typescript/bindings.native.d.ts +12 -0
  185. package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +6 -0
  186. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +50 -0
  187. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +25 -0
  188. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
  189. package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
  190. package/lib/typescript/components/KeyboardStickyView/index.d.ts +35 -0
  191. package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
  192. package/lib/typescript/components/KeyboardToolbar/Button.d.ts +15 -0
  193. package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
  194. package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
  195. package/lib/typescript/components/KeyboardToolbar/index.d.ts +50 -0
  196. package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
  197. package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
  198. package/lib/typescript/components/index.d.ts +8 -0
  199. package/lib/typescript/constants.d.ts +16 -0
  200. package/lib/typescript/context.d.ts +23 -0
  201. package/lib/typescript/hooks/index.d.ts +17 -0
  202. package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
  203. package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
  204. package/lib/typescript/index.d.ts +8 -0
  205. package/lib/typescript/internal.d.ts +30 -0
  206. package/lib/typescript/monkey-patch.android.d.ts +2 -0
  207. package/lib/typescript/monkey-patch.d.ts +2 -0
  208. package/lib/typescript/reanimated.d.ts +5 -0
  209. package/lib/typescript/reanimated.native.d.ts +7 -0
  210. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +53 -0
  211. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +10 -0
  212. package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
  213. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
  214. package/lib/typescript/types.d.ts +133 -0
  215. package/lib/typescript/utils.d.ts +1 -0
  216. package/package.json +178 -0
  217. package/react-native-keyboard-controller.podspec +61 -0
  218. package/src/animated.tsx +253 -0
  219. package/src/bindings.native.ts +57 -0
  220. package/src/bindings.ts +38 -0
  221. package/src/components/KeyboardAvoidingView/hooks.ts +58 -0
  222. package/src/components/KeyboardAvoidingView/index.tsx +156 -0
  223. package/src/components/KeyboardAwareScrollView/index.tsx +373 -0
  224. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
  225. package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
  226. package/src/components/KeyboardStickyView/index.tsx +57 -0
  227. package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
  228. package/src/components/KeyboardToolbar/Button.tsx +98 -0
  229. package/src/components/KeyboardToolbar/colors.native.ts +37 -0
  230. package/src/components/KeyboardToolbar/colors.ts +16 -0
  231. package/src/components/KeyboardToolbar/index.tsx +211 -0
  232. package/src/components/KeyboardToolbar/types.ts +40 -0
  233. package/src/components/hooks/useColorScheme.ts +5 -0
  234. package/src/components/index.ts +11 -0
  235. package/src/constants.ts +19 -0
  236. package/src/context.ts +65 -0
  237. package/src/hooks/index.ts +90 -0
  238. package/src/hooks/useWindowDimensions/index.android.ts +33 -0
  239. package/src/hooks/useWindowDimensions/index.ts +1 -0
  240. package/src/index.ts +21 -0
  241. package/src/internal.ts +84 -0
  242. package/src/monkey-patch.android.ts +44 -0
  243. package/src/monkey-patch.ts +4 -0
  244. package/src/reanimated.native.ts +132 -0
  245. package/src/reanimated.ts +29 -0
  246. package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -0
  247. package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -0
  248. package/src/specs/NativeKeyboardController.ts +19 -0
  249. package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
  250. package/src/types.ts +211 -0
  251. package/src/utils.ts +1 -0
@@ -0,0 +1,274 @@
1
+ /*
2
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3
+ */
4
+ /**
5
+ * MIT License
6
+ *
7
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #include "KeyboardControllerViewComponentInstance.h"
29
+ #include <folly/dynamic.h>
30
+ #include <iostream>
31
+ #include <arkui/native_interface_focus.h>
32
+
33
+ namespace rnoh {
34
+ using KeyboardControllerStatus = rnoh::KeyboardControllerStatus;
35
+ KeyboardControllerViewComponentInstance::KeyboardControllerViewComponentInstance(Context context)
36
+ : CppComponentInstance(std::move(context)), ArkTSMessageHub::Observer(m_deps->arkTSMessageHub) {
37
+ DLOG(INFO) << "KeyboardControllerViewComponentInstance";
38
+
39
+ m_customNode.setCustomNodeDelegate(this);
40
+ }
41
+ void KeyboardControllerViewComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
42
+ std::size_t index) {
43
+ CppComponentInstance::onChildInserted(childComponentInstance, index);
44
+ m_customNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index + 1);
45
+ DLOG(INFO) << "###111" << childComponentInstance->getComponentName();
46
+ findTextInputComponents(childComponentInstance);
47
+ }
48
+
49
+ void KeyboardControllerViewComponentInstance::onChildRemoved(ComponentInstance::Shared const &childComponentInstance) {
50
+ CppComponentInstance::onChildRemoved(childComponentInstance);
51
+ m_customNode.removeChild(childComponentInstance->getLocalRootArkUINode());
52
+ }
53
+
54
+ void KeyboardControllerViewComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
55
+ DLOG(INFO) << "###onPropsChanged" << props->enabled << props->statusBarTranslucent
56
+ << props->navigationBarTranslucent;
57
+ CppComponentInstance::onPropsChanged(props);
58
+ if (this->enabled != props->enabled) {
59
+ this->enabled = props->enabled;
60
+ this->startKeyboardObserver();
61
+ }
62
+ if (this->navigationBarTranslucent != props->navigationBarTranslucent) {
63
+ this->navigationBarTranslucent = props->navigationBarTranslucent;
64
+ this->setWindowSystemBarEnable();
65
+ }
66
+ if (this->statusBarTranslucent != props->statusBarTranslucent) {
67
+ this->statusBarTranslucent = props->statusBarTranslucent;
68
+ this->setWindowSystemBarEnable();
69
+ }
70
+ }
71
+
72
+ void KeyboardControllerViewComponentInstance::onCommandReceived(std::string const &commandName,
73
+ folly::dynamic const &args) {
74
+ CppComponentInstance::onCommandReceived(commandName, args);
75
+ }
76
+
77
+ ArkUINode &KeyboardControllerViewComponentInstance::getLocalRootArkUINode() { return m_customNode; }
78
+ void KeyboardControllerViewComponentInstance::onClick() {}
79
+ void KeyboardControllerViewComponentInstance::onMessageReceived(ArkTSMessage const &message) {
80
+ DLOG(INFO) << "onMessageReceived";
81
+ if (message.name == "keyboardHeightChange") {
82
+ double height = message.payload.getDouble();
83
+ DLOG(INFO) << "keyboardHeightChange: " << height;
84
+ if (height > 0) {
85
+ this->keyboardStatus = KeyboardControllerStatus::SHOW;
86
+ this->keyboardHeight = height;
87
+ this->textInputVector.clear();
88
+ this->focusDidSet();
89
+ auto textInputVectorTemp = ViewHierarchyNavigator::getAllInputFields(this->shared_from_this());
90
+ for (size_t i = 0; i < textInputVectorTemp.size(); ++i) {
91
+ auto &input = textInputVectorTemp[i];
92
+ findTextInputComponents(input);
93
+ }
94
+ }
95
+ if (height == 0) {
96
+ this->keyboardStatus = KeyboardControllerStatus::HIDE;
97
+ }
98
+ this->keyboardHeightChangeHandle();
99
+ }
100
+ if (message.name == "setFocusTo") {
101
+ std::string direction = message.payload.getString();
102
+ this->setFocusTo(direction);
103
+ }
104
+ }
105
+ void KeyboardControllerViewComponentInstance::setWindowSystemBarEnable() {
106
+ auto rnInstancePtr = this->m_deps->rnInstance.lock();
107
+ if (rnInstancePtr != nullptr) {
108
+ auto turboModule = rnInstancePtr->getTurboModule("KeyboardController");
109
+ auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
110
+ arkTsTurboModule->callSync("setWindowSystemBarEnable", {this->statusBarTranslucent, this->navigationBarTranslucent});
111
+ }
112
+ }
113
+
114
+ void KeyboardControllerViewComponentInstance::startKeyboardObserver() {
115
+ auto rnInstancePtr = this->m_deps->rnInstance.lock();
116
+ if (rnInstancePtr != nullptr) {
117
+ auto turboModule = rnInstancePtr->getTurboModule("KeyboardController");
118
+ auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
119
+ arkTsTurboModule->callSync("startKeyboardObserver", {this->enabled});
120
+ }
121
+ }
122
+
123
+ void KeyboardControllerViewComponentInstance::keyboardHeightChangeHandle() {
124
+ auto rnInstancePtr = this->m_deps->rnInstance.lock();
125
+ if (rnInstancePtr != nullptr && this->enabled) {
126
+ if (this->keyboardStatus == KeyboardControllerStatus::HIDE) {
127
+ facebook::react::KeyboardControllerViewEventEmitter::MoveEvent start = {this->keyboardHeight, 0, 0, m_tag};
128
+ facebook::react::KeyboardControllerViewEventEmitter::MoveEvent end = {0, 0, 0, m_tag};
129
+ m_eventEmitter->onKeyboardMoveStart(start);
130
+ m_eventEmitter->onKeyboardMove(end);
131
+ m_eventEmitter->onKeyboardMoveEnd(end);
132
+ } else {
133
+ facebook::react::KeyboardControllerViewEventEmitter::MoveEvent start = {0, 0, 0, m_tag};
134
+ facebook::react::KeyboardControllerViewEventEmitter::MoveEvent end = {this->keyboardHeight, 1, 0, m_tag};
135
+ m_eventEmitter->onKeyboardMoveStart(start);
136
+ m_eventEmitter->onKeyboardMove(end);
137
+ m_eventEmitter->onKeyboardMoveEnd(end);
138
+ }
139
+ }
140
+ }
141
+
142
+ /**
143
+ * 遍历查找TextInput
144
+ * */
145
+ void KeyboardControllerViewComponentInstance::findTextInputComponents(
146
+ ComponentInstance::Shared const &childComponentInstance) {
147
+ std::string name = childComponentInstance->getComponentName();
148
+ DLOG(INFO) << "###" << name;
149
+ if (name.find("TextInput") != std::string::npos || name.find("TextArea") != std::string::npos) {
150
+ auto input = std::dynamic_pointer_cast<TextInputComponentInstance>(childComponentInstance);
151
+ ArkUINode &node = input->getLocalRootArkUINode();
152
+ TextInputNode *inputNodePtr = dynamic_cast<TextInputNode *>(&node);
153
+ if (!inputNodePtr) {
154
+ TextAreaNode *textAreaNodePtr = dynamic_cast<TextAreaNode *>(&node);
155
+ textAreaNodePtr->setTextAreaNodeDelegate(this);
156
+ } else {
157
+ inputNodePtr->setTextInputNodeDelegate(this);
158
+ }
159
+ this->textInputVector.push_back(input);
160
+ }
161
+ auto childrenComponentInstances = childComponentInstance->getChildren();
162
+ if (childrenComponentInstances.empty()) {
163
+ return;
164
+ }
165
+
166
+ std::vector<ComponentInstance::Shared>::iterator it1;
167
+ for (it1 = childrenComponentInstances.begin(); it1 != childrenComponentInstances.end(); ++it1) {
168
+ ComponentInstance::Shared const &t = *it1;
169
+ findTextInputComponents(t);
170
+ }
171
+ }
172
+
173
+ void KeyboardControllerViewComponentInstance::onChange(std::string text) {
174
+ facebook::react::KeyboardControllerViewEventEmitter::TextChangeEvent event = {text};
175
+ if(this->enabled){
176
+ m_eventEmitter->onFocusedInputTextChanged(event);
177
+ }
178
+
179
+ }
180
+
181
+ void KeyboardControllerViewComponentInstance::onChange(std::string text, std::string extendStr) {
182
+ onChange(std::move(text));
183
+ }
184
+
185
+ void KeyboardControllerViewComponentInstance::onTextSelectionChange(int32_t location, int32_t length) {
186
+ DLOG(INFO) << " onKeyboardControllerView onTextSelectionChange";
187
+ // to do
188
+ };
189
+
190
+ void KeyboardControllerViewComponentInstance::focusDidSet() {
191
+ int currentIndex = -1;
192
+ this->textInputVector = ViewHierarchyNavigator::getAllInputFields(this->shared_from_this());
193
+ int count = static_cast<int>(this->textInputVector.size());
194
+ for (size_t i = 0; i < this->textInputVector.size(); ++i) {
195
+ auto& input = this->textInputVector[i];
196
+ ArkUINode& node = input->getLocalRootArkUINode();
197
+ if (node.isFocused()) {
198
+ currentIndex = static_cast<int>(i);
199
+ break;
200
+ }
201
+ }
202
+ this->textInputVector.clear();
203
+ // 发送 focusDidSet 事件到 JS 层
204
+ if (currentIndex >= 0 && this->enabled) {
205
+ auto rnInstancePtr = this->m_deps->rnInstance.lock();
206
+ if (rnInstancePtr != nullptr) {
207
+ folly::dynamic payload = folly::dynamic::object
208
+ ("current", currentIndex)
209
+ ("count", count);
210
+ rnInstancePtr->postMessageToArkTS("focusDidSet", payload);
211
+ }
212
+ }
213
+ }
214
+
215
+ void KeyboardControllerViewComponentInstance::onFocus() {
216
+ DLOG(INFO) << "onKeyboardControllerView onFocus";
217
+ this->focusDidSet();
218
+ }
219
+
220
+ void KeyboardControllerViewComponentInstance::onBlur() { DLOG(INFO) << " onKeyboardControllerView onBlur"; }
221
+
222
+ /**
223
+ * 设置焦点到指定方向的输入框
224
+ * 实现逻辑仿照 iOS ViewHierarchyNavigator.swift
225
+ * @param direction "next" | "prev"
226
+ */
227
+ void KeyboardControllerViewComponentInstance::setFocusTo(const std::string& direction) {
228
+ // 确定当前焦点组件
229
+ this->textInputVector = ViewHierarchyNavigator::getAllInputFields(this->shared_from_this());
230
+ ComponentInstance::Shared currentFocus = nullptr;
231
+ for (size_t i = 0; i < this->textInputVector.size(); ++i) {
232
+ auto& input = this->textInputVector[i];
233
+ ArkUINode& node = input->getLocalRootArkUINode();
234
+ if (node.isFocused()) {
235
+ currentFocus = input;
236
+ break;
237
+ }
238
+ }
239
+ if (!currentFocus) {
240
+ DLOG(INFO) << "no current focus available";
241
+ return;
242
+ }
243
+ // 使用 ViewHierarchyNavigator 查找目标输入框
244
+ auto targetInput = ViewHierarchyNavigator::setFocusTo(direction, currentFocus);
245
+ if (targetInput) {
246
+ DLOG(INFO) << "setFocusTo: found target, requesting focus, tag=" << targetInput->getTag();
247
+ // 获取 ArkUI_NodeHandle 并请求焦点
248
+ ArkUINode& node = targetInput->getLocalRootArkUINode();
249
+ ArkUI_NodeHandle nodeHandle = node.getArkUINodeHandle();
250
+ ArkUI_ErrorCode result = ARKUI_ERROR_CODE_NO_ERROR;
251
+ high_lib_handle = dlopen("libace_ndk.z.so", RTLD_LAZY);
252
+ if (high_lib_handle == NULL) {
253
+ DLOG(INFO) << "libace_ndk.z.so not existed";
254
+ dlclose(high_lib_handle);
255
+ } else {
256
+ focusRequestMethod = (ArkUI_ErrorCode(*)(ArkUI_NodeHandle node))dlsym(high_lib_handle, "OH_ArkUI_FocusRequest");
257
+ bool isFocusRequestMethodExisted = focusRequestMethod != NULL;
258
+ if (isFocusRequestMethodExisted) {
259
+ DLOG(INFO) << "OH_ArkUI_FocusRequest method existed";
260
+ result = focusRequestMethod(nodeHandle);
261
+ } else {
262
+ DLOG(INFO) << "OH_ArkUI_FocusRequest method not existed";
263
+ }
264
+ dlclose(high_lib_handle);
265
+ }
266
+ if (!(result == ARKUI_ERROR_CODE_NO_ERROR)) {
267
+ DLOG(WARNING) << "setFocusTo: focus request failed with error code: " << result;
268
+ }
269
+ } else {
270
+ DLOG(INFO) << "setFocusTo: no target input found in direction " << direction;
271
+ }
272
+ this->textInputVector.clear();
273
+ }
274
+ } // namespace rnoh
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3
+ */
4
+ /**
5
+ * MIT License
6
+ *
7
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #ifndef KEYBOARDCONTROLLERVIEWCOMPONENTINSTANCE_H
29
+ #define KEYBOARDCONTROLLERVIEWCOMPONENTINSTANCE_H
30
+
31
+ #ifndef TESTER_HARMONY_KEYBOARD_CONTROLLER_SRC_MAIN_CPP_KEYBOARDCONTROLLERVIEWCOMPONENTINSTANCE_H
32
+ #define TESTER_HARMONY_KEYBOARD_CONTROLLER_SRC_MAIN_CPP_KEYBOARDCONTROLLERVIEWCOMPONENTINSTANCE_H
33
+
34
+ #include <any>
35
+ #include "RNOH/CppComponentInstance.h"
36
+ #include "KeyboardControllerViewComponentDescriptor.h"
37
+ #include "RNOHCorePackage/ComponentInstances/TextInputComponentInstance.h"
38
+ #include "RNOH/arkui/CustomNode.h"
39
+ #include "RNOH/ArkTSMessageHub.h"
40
+ #include "RNOH/arkui/TextInputNode.h"
41
+ #include "RNOH/arkui/TextAreaNode.h"
42
+ #include "ViewHierarchyNavigator.h"
43
+
44
+ namespace rnoh {
45
+ enum KeyboardControllerStatus { HIDE = 0, SHOW = 1 };
46
+ class KeyboardControllerViewComponentInstance
47
+ : public CppComponentInstance<facebook::react::KeyboardControllerViewShadowNode>,
48
+ public CustomNodeDelegate,
49
+ public TextAreaNodeDelegate,
50
+ public TextInputNodeDelegate,
51
+ public ArkTSMessageHub::Observer {
52
+ public:
53
+ KeyboardControllerViewComponentInstance(Context context);
54
+ void onKeyboardMoveStart();
55
+ void onKeyboardMove();
56
+ void onKeyboardMoveEnd();
57
+ void onKeyboardMoveInteractive();
58
+ void onFocusedInputLayoutChanged();
59
+ void onFocusedInputTextChanged();
60
+ void onFocusedInputSelectionChanged();
61
+
62
+ void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
63
+ void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;
64
+ void onPropsChanged(SharedConcreteProps const &props) override;
65
+ void onCommandReceived(std::string const &commandName, folly::dynamic const &args) override;
66
+ void onMessageReceived(ArkTSMessage const &message) override;
67
+ ArkUINode &getLocalRootArkUINode() override;
68
+ void onClick() override;
69
+ // textArea textInput delegate
70
+ void onChange(std::string text) override;
71
+ void onChange(std::string text, std::string extendStr) override;
72
+ void onBlur() override;
73
+ void onFocus() override;
74
+ void onTextSelectionChange(int32_t location, int32_t length) override;
75
+
76
+ protected:
77
+ private:
78
+ bool enabled;
79
+ bool statusBarTranslucent;
80
+ bool navigationBarTranslucent;
81
+ double keyboardHeight;
82
+ std::map<std::string, std::any> dictionary;
83
+ int keyboardStatus;
84
+ std::vector<TextInputComponentInstance::Shared> textInputVector{};
85
+ CustomNode m_customNode{};
86
+ ComponentInstance::Shared currentResponder;
87
+ void findTextInputComponents(ComponentInstance::Shared const &parentComponentInstance);
88
+ void setWindowSystemBarEnable();
89
+ void startKeyboardObserver();
90
+ void closeKeyboardObserver();
91
+ void keyboardHeightChangeHandle();
92
+ void setFocusTo(const std::string& direction);
93
+ void focusDidSet();
94
+ void *high_lib_handle = NULL;
95
+ ArkUI_ErrorCode (*focusRequestMethod)(ArkUI_NodeHandle node);
96
+ };
97
+ } // namespace rnoh
98
+
99
+ #endif
100
+
101
+ #endif
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3
+ */
4
+ /**
5
+ * MIT License
6
+ *
7
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #ifndef TESTER_HARMONY_KEYBOARD_CONTROLLER_SRC_MAIN_CPP_KEYBOARDCONTROLLERVIEWJSIBINDER_H
29
+ #define TESTER_HARMONY_KEYBOARD_CONTROLLER_SRC_MAIN_CPP_KEYBOARDCONTROLLERVIEWJSIBINDER_H
30
+
31
+ #pragma once
32
+ #include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"
33
+ namespace rnoh {
34
+ class KeyboardControllerViewJSIBinder : public ViewComponentJSIBinder {
35
+ protected:
36
+ facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
37
+ auto object = ViewComponentJSIBinder::createNativeProps(rt);
38
+ object.setProperty(rt, "enabled", "bool");
39
+ object.setProperty(rt, "statusBarTranslucent", "bool");
40
+ object.setProperty(rt, "navigationBarTranslucent", "bool");
41
+ return object;
42
+ }
43
+
44
+ facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
45
+ facebook::jsi::Object events(rt);
46
+ return events;
47
+ }
48
+
49
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
50
+ facebook::jsi::Object events(rt);
51
+ events.setProperty(rt, "topKeyboardMoveStart", createDirectEvent(rt, "onKeyboardMoveStart"));
52
+ events.setProperty(rt, "topKeyboardMove", createDirectEvent(rt, "onKeyboardMove"));
53
+ events.setProperty(rt, "topKeyboardMoveEnd", createDirectEvent(rt, "onKeyboardMoveEnd"));
54
+ events.setProperty(rt, "topKeyboardMoveInteractive", createDirectEvent(rt, "onKeyboardMoveInteractive"));
55
+ events.setProperty(rt, "topFocusedInputLayoutChanged", createDirectEvent(rt, "onFocusedInputLayoutChanged"));
56
+ events.setProperty(rt, "topFocusedInputTextChanged", createDirectEvent(rt, "onFocusedInputTextChanged"));
57
+ events.setProperty(rt, "topFocusedInputSelectionChanged",
58
+ createDirectEvent(rt, "onFocusedInputSelectionChanged"));
59
+ return events;
60
+ }
61
+ };
62
+ } // namespace rnoh
63
+
64
+ #endif
@@ -0,0 +1,85 @@
1
+ /*
2
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3
+ */
4
+ /**
5
+ * MIT License
6
+ *
7
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #ifndef TESTER_HARMONY_KEYBOARD_CONTROLLER_SRC_MAIN_CPP_KEYBOARDGESTUREAREACOMPONENTDESCRIPTOR_H
29
+ #define TESTER_HARMONY_KEYBOARD_CONTROLLER_SRC_MAIN_CPP_KEYBOARDGESTUREAREACOMPONENTDESCRIPTOR_H
30
+
31
+ #ifndef KEYBOARDGESTUREAREACOMPONENTDESCRIPTOR_H
32
+ #define KEYBOARDGESTUREAREACOMPONENTDESCRIPTOR_H
33
+
34
+
35
+ #pragma once
36
+
37
+
38
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
39
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
40
+ #include <react/renderer/components/view/ViewShadowNode.h>
41
+ #include <react/renderer/core/propsConversions.h>
42
+ #include "EventEmitters.h"
43
+
44
+ namespace facebook {
45
+ namespace react {
46
+
47
+ inline const char KeyboardGestureAreaComponentName[] = "RNKeyboardGestureArea";
48
+
49
+ class KeyboardGestureAreaProps : public ViewProps {
50
+ public:
51
+ bool showOnSwipeUp;
52
+ bool enableSwipeToDismiss;
53
+ std::string interpolator;
54
+ KeyboardGestureAreaProps() = default;
55
+
56
+ KeyboardGestureAreaProps(const PropsParserContext &context, const KeyboardGestureAreaProps &sourceProps,
57
+ const RawProps &rawProps)
58
+ : ViewProps(context, sourceProps, rawProps),
59
+ showOnSwipeUp(CoreFeatures::enablePropIteratorSetter
60
+ ? sourceProps.showOnSwipeUp
61
+ : convertRawProp(context, rawProps, "showOnSwipeUp", sourceProps.showOnSwipeUp, {false})),
62
+ enableSwipeToDismiss(CoreFeatures::enablePropIteratorSetter
63
+ ? sourceProps.enableSwipeToDismiss
64
+ : convertRawProp(context, rawProps, "enableSwipeToDismiss",
65
+ sourceProps.enableSwipeToDismiss, {false})),
66
+ interpolator(CoreFeatures::enablePropIteratorSetter
67
+ ? sourceProps.interpolator
68
+ : convertRawProp(context, rawProps, "interpolator", sourceProps.interpolator, {"linear"})) {}
69
+ };
70
+
71
+ using KeyboardGestureAreaShadowNode =
72
+ ConcreteViewShadowNode<KeyboardGestureAreaComponentName, KeyboardGestureAreaProps, ViewEventEmitter>;
73
+
74
+ class KeyboardGestureAreaComponentDescriptor final : public ConcreteComponentDescriptor<KeyboardGestureAreaShadowNode> {
75
+ public:
76
+ KeyboardGestureAreaComponentDescriptor(ComponentDescriptorParameters const &parameters)
77
+ : ConcreteComponentDescriptor(parameters) {}
78
+ };
79
+
80
+ } // namespace react
81
+ } // namespace facebook
82
+
83
+ #endif
84
+
85
+ #endif
@@ -0,0 +1,110 @@
1
+ /*
2
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3
+ */
4
+ /**
5
+ * MIT License
6
+ *
7
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ #include "KeyboardGestureAreaComponentInstance.h"
29
+ #include <folly/dynamic.h>
30
+
31
+
32
+ namespace rnoh {
33
+ KeyboardGestureAreaComponentInstance::KeyboardGestureAreaComponentInstance(Context context)
34
+ : CppComponentInstance(std::move(context)) {
35
+ DLOG(INFO) << "KeyboardGestureAreaComponentInstance";
36
+ ArkUINodeRegistry::getInstance().registerTouchHandler(&m_stackNode, this);
37
+ NativeNodeApi::getInstance()->registerNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT,
38
+ NODE_TOUCH_EVENT, 0);
39
+ }
40
+ void KeyboardGestureAreaComponentInstance::onTouchEvent(ArkUI_UIInputEvent *e) {
41
+ auto action = OH_ArkUI_UIInputEvent_GetAction(e);
42
+ DLOG(INFO) << "KeyboardGestureAreaComponentInstance onTouchEvent" << action;
43
+ if (action == UI_TOUCH_EVENT_ACTION_DOWN) {
44
+ this->swipeToDismiss();
45
+ }
46
+ if (action == UI_TOUCH_EVENT_ACTION_UP) {
47
+ this->swipeToUp();
48
+ }
49
+ }
50
+ void KeyboardGestureAreaComponentInstance::onChildInserted(ComponentInstance::Shared const &childComponentInstance,
51
+ std::size_t index) {
52
+ CppComponentInstance::onChildInserted(childComponentInstance, index);
53
+ m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index + 1);
54
+ }
55
+
56
+ void KeyboardGestureAreaComponentInstance::onChildRemoved(ComponentInstance::Shared const &childComponentInstance) {
57
+ CppComponentInstance::onChildRemoved(childComponentInstance);
58
+ m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
59
+ }
60
+ ArkUINode &KeyboardGestureAreaComponentInstance::getLocalRootArkUINode() { return m_stackNode; }
61
+ void KeyboardGestureAreaComponentInstance::onPropsChanged(SharedConcreteProps const &props) {
62
+ DLOG(INFO) << "###onPropsChanged";
63
+ CppComponentInstance::onPropsChanged(props);
64
+ this->showOnSwipeUp = props->showOnSwipeUp;
65
+ this->enableSwipeToDismiss = props->enableSwipeToDismiss;
66
+ this->interpolator = props->interpolator;
67
+ }
68
+
69
+ void KeyboardGestureAreaComponentInstance::onCommandReceived(std::string const &commandName,
70
+ folly::dynamic const &args) {
71
+ CppComponentInstance::onCommandReceived(commandName, args);
72
+ }
73
+
74
+ void KeyboardGestureAreaComponentInstance::handleTouchEvent(ArkUI_UIInputEvent *e) {
75
+ auto action = OH_ArkUI_UIInputEvent_GetAction(e);
76
+ if (action == UI_TOUCH_EVENT_ACTION_DOWN) {
77
+ this->swipeToDismiss();
78
+ }
79
+ if (action == UI_TOUCH_EVENT_ACTION_UP) {
80
+ this->swipeToUp();
81
+ }
82
+ }
83
+ void KeyboardGestureAreaComponentInstance::swipeToDismiss() {
84
+ if (!this->enableSwipeToDismiss) {
85
+ return;
86
+ }
87
+ auto rnInstancePtr = this->m_deps->rnInstance.lock();
88
+ if (rnInstancePtr != nullptr) {
89
+ auto turboModule = rnInstancePtr->getTurboModule("KeyboardController");
90
+ auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
91
+ arkTsTurboModule->callSync("dismiss", {});
92
+ }
93
+ }
94
+ void KeyboardGestureAreaComponentInstance::swipeToUp() {
95
+ if (!this->showOnSwipeUp) {
96
+ return;
97
+ }
98
+ auto rnInstancePtr = this->m_deps->rnInstance.lock();
99
+ if (rnInstancePtr != nullptr) {
100
+ auto turboModule = rnInstancePtr->getTurboModule("KeyboardController");
101
+ auto arkTsTurboModule = std::dynamic_pointer_cast<rnoh::ArkTSTurboModule>(turboModule);
102
+ arkTsTurboModule->callSync("show", {});
103
+ }
104
+ }
105
+ void KeyboardGestureAreaComponentInstance::executeInterpolator() {
106
+ // to do
107
+ }
108
+
109
+ } // namespace rnoh
110
+ // namespace rnoh