@react-native-ohos/react-native-keyboard-controller 1.12.8-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 (248) 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 +9 -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.json5 +11 -0
  12. package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
  13. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
  14. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -0
  15. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +77 -0
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +158 -0
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +74 -0
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +43 -0
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +64 -0
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +89 -0
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +63 -0
  22. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -0
  23. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -0
  24. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -0
  25. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.cpp +43 -0
  26. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardControllerPackage.h +56 -0
  27. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -0
  28. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -0
  29. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -0
  30. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -0
  31. package/harmony/keyboard_controller/src/main/ets/Logger.ts +46 -0
  32. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ets +46 -0
  33. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +210 -0
  34. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +98 -0
  35. package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -0
  36. package/harmony/keyboard_controller/src/main/module.json +29 -0
  37. package/harmony/keyboard_controller/src/main/module.json5 +11 -0
  38. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
  39. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
  40. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
  41. package/harmony/keyboard_controller/ts.ets +9 -0
  42. package/harmony/keyboard_controller.har +0 -0
  43. package/lib/commonjs/animated.js +174 -0
  44. package/lib/commonjs/animated.js.map +1 -0
  45. package/lib/commonjs/bindings.js +38 -0
  46. package/lib/commonjs/bindings.js.map +1 -0
  47. package/lib/commonjs/bindings.native.js +37 -0
  48. package/lib/commonjs/bindings.native.js.map +1 -0
  49. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +66 -0
  50. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
  51. package/lib/commonjs/components/KeyboardAvoidingView/index.js +102 -0
  52. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
  53. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +255 -0
  54. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
  55. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
  56. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  57. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
  58. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
  59. package/lib/commonjs/components/KeyboardStickyView/index.js +40 -0
  60. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
  61. package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
  62. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
  63. package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
  64. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
  65. package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
  66. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
  67. package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
  68. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
  69. package/lib/commonjs/components/KeyboardToolbar/index.js +152 -0
  70. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
  71. package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
  72. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
  73. package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
  74. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
  75. package/lib/commonjs/components/index.js +42 -0
  76. package/lib/commonjs/components/index.js.map +1 -0
  77. package/lib/commonjs/constants.js +25 -0
  78. package/lib/commonjs/constants.js.map +1 -0
  79. package/lib/commonjs/context.js +42 -0
  80. package/lib/commonjs/context.js.map +1 -0
  81. package/lib/commonjs/hooks/index.js +104 -0
  82. package/lib/commonjs/hooks/index.js.map +1 -0
  83. package/lib/commonjs/hooks/useWindowDimensions/index.android.js +29 -0
  84. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
  85. package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
  86. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
  87. package/lib/commonjs/index.js +116 -0
  88. package/lib/commonjs/index.js.map +1 -0
  89. package/lib/commonjs/internal.js +73 -0
  90. package/lib/commonjs/internal.js.map +1 -0
  91. package/lib/commonjs/monkey-patch.android.js +57 -0
  92. package/lib/commonjs/monkey-patch.android.js.map +1 -0
  93. package/lib/commonjs/monkey-patch.js +11 -0
  94. package/lib/commonjs/monkey-patch.js.map +1 -0
  95. package/lib/commonjs/reanimated.js +12 -0
  96. package/lib/commonjs/reanimated.js.map +1 -0
  97. package/lib/commonjs/reanimated.native.js +88 -0
  98. package/lib/commonjs/reanimated.native.js.map +1 -0
  99. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
  100. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  101. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
  102. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  103. package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
  104. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
  105. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
  106. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
  107. package/lib/commonjs/types.js +6 -0
  108. package/lib/commonjs/types.js.map +1 -0
  109. package/lib/commonjs/utils.js +9 -0
  110. package/lib/commonjs/utils.js.map +1 -0
  111. package/lib/module/animated.js +166 -0
  112. package/lib/module/animated.js.map +1 -0
  113. package/lib/module/bindings.js +32 -0
  114. package/lib/module/bindings.js.map +1 -0
  115. package/lib/module/bindings.native.js +31 -0
  116. package/lib/module/bindings.native.js.map +1 -0
  117. package/lib/module/components/KeyboardAvoidingView/hooks.js +59 -0
  118. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
  119. package/lib/module/components/KeyboardAvoidingView/index.js +95 -0
  120. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
  121. package/lib/module/components/KeyboardAwareScrollView/index.js +248 -0
  122. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
  123. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
  124. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  125. package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
  126. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
  127. package/lib/module/components/KeyboardStickyView/index.js +33 -0
  128. package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
  129. package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
  130. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
  131. package/lib/module/components/KeyboardToolbar/Button.js +62 -0
  132. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
  133. package/lib/module/components/KeyboardToolbar/colors.js +15 -0
  134. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
  135. package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
  136. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
  137. package/lib/module/components/KeyboardToolbar/index.js +140 -0
  138. package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
  139. package/lib/module/components/KeyboardToolbar/types.js +2 -0
  140. package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
  141. package/lib/module/components/hooks/useColorScheme.js +4 -0
  142. package/lib/module/components/hooks/useColorScheme.js.map +1 -0
  143. package/lib/module/components/index.js +5 -0
  144. package/lib/module/components/index.js.map +1 -0
  145. package/lib/module/constants.js +19 -0
  146. package/lib/module/constants.js.map +1 -0
  147. package/lib/module/context.js +35 -0
  148. package/lib/module/context.js.map +1 -0
  149. package/lib/module/hooks/index.js +68 -0
  150. package/lib/module/hooks/index.js.map +1 -0
  151. package/lib/module/hooks/useWindowDimensions/index.android.js +22 -0
  152. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
  153. package/lib/module/hooks/useWindowDimensions/index.js +2 -0
  154. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
  155. package/lib/module/index.js +10 -0
  156. package/lib/module/index.js.map +1 -0
  157. package/lib/module/internal.js +66 -0
  158. package/lib/module/internal.js.map +1 -0
  159. package/lib/module/monkey-patch.android.js +47 -0
  160. package/lib/module/monkey-patch.android.js.map +1 -0
  161. package/lib/module/monkey-patch.js +5 -0
  162. package/lib/module/monkey-patch.js.map +1 -0
  163. package/lib/module/reanimated.js +6 -0
  164. package/lib/module/reanimated.js.map +1 -0
  165. package/lib/module/reanimated.native.js +78 -0
  166. package/lib/module/reanimated.native.js.map +1 -0
  167. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
  168. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  169. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
  170. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  171. package/lib/module/specs/NativeKeyboardController.js +3 -0
  172. package/lib/module/specs/NativeKeyboardController.js.map +1 -0
  173. package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
  174. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
  175. package/lib/module/types.js +2 -0
  176. package/lib/module/types.js.map +1 -0
  177. package/lib/module/utils.js +2 -0
  178. package/lib/module/utils.js.map +1 -0
  179. package/lib/typescript/animated.d.ts +31 -0
  180. package/lib/typescript/bindings.d.ts +12 -0
  181. package/lib/typescript/bindings.native.d.ts +12 -0
  182. package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +6 -0
  183. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +50 -0
  184. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +25 -0
  185. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
  186. package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
  187. package/lib/typescript/components/KeyboardStickyView/index.d.ts +35 -0
  188. package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
  189. package/lib/typescript/components/KeyboardToolbar/Button.d.ts +15 -0
  190. package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
  191. package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
  192. package/lib/typescript/components/KeyboardToolbar/index.d.ts +50 -0
  193. package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
  194. package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
  195. package/lib/typescript/components/index.d.ts +8 -0
  196. package/lib/typescript/constants.d.ts +16 -0
  197. package/lib/typescript/context.d.ts +23 -0
  198. package/lib/typescript/hooks/index.d.ts +17 -0
  199. package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
  200. package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
  201. package/lib/typescript/index.d.ts +8 -0
  202. package/lib/typescript/internal.d.ts +30 -0
  203. package/lib/typescript/monkey-patch.android.d.ts +2 -0
  204. package/lib/typescript/monkey-patch.d.ts +2 -0
  205. package/lib/typescript/reanimated.d.ts +5 -0
  206. package/lib/typescript/reanimated.native.d.ts +7 -0
  207. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +53 -0
  208. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +10 -0
  209. package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
  210. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
  211. package/lib/typescript/types.d.ts +133 -0
  212. package/lib/typescript/utils.d.ts +1 -0
  213. package/package.json +177 -0
  214. package/react-native-keyboard-controller.podspec +61 -0
  215. package/src/animated.tsx +246 -0
  216. package/src/bindings.native.ts +57 -0
  217. package/src/bindings.ts +38 -0
  218. package/src/components/KeyboardAvoidingView/hooks.ts +58 -0
  219. package/src/components/KeyboardAvoidingView/index.tsx +156 -0
  220. package/src/components/KeyboardAwareScrollView/index.tsx +373 -0
  221. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
  222. package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
  223. package/src/components/KeyboardStickyView/index.tsx +57 -0
  224. package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
  225. package/src/components/KeyboardToolbar/Button.tsx +98 -0
  226. package/src/components/KeyboardToolbar/colors.native.ts +37 -0
  227. package/src/components/KeyboardToolbar/colors.ts +16 -0
  228. package/src/components/KeyboardToolbar/index.tsx +211 -0
  229. package/src/components/KeyboardToolbar/types.ts +40 -0
  230. package/src/components/hooks/useColorScheme.ts +5 -0
  231. package/src/components/index.ts +11 -0
  232. package/src/constants.ts +19 -0
  233. package/src/context.ts +65 -0
  234. package/src/hooks/index.ts +90 -0
  235. package/src/hooks/useWindowDimensions/index.android.ts +33 -0
  236. package/src/hooks/useWindowDimensions/index.ts +1 -0
  237. package/src/index.ts +21 -0
  238. package/src/internal.ts +84 -0
  239. package/src/monkey-patch.android.ts +44 -0
  240. package/src/monkey-patch.ts +4 -0
  241. package/src/reanimated.native.ts +132 -0
  242. package/src/reanimated.ts +29 -0
  243. package/src/specs/KeyboardControllerViewNativeComponent.ts +70 -0
  244. package/src/specs/KeyboardGestureAreaNativeComponent.ts +15 -0
  245. package/src/specs/NativeKeyboardController.ts +19 -0
  246. package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
  247. package/src/types.ts +211 -0
  248. package/src/utils.ts +1 -0
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import {TurboModulesFactory} from '@rnoh/react-native-openharmony/ts';
8
+ import type { TurboModule, TurboModuleContext, } from '@rnoh/react-native-openharmony/ts';
9
+ import {RNKeyboardControllerTurboModule} from './RNKeyboardControllerTurboModule';
10
+ import {RNStatusBarManagerCompatTurboModule} from './RNStatusBarManagerCompatTurboModule';
11
+ import { RNOHPackage } from '@rnoh/react-native-openharmony'
12
+
13
+ class RNKeyboardControllerTurboModuleFactory extends TurboModulesFactory {
14
+ createTurboModule(name: string): TurboModule | null {
15
+ if (this.hasTurboModule(name)) {
16
+ return new RNKeyboardControllerTurboModule(this.ctx);
17
+ }
18
+ return null;
19
+ }
20
+ hasTurboModule(name: string): boolean {
21
+ return name === 'KeyboardController';
22
+ }
23
+
24
+ }
25
+ class RNStatusBarManagerCompatTurboModuleFactory extends TurboModulesFactory {
26
+ createTurboModule(name: string): TurboModule | null {
27
+ if(this.hasTurboModule(name)){
28
+ return new RNStatusBarManagerCompatTurboModule(this.ctx);
29
+ }
30
+ return null;
31
+ }
32
+ hasTurboModule(name: string): boolean {
33
+ return name === 'StatusBarManagerCompat';
34
+ }
35
+ }
36
+
37
+ export class RNKeyboardControllerPackage extends RNOHPackage {
38
+ createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
39
+ return new RNKeyboardControllerTurboModuleFactory(ctx);
40
+ }
41
+ }
42
+ export class RNStatusBarManagerCompatPackage extends RNOHPackage {
43
+ createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
44
+ return new RNStatusBarManagerCompatTurboModuleFactory(ctx);
45
+ }
46
+ }
@@ -0,0 +1,210 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import { TurboModule } from "@rnoh/react-native-openharmony/ts";
8
+ import common from '@ohos.app.ability.common';
9
+ import window from '@ohos.window';
10
+ import inputMethod from '@ohos.inputMethod';
11
+ import Logger from './Logger';
12
+ import { KeyboardControllerEventName, KeyboardStatusType } from './Type';
13
+ import { BusinessError } from '@kit.BasicServicesKit';
14
+ import { JSON } from '@kit.ArkTS';
15
+
16
+ declare function px2vp(px: number): number;
17
+
18
+ interface RNKeyboardControllerSpec {
19
+ getConstants(): {};
20
+
21
+ setInputMode(mode: number): void;
22
+
23
+ setDefaultMode(): void;
24
+
25
+ dismiss(): void;
26
+
27
+ setFocusTo(direction: string): void;
28
+
29
+ addListener(eventName: string, listener: (event) => void,): void;
30
+
31
+ removeListeners(count: number): void;
32
+ }
33
+
34
+ export class RNKeyboardControllerTurboModule extends TurboModule implements RNKeyboardControllerSpec {
35
+ private context: common.UIAbilityContext;
36
+ private keyboardHeight: number;
37
+ private keyboardStatus: KeyboardStatusType;
38
+ private eventListeners: KeyboardControllerEventName[];
39
+ private currentWindow:window.Window;
40
+ private enabled:boolean;
41
+ constructor(ctx) {
42
+ super(ctx);
43
+ this.context = this.ctx.uiAbilityContext;
44
+ this.eventListeners = this.supportListeners();
45
+ }
46
+
47
+ readonly getConstants: () => {};
48
+
49
+ // set mode
50
+ setInputMode(mode: number): void {
51
+ Logger.info('harmonyOS not support setInputMode')
52
+ }
53
+
54
+ setDefaultMode(): void {
55
+ Logger.info('harmonyOS not support setDefaultMode')
56
+ }
57
+
58
+ /**
59
+ * @description 键盘隐藏
60
+ * */
61
+ dismiss(): void {
62
+ let inputMethodController = inputMethod.getController();
63
+ inputMethodController.stopInputSession()
64
+
65
+ }
66
+ /**
67
+ * @description 键盘隐藏
68
+ * */
69
+ private show(): void {
70
+ let inputMethodController = inputMethod.getController();
71
+ inputMethodController.showSoftKeyboard()
72
+
73
+ }
74
+
75
+ setFocusTo(direction: string): void {
76
+ this.ctx.rnInstance.postMessageToCpp('setFocusTo', direction);
77
+ }
78
+
79
+ /**
80
+ * @description 添加监听键盘事件
81
+ */
82
+ addListener(eventName: KeyboardControllerEventName) {
83
+ let supportEvents = this.supportListeners()
84
+ let bo = supportEvents.includes(eventName)
85
+ if (bo && !this.eventListeners.includes(eventName)) {
86
+ this.eventListeners.push(eventName)
87
+ }
88
+ }
89
+
90
+ /**
91
+ * @description 删除监听事件
92
+ * */
93
+ removeListeners(count: number): void {
94
+ let num = this.eventListeners.length;
95
+ if (num>0) {
96
+ this.eventListeners = [];
97
+ }
98
+ }
99
+
100
+ private supportListeners() {
101
+ return [
102
+ KeyboardControllerEventName.KEYBOARD_WILL_SHOW,
103
+ KeyboardControllerEventName.KEYBOARD_DID_SHOW,
104
+ KeyboardControllerEventName.KEYBOARD_WILL_HIDE,
105
+ KeyboardControllerEventName.KEYBOARD_DID_HIDE,
106
+ KeyboardControllerEventName.FOCUS_DID_SET
107
+ ];
108
+ }
109
+
110
+ private async setWindowSystemBarEnable(statusBarTranslucent: boolean, navigationBarTranslucent: boolean) {
111
+
112
+ let windowInstance: window.Window | undefined = undefined;
113
+ windowInstance = await window.getLastWindow(this.context);
114
+ let systemBarProperty = windowInstance.getWindowSystemBarProperties();
115
+ let newSystemBarProperty: window.SystemBarProperties = {
116
+ ...systemBarProperty,
117
+ statusBarColor: statusBarTranslucent ? "#00000000" : systemBarProperty.statusBarColor,
118
+ navigationBarColor: navigationBarTranslucent ? "#00000000" : systemBarProperty.navigationBarColor
119
+ };
120
+ try {
121
+ let promise = windowInstance.setWindowSystemBarProperties(newSystemBarProperty);
122
+ promise.then(() => {
123
+ Logger.info('Succeeded in setting the system bar properties.');
124
+ }).catch((err: BusinessError) => {
125
+ Logger.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
126
+ });
127
+ } catch (exception) {
128
+ Logger.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
129
+ }
130
+ }
131
+
132
+ private keyboardControllerEventHandle(keyboardStatus: number, height: number) {
133
+ Logger.info('###turboModule keyboardControllerEventHandle', String(keyboardStatus) + ',' + String(height));
134
+ if(!this.enabled){
135
+ return
136
+ }
137
+
138
+ if (this.keyboardStatus == KeyboardStatusType.HIDE) {
139
+ // 键盘隐藏
140
+ Logger.info('###turboModule keyboardControllerEventHandle');
141
+ this.eventListeners.includes(KeyboardControllerEventName.KEYBOARD_DID_HIDE) &&
142
+ this.ctx.rnInstance.emitDeviceEvent(KeyboardControllerEventName.KEYBOARD_DID_HIDE, {
143
+ duration: 0,
144
+ timestamp: new Date().getTime(),
145
+ target: 0,
146
+ height: height,
147
+ tag:0
148
+ });
149
+ }
150
+ if (this.keyboardStatus == KeyboardStatusType.SHOW) {
151
+ // 键盘显示
152
+ Logger.info('###turboModule keyboardControllerEventHandle');
153
+ this.eventListeners.includes(KeyboardControllerEventName.KEYBOARD_DID_SHOW) &&
154
+ this.ctx.rnInstance.emitDeviceEvent(KeyboardControllerEventName.KEYBOARD_DID_SHOW, {
155
+ duration: 0,
156
+ timestamp: new Date().getTime(),
157
+ target: 0,
158
+ height:height,
159
+ tag:0
160
+ });
161
+ }
162
+ }
163
+
164
+ private async startKeyboardObserver(open:boolean) {
165
+ Logger.info("###turboModule startKeyboardObserver",String(open));
166
+ this.enabled=open;
167
+ this.currentWindow = await window.getLastWindow(this.context);
168
+ if (!this.currentWindow) {
169
+ throw ('windowInstance is null')
170
+ return
171
+ }
172
+ if(!open){
173
+ try {
174
+ Logger.info("###turboModule Close KeyboardObserver");
175
+ this.currentWindow.off('keyboardHeightChange', (data) => {
176
+ this.keyboardStatus = KeyboardStatusType.HIDE;
177
+ this.keyboardHeight = 0;
178
+ Logger.info('### close keyboardHeightChange observer');
179
+ });
180
+ } catch (exception) {
181
+ Logger.error('### Failed to close the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
182
+ }
183
+ }else{
184
+ try {
185
+ this.currentWindow.on('keyboardHeightChange', (data) => {
186
+ const keyboardAvoidArea = this.currentWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD).bottomRect;
187
+ let height = Math.ceil(px2vp(keyboardAvoidArea.height))
188
+ if(open){
189
+ if(this.keyboardHeight == height ){
190
+ return
191
+ }
192
+ if (height > 0) {
193
+ this.keyboardStatus = KeyboardStatusType.SHOW;
194
+ } else {
195
+ this.keyboardStatus = KeyboardStatusType.HIDE;
196
+ }
197
+ this.keyboardHeight = height;
198
+ this.keyboardControllerEventHandle(this.keyboardStatus, height);
199
+ this.ctx.rnInstance.postMessageToCpp('keyboardHeightChange', height);
200
+ }
201
+
202
+ });
203
+ } catch (exception) {
204
+ Logger.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
205
+ }
206
+ }
207
+
208
+ }
209
+
210
+ }
@@ -0,0 +1,98 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ import { TurboModule } from "@rnoh/react-native-openharmony/ts";
8
+ import window from '@ohos.window';
9
+ import common from '@ohos.app.ability.common';
10
+ import { BusinessError } from '@kit.BasicServicesKit';
11
+ import Logger from './Logger';
12
+
13
+
14
+ interface StatusBarManagerCompatSpec {
15
+ getConstants(): {};
16
+ setHidden(hidden: boolean): void;
17
+ setColor(color: number, animated: boolean): void;
18
+ setTranslucent(translucent: boolean): void;
19
+ setStyle(style: string): void;
20
+
21
+ }
22
+ export class RNStatusBarManagerCompatTurboModule extends TurboModule implements StatusBarManagerCompatSpec{
23
+ private context: common.UIAbilityContext;
24
+ constructor(ctx) {
25
+ super(ctx);
26
+ this.context = this.ctx.uiAbilityContext;
27
+ }
28
+ private async setWindowSystemBarProperties(properties:window.SystemBarProperties){
29
+ let windowInstance: window.Window | undefined = undefined;
30
+ windowInstance = await window.getLastWindow(this.context);
31
+ let systemBarProperty = windowInstance.getWindowSystemBarProperties();
32
+ let newSystemBarProperty: window.SystemBarProperties = {
33
+ ...systemBarProperty,
34
+ ...properties
35
+ };
36
+ try {
37
+ let promise = windowInstance.setWindowSystemBarProperties(newSystemBarProperty);
38
+ promise.then(() => {
39
+ Logger.info('Succeeded in setting the system bar properties.');
40
+ }).catch((err: BusinessError) => {
41
+ Logger.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
42
+ });
43
+ } catch (exception) {
44
+ Logger.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
45
+ }
46
+ }
47
+ readonly getConstants:()=>{};
48
+ // set mode
49
+ async setHidden(hidden: boolean): Promise<void> {
50
+ Logger.info("###turboModule setHidden");
51
+ let windowInstance: window.Window | undefined = undefined;
52
+ windowInstance = await window.getLastWindow(this.context);
53
+ let names: Array<'status' | 'navigation'> = ['navigation'];
54
+ hidden && names.push('status');
55
+ try {
56
+ let promise = windowInstance.setWindowSystemBarEnable(names);
57
+ promise.then(() => {
58
+ Logger.info('Succeeded in setting the system bar to be invisible.');
59
+ }).catch((err: BusinessError) => {
60
+ Logger.error(`Failed to set the system bar to be invisible. Cause code: ${err.code}, message: ${err.message}`);
61
+ });
62
+ } catch (exception) {
63
+ Logger.error(`Failed to set the system bar to be invisible. Cause code: ${exception.code}, message: ${exception.message}`);
64
+ }
65
+ }
66
+
67
+ async setColor(color: number, animated: boolean): Promise<void> {
68
+ Logger.info("###turboModule setColor");
69
+ let newSystemBarProperty: window.SystemBarProperties = {
70
+ statusBarColor: color.toString(),
71
+ enableStatusBarAnimation:animated
72
+ };
73
+ this.setWindowSystemBarProperties(newSystemBarProperty)
74
+ }
75
+
76
+ async setTranslucent(translucent: boolean): Promise<void> {
77
+ Logger.info("###turboModule setTranslucent");
78
+ let windowInstance: window.Window | undefined = undefined;
79
+ windowInstance = await window.getLastWindow(this.context);
80
+ let systemBarProperty = windowInstance.getWindowSystemBarProperties();
81
+ let newSystemBarProperty: window.SystemBarProperties = {
82
+ statusBarColor:translucent?'#00000000':systemBarProperty.statusBarColor,
83
+ };
84
+ this.setWindowSystemBarProperties(newSystemBarProperty)
85
+ }
86
+
87
+ setStyle(style: 'dark-content'|'light-content'): void {
88
+ Logger.info("###turboModule setStyle");
89
+ let themeFlag= style == "dark-content"
90
+ let newSystemBarProperty: window.SystemBarProperties = {
91
+ statusBarContentColor:themeFlag?"#000000":"#ffffff",
92
+ };
93
+ this.setWindowSystemBarProperties(newSystemBarProperty)
94
+ }
95
+
96
+ }
97
+
98
+
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ export enum KeyboardControllerEventName {
8
+ KEYBOARD_WILL_SHOW="KeyboardController::keyboardWillShow",
9
+ KEYBOARD_DID_SHOW="KeyboardController::keyboardDidShow",
10
+ KEYBOARD_WILL_HIDE="KeyboardController::keyboardWillHide",
11
+ KEYBOARD_DID_HIDE="KeyboardController::keyboardDidHide",
12
+ FOCUS_DID_SET="KeyboardController::focusDidSet"
13
+ }
14
+ export type KeyboardChangeResult = {
15
+ code:number;
16
+ message:string;
17
+ data:number | undefined
18
+ }
19
+ export type KeyboardEvent ={
20
+ height:number;
21
+ duration:number;
22
+ timestamp:number;
23
+ target:number;
24
+ }
25
+ export enum KeyboardStatusType {
26
+ HIDE = 0,
27
+ SHOW = 1
28
+ };
29
+ export type RawTouchPoint={
30
+ pointerId: number;
31
+ windowX: number;
32
+ windowY: number;
33
+ }
34
+ export type RawTouchEvent = {
35
+ action: number;
36
+ actionTouch: RawTouchPoint;
37
+ touchPoints: RawTouchPoint[];
38
+ sourceType: number;
39
+ timestamp: number;
40
+ rootTag:number;
41
+ };
@@ -0,0 +1,29 @@
1
+ {
2
+ "app": {
3
+ "bundleName": "com.rnoh.lhg.test",
4
+ "debug": true,
5
+ "versionCode": 1000000,
6
+ "versionName": "1.0.0",
7
+ "minAPIVersion": 50000012,
8
+ "targetAPIVersion": 50000012,
9
+ "apiReleaseType": "Beta5",
10
+ "compileSdkVersion": "5.0.0.60",
11
+ "compileSdkType": "HarmonyOS",
12
+ "appEnvironments": [],
13
+ "bundleType": "app"
14
+ },
15
+ "module": {
16
+ "name": "keyboard_controller",
17
+ "type": "har",
18
+ "deviceTypes": [
19
+ "default",
20
+ "tablet",
21
+ "2in1"
22
+ ],
23
+ "packageName": "@react-native-oh-tpl/react-native-keyboard-controller",
24
+ "installationFree": false,
25
+ "virtualMachine": "ark12.0.2.0",
26
+ "compileMode": "esmodule",
27
+ "dependencies": []
28
+ }
29
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "module": {
3
+ "name": "keyboard_controller",
4
+ "type": "har",
5
+ "deviceTypes": [
6
+ "default",
7
+ "tablet",
8
+ "2in1"
9
+ ]
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "page_show",
5
+ "value": "page from package"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3
+ * Use of this source code is governed by a MIT license that can be
4
+ * found in the LICENSE file.
5
+ */
6
+
7
+ export * from './src/main/ets/RNKeyboardControllerPackage.ets';
8
+ export * from './src/main/ets/RNKeyboardControllerTurboModule';
9
+ export * from './src/main/ets/RNStatusBarManagerCompatTurboModule';
Binary file
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.KeyboardProvider = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
10
+ var _bindings = require("./bindings");
11
+ var _context = require("./context");
12
+ var _internal = require("./internal");
13
+ var _monkeyPatch = require("./monkey-patch");
14
+ var _reanimated = require("./reanimated");
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
+ const KeyboardControllerViewAnimated = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.Animated.createAnimatedComponent(_bindings.KeyboardControllerView));
17
+ const styles = _reactNative.StyleSheet.create({
18
+ container: {
19
+ flex: 1
20
+ },
21
+ hidden: {
22
+ display: "none",
23
+ position: "absolute"
24
+ }
25
+ });
26
+ // capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package
27
+ // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/393 and https://github.com/kirillzyusko/react-native-keyboard-controller/issues/294 for more details
28
+ const OS = _reactNative.Platform.OS;
29
+ const KeyboardProvider = ({
30
+ children,
31
+ statusBarTranslucent,
32
+ navigationBarTranslucent,
33
+ enabled: initiallyEnabled = true
34
+ }) => {
35
+ // state
36
+ const [enabled, setEnabled] = (0, _react.useState)(initiallyEnabled);
37
+ // animated values
38
+ const progress = (0, _internal.useAnimatedValue)(0);
39
+ const height = (0, _internal.useAnimatedValue)(0);
40
+ // shared values
41
+ const progressSV = (0, _reactNativeReanimated.useSharedValue)(0);
42
+ const heightSV = (0, _reactNativeReanimated.useSharedValue)(0);
43
+ const layout = (0, _reactNativeReanimated.useSharedValue)(null);
44
+ const [setKeyboardHandlers, broadcastKeyboardEvents] = (0, _internal.useSharedHandlers)();
45
+ const [setInputHandlers, broadcastInputEvents] = (0, _internal.useSharedHandlers)();
46
+ // memo
47
+ const context = (0, _react.useMemo)(() => ({
48
+ enabled,
49
+ animated: {
50
+ progress: progress,
51
+ height: _reactNative.Animated.multiply(height, -1)
52
+ },
53
+ reanimated: {
54
+ progress: progressSV,
55
+ height: heightSV
56
+ },
57
+ layout,
58
+ setKeyboardHandlers,
59
+ setInputHandlers,
60
+ setEnabled
61
+ }), [enabled]);
62
+ const style = (0, _react.useMemo)(() => [styles.hidden, {
63
+ transform: [{
64
+ translateX: height
65
+ }, {
66
+ translateY: progress
67
+ }]
68
+ }], []);
69
+ const onKeyboardMove = (0, _react.useMemo)(() => _reactNative.Animated.event([{
70
+ nativeEvent: {
71
+ progress,
72
+ height
73
+ }
74
+ }], {
75
+ useNativeDriver: _reactNative.Platform.OS == 'harmony' ? false : true
76
+ }), []);
77
+ // handlers
78
+ const updateSharedValues = (event, platforms) => {
79
+ "worklet";
80
+
81
+ if (platforms.includes(OS)) {
82
+ // eslint-disable-next-line react-compiler/react-compiler
83
+ progressSV.value = event.progress;
84
+ heightSV.value = -event.height;
85
+ }
86
+ };
87
+ const keyboardHandler = (0, _reanimated.useAnimatedKeyboardHandler)({
88
+ onKeyboardMoveStart: event => {
89
+ "worklet";
90
+
91
+ broadcastKeyboardEvents("onStart", event);
92
+ updateSharedValues(event, ["ios"]);
93
+ },
94
+ onKeyboardMove: event => {
95
+ "worklet";
96
+
97
+ broadcastKeyboardEvents("onMove", event);
98
+ updateSharedValues(event, ["android"]);
99
+ },
100
+ onKeyboardMoveEnd: event => {
101
+ "worklet";
102
+
103
+ broadcastKeyboardEvents("onEnd", event);
104
+ updateSharedValues(event, ['harmony']);
105
+ },
106
+ onKeyboardMoveInteractive: event => {
107
+ "worklet";
108
+
109
+ updateSharedValues(event, ["android", "ios"]);
110
+ broadcastKeyboardEvents("onInteractive", event);
111
+ }
112
+ }, []);
113
+ const inputLayoutHandler = (0, _reanimated.useFocusedInputLayoutHandler)({
114
+ onFocusedInputLayoutChanged: e => {
115
+ "worklet";
116
+
117
+ if (e.target !== -1) {
118
+ layout.value = e;
119
+ } else {
120
+ layout.value = null;
121
+ }
122
+ }
123
+ }, []);
124
+ const inputTextHandler = (0, _reanimated.useFocusedInputTextHandler)({
125
+ onFocusedInputTextChanged: e => {
126
+ "worklet";
127
+
128
+ broadcastInputEvents("onChangeText", e);
129
+ }
130
+ }, []);
131
+ const inputSelectionHandler = (0, _reanimated.useFocusedInputSelectionHandler)({
132
+ onFocusedInputSelectionChanged: e => {
133
+ "worklet";
134
+
135
+ broadcastInputEvents("onSelectionChange", e);
136
+ }
137
+ }, []);
138
+ // effects
139
+ (0, _react.useEffect)(() => {
140
+ if (enabled) {
141
+ (0, _monkeyPatch.applyMonkeyPatch)();
142
+ } else {
143
+ (0, _monkeyPatch.revertMonkeyPatch)();
144
+ }
145
+ }, [enabled]);
146
+ return /*#__PURE__*/_react.default.createElement(_context.KeyboardContext.Provider, {
147
+ value: context
148
+ }, /*#__PURE__*/_react.default.createElement(KeyboardControllerViewAnimated, {
149
+ enabled: enabled,
150
+ onKeyboardMoveReanimated: keyboardHandler,
151
+ onKeyboardMoveStart: OS === "ios" ? onKeyboardMove : undefined,
152
+ onKeyboardMove: OS === "android" ? onKeyboardMove : undefined,
153
+ onKeyboardMoveInteractive: onKeyboardMove,
154
+ onKeyboardMoveEnd: OS === "harmony" ? onKeyboardMove : undefined,
155
+ onFocusedInputLayoutChangedReanimated: inputLayoutHandler,
156
+ onFocusedInputTextChangedReanimated: inputTextHandler,
157
+ onFocusedInputSelectionChangedReanimated: inputSelectionHandler,
158
+ navigationBarTranslucent: navigationBarTranslucent,
159
+ statusBarTranslucent: statusBarTranslucent,
160
+ style: styles.container
161
+ }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, null, children)), /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
162
+ // we are using this small hack, because if the component (where
163
+ // animated value has been used) is unmounted, then animation will
164
+ // stop receiving events (seems like it's react-native optimization).
165
+ // So we need to keep a reference to the animated value, to keep it's
166
+ // always mounted (keep a reference to an animated value).
167
+ //
168
+ // To test why it's needed, try to open screen which consumes Animated.Value
169
+ // then close it and open it again (for example 'Animated transition').
170
+ style: style
171
+ }));
172
+ };
173
+ exports.KeyboardProvider = KeyboardProvider;
174
+ //# sourceMappingURL=animated.js.map