@react-native-ohos/react-native-keyboard-controller 1.16.6-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 (269) 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 +7 -0
  6. package/harmony/keyboard_controller/ResourceTable.txt +1 -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 +73 -0
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +172 -0
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +76 -0
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +44 -0
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +58 -0
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +87 -0
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +62 -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/RNStatusBarManagerCompat.cpp +24 -0
  26. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -0
  27. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -0
  28. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -0
  29. package/harmony/keyboard_controller/src/main/ets/Logger.ts +46 -0
  30. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ts +45 -0
  31. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +238 -0
  32. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +98 -0
  33. package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -0
  34. package/harmony/keyboard_controller/src/main/module.json5 +11 -0
  35. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
  36. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
  37. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
  38. package/harmony/keyboard_controller/ts.ts +9 -0
  39. package/harmony/keyboard_controller.har +0 -0
  40. package/lib/commonjs/animated.js +176 -0
  41. package/lib/commonjs/animated.js.map +1 -0
  42. package/lib/commonjs/bindings.js +39 -0
  43. package/lib/commonjs/bindings.js.map +1 -0
  44. package/lib/commonjs/bindings.native.js +39 -0
  45. package/lib/commonjs/bindings.native.js.map +1 -0
  46. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +126 -0
  47. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
  48. package/lib/commonjs/components/KeyboardAvoidingView/index.js +120 -0
  49. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
  50. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +262 -0
  51. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
  52. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
  53. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  54. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
  55. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
  56. package/lib/commonjs/components/KeyboardStickyView/index.js +41 -0
  57. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
  58. package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
  59. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
  60. package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
  61. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
  62. package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
  63. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
  64. package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
  65. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
  66. package/lib/commonjs/components/KeyboardToolbar/index.js +161 -0
  67. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
  68. package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
  69. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
  70. package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
  71. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
  72. package/lib/commonjs/components/index.js +42 -0
  73. package/lib/commonjs/components/index.js.map +1 -0
  74. package/lib/commonjs/constants.js +27 -0
  75. package/lib/commonjs/constants.js.map +1 -0
  76. package/lib/commonjs/context.js +45 -0
  77. package/lib/commonjs/context.js.map +1 -0
  78. package/lib/commonjs/hooks/index.js +104 -0
  79. package/lib/commonjs/hooks/index.js.map +1 -0
  80. package/lib/commonjs/hooks/useWindowDimensions/index.android.js +34 -0
  81. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
  82. package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
  83. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
  84. package/lib/commonjs/index.js +136 -0
  85. package/lib/commonjs/index.js.map +1 -0
  86. package/lib/commonjs/internal.js +73 -0
  87. package/lib/commonjs/internal.js.map +1 -0
  88. package/lib/commonjs/module.js +47 -0
  89. package/lib/commonjs/module.js.map +1 -0
  90. package/lib/commonjs/monkey-patch.android.js +57 -0
  91. package/lib/commonjs/monkey-patch.android.js.map +1 -0
  92. package/lib/commonjs/monkey-patch.js +11 -0
  93. package/lib/commonjs/monkey-patch.js.map +1 -0
  94. package/lib/commonjs/reanimated.js +12 -0
  95. package/lib/commonjs/reanimated.js.map +1 -0
  96. package/lib/commonjs/reanimated.native.js +88 -0
  97. package/lib/commonjs/reanimated.native.js.map +1 -0
  98. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
  99. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  100. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
  101. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  102. package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
  103. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
  104. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
  105. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
  106. package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js +10 -0
  107. package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js.map +1 -0
  108. package/lib/commonjs/types.js +6 -0
  109. package/lib/commonjs/types.js.map +1 -0
  110. package/lib/commonjs/utils.js +9 -0
  111. package/lib/commonjs/utils.js.map +1 -0
  112. package/lib/commonjs/views/OverKeyboardView/index.js +42 -0
  113. package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -0
  114. package/lib/commonjs/views/index.js +14 -0
  115. package/lib/commonjs/views/index.js.map +1 -0
  116. package/lib/module/animated.js +168 -0
  117. package/lib/module/animated.js.map +1 -0
  118. package/lib/module/bindings.js +33 -0
  119. package/lib/module/bindings.js.map +1 -0
  120. package/lib/module/bindings.native.js +33 -0
  121. package/lib/module/bindings.native.js.map +1 -0
  122. package/lib/module/components/KeyboardAvoidingView/hooks.js +118 -0
  123. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
  124. package/lib/module/components/KeyboardAvoidingView/index.js +113 -0
  125. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
  126. package/lib/module/components/KeyboardAwareScrollView/index.js +255 -0
  127. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
  128. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
  129. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  130. package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
  131. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
  132. package/lib/module/components/KeyboardStickyView/index.js +34 -0
  133. package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
  134. package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
  135. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
  136. package/lib/module/components/KeyboardToolbar/Button.js +62 -0
  137. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
  138. package/lib/module/components/KeyboardToolbar/colors.js +15 -0
  139. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
  140. package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
  141. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
  142. package/lib/module/components/KeyboardToolbar/index.js +149 -0
  143. package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
  144. package/lib/module/components/KeyboardToolbar/types.js +2 -0
  145. package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
  146. package/lib/module/components/hooks/useColorScheme.js +4 -0
  147. package/lib/module/components/hooks/useColorScheme.js.map +1 -0
  148. package/lib/module/components/index.js +5 -0
  149. package/lib/module/components/index.js.map +1 -0
  150. package/lib/module/constants.js +21 -0
  151. package/lib/module/constants.js.map +1 -0
  152. package/lib/module/context.js +38 -0
  153. package/lib/module/context.js.map +1 -0
  154. package/lib/module/hooks/index.js +68 -0
  155. package/lib/module/hooks/index.js.map +1 -0
  156. package/lib/module/hooks/useWindowDimensions/index.android.js +27 -0
  157. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
  158. package/lib/module/hooks/useWindowDimensions/index.js +2 -0
  159. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
  160. package/lib/module/index.js +12 -0
  161. package/lib/module/index.js.map +1 -0
  162. package/lib/module/internal.js +66 -0
  163. package/lib/module/internal.js.map +1 -0
  164. package/lib/module/module.js +41 -0
  165. package/lib/module/module.js.map +1 -0
  166. package/lib/module/monkey-patch.android.js +47 -0
  167. package/lib/module/monkey-patch.android.js.map +1 -0
  168. package/lib/module/monkey-patch.js +5 -0
  169. package/lib/module/monkey-patch.js.map +1 -0
  170. package/lib/module/reanimated.js +6 -0
  171. package/lib/module/reanimated.js.map +1 -0
  172. package/lib/module/reanimated.native.js +78 -0
  173. package/lib/module/reanimated.native.js.map +1 -0
  174. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
  175. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  176. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
  177. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  178. package/lib/module/specs/NativeKeyboardController.js +3 -0
  179. package/lib/module/specs/NativeKeyboardController.js.map +1 -0
  180. package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
  181. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
  182. package/lib/module/specs/OverKeyboardViewNativeComponent.js +3 -0
  183. package/lib/module/specs/OverKeyboardViewNativeComponent.js.map +1 -0
  184. package/lib/module/types.js +2 -0
  185. package/lib/module/types.js.map +1 -0
  186. package/lib/module/utils.js +2 -0
  187. package/lib/module/utils.js.map +1 -0
  188. package/lib/module/views/OverKeyboardView/index.js +35 -0
  189. package/lib/module/views/OverKeyboardView/index.js.map +1 -0
  190. package/lib/module/views/index.js +2 -0
  191. package/lib/module/views/index.js.map +1 -0
  192. package/lib/typescript/animated.d.ts +39 -0
  193. package/lib/typescript/bindings.d.ts +12 -0
  194. package/lib/typescript/bindings.native.d.ts +12 -0
  195. package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +10 -0
  196. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +40 -0
  197. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +29 -0
  198. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
  199. package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
  200. package/lib/typescript/components/KeyboardStickyView/index.d.ts +39 -0
  201. package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
  202. package/lib/typescript/components/KeyboardToolbar/Button.d.ts +16 -0
  203. package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
  204. package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
  205. package/lib/typescript/components/KeyboardToolbar/index.d.ts +52 -0
  206. package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
  207. package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
  208. package/lib/typescript/components/index.d.ts +8 -0
  209. package/lib/typescript/constants.d.ts +16 -0
  210. package/lib/typescript/context.d.ts +23 -0
  211. package/lib/typescript/hooks/index.d.ts +17 -0
  212. package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
  213. package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
  214. package/lib/typescript/index.d.ts +10 -0
  215. package/lib/typescript/internal.d.ts +30 -0
  216. package/lib/typescript/module.d.ts +2 -0
  217. package/lib/typescript/monkey-patch.android.d.ts +2 -0
  218. package/lib/typescript/monkey-patch.d.ts +2 -0
  219. package/lib/typescript/reanimated.d.ts +5 -0
  220. package/lib/typescript/reanimated.native.d.ts +7 -0
  221. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +54 -0
  222. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +12 -0
  223. package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
  224. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
  225. package/lib/typescript/specs/OverKeyboardViewNativeComponent.d.ts +7 -0
  226. package/lib/typescript/types.d.ts +161 -0
  227. package/lib/typescript/utils.d.ts +1 -0
  228. package/lib/typescript/views/OverKeyboardView/index.d.ts +5 -0
  229. package/lib/typescript/views/index.d.ts +1 -0
  230. package/package.json +173 -0
  231. package/react-native-keyboard-controller.podspec +61 -0
  232. package/src/animated.tsx +256 -0
  233. package/src/bindings.native.ts +62 -0
  234. package/src/bindings.ts +42 -0
  235. package/src/components/KeyboardAvoidingView/hooks.ts +123 -0
  236. package/src/components/KeyboardAvoidingView/index.tsx +188 -0
  237. package/src/components/KeyboardAwareScrollView/index.tsx +389 -0
  238. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
  239. package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
  240. package/src/components/KeyboardStickyView/index.tsx +66 -0
  241. package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
  242. package/src/components/KeyboardToolbar/Button.tsx +98 -0
  243. package/src/components/KeyboardToolbar/colors.native.ts +37 -0
  244. package/src/components/KeyboardToolbar/colors.ts +16 -0
  245. package/src/components/KeyboardToolbar/index.tsx +223 -0
  246. package/src/components/KeyboardToolbar/types.ts +40 -0
  247. package/src/components/hooks/useColorScheme.ts +5 -0
  248. package/src/components/index.ts +11 -0
  249. package/src/constants.ts +19 -0
  250. package/src/context.ts +68 -0
  251. package/src/hooks/index.ts +90 -0
  252. package/src/hooks/useWindowDimensions/index.android.ts +38 -0
  253. package/src/hooks/useWindowDimensions/index.ts +1 -0
  254. package/src/index.ts +23 -0
  255. package/src/internal.ts +84 -0
  256. package/src/module.ts +52 -0
  257. package/src/monkey-patch.android.ts +44 -0
  258. package/src/monkey-patch.ts +4 -0
  259. package/src/reanimated.native.ts +132 -0
  260. package/src/reanimated.ts +29 -0
  261. package/src/specs/KeyboardControllerViewNativeComponent.ts +71 -0
  262. package/src/specs/KeyboardGestureAreaNativeComponent.ts +20 -0
  263. package/src/specs/NativeKeyboardController.ts +19 -0
  264. package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
  265. package/src/specs/OverKeyboardViewNativeComponent.ts +12 -0
  266. package/src/types.ts +243 -0
  267. package/src/utils.ts +1 -0
  268. package/src/views/OverKeyboardView/index.tsx +43 -0
  269. package/src/views/index.ts +1 -0
@@ -0,0 +1,238 @@
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
+ import { ConfigurationConstant } from '@kit.AbilityKit';
16
+
17
+ declare function px2vp(px: number): number;
18
+
19
+ interface RNKeyboardControllerSpec {
20
+ getConstants(): {};
21
+
22
+ setInputMode(mode: number): void;
23
+
24
+ setDefaultMode(): void;
25
+
26
+ dismiss(keepFocus: boolean): void;
27
+
28
+ setFocusTo(direction: string): void;
29
+
30
+ addListener(eventName: string, listener: (event) => void,): void;
31
+
32
+ removeListeners(count: number): void;
33
+ }
34
+
35
+ export class RNKeyboardControllerTurboModule extends TurboModule implements RNKeyboardControllerSpec {
36
+ private context: common.UIAbilityContext;
37
+ private keyboardHeight: number;
38
+ private keyboardStatus: KeyboardStatusType;
39
+ private eventListeners: KeyboardControllerEventName[];
40
+ private currentWindow:window.Window;
41
+ private enabled:boolean;
42
+ constructor(ctx) {
43
+ super(ctx);
44
+ this.context = this.ctx.uiAbilityContext;
45
+ this.eventListeners = this.supportListeners();
46
+ }
47
+
48
+ readonly getConstants: () => {};
49
+
50
+ // set mode
51
+ setInputMode(mode: number): void {
52
+ Logger.info('harmonyOS not support setInputMode')
53
+ }
54
+
55
+ setDefaultMode(): void {
56
+ Logger.info('harmonyOS not support setDefaultMode')
57
+ }
58
+
59
+ /**
60
+ * @description 键盘隐藏
61
+ * */
62
+ dismiss(keepFocus: boolean): void {
63
+ let inputMethodController = inputMethod.getController();
64
+ inputMethodController.stopInputSession()
65
+
66
+ }
67
+ /**
68
+ * @description 键盘隐藏
69
+ * */
70
+ private show(): void {
71
+ let inputMethodController = inputMethod.getController();
72
+ inputMethodController.showSoftKeyboard()
73
+
74
+ }
75
+
76
+ setFocusTo(direction: string): void {
77
+ this.ctx.rnInstance.postMessageToCpp('setFocusTo', direction);
78
+ }
79
+
80
+ /**
81
+ * @description 添加监听键盘事件
82
+ */
83
+ addListener(eventName: KeyboardControllerEventName) {
84
+ let supportEvents = this.supportListeners()
85
+ let bo = supportEvents.includes(eventName)
86
+ if (bo && !this.eventListeners.includes(eventName)) {
87
+ this.eventListeners.push(eventName)
88
+ }
89
+ }
90
+
91
+ /**
92
+ * @description 删除监听事件
93
+ * */
94
+ removeListeners(count: number): void {
95
+ let num = this.eventListeners.length;
96
+ if (num>0) {
97
+ this.eventListeners = [];
98
+ }
99
+ }
100
+
101
+ private supportListeners() {
102
+ return [
103
+ KeyboardControllerEventName.KEYBOARD_WILL_SHOW,
104
+ KeyboardControllerEventName.KEYBOARD_DID_SHOW,
105
+ KeyboardControllerEventName.KEYBOARD_WILL_HIDE,
106
+ KeyboardControllerEventName.KEYBOARD_DID_HIDE,
107
+ KeyboardControllerEventName.FOCUS_DID_SET
108
+ ];
109
+ }
110
+
111
+ private async setWindowSystemBarEnable(statusBarTranslucent: boolean, navigationBarTranslucent: boolean) {
112
+
113
+ let windowInstance: window.Window | undefined = undefined;
114
+ windowInstance = await window.getLastWindow(this.context);
115
+ let systemBarProperty = windowInstance.getWindowSystemBarProperties();
116
+ let newSystemBarProperty: window.SystemBarProperties = {
117
+ ...systemBarProperty,
118
+ statusBarColor: statusBarTranslucent ? "#00000000" : systemBarProperty.statusBarColor,
119
+ navigationBarColor: navigationBarTranslucent ? "#00000000" : systemBarProperty.navigationBarColor
120
+ };
121
+ try {
122
+ let promise = windowInstance.setWindowSystemBarProperties(newSystemBarProperty);
123
+ promise.then(() => {
124
+ Logger.info('Succeeded in setting the system bar properties.');
125
+ }).catch((err: BusinessError) => {
126
+ Logger.error(`Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`);
127
+ });
128
+ } catch (exception) {
129
+ Logger.error(`Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`);
130
+ }
131
+ }
132
+
133
+ private keyboardControllerEventHandle(keyboardStatus: number, height: number) {
134
+ Logger.info('###turboModule keyboardControllerEventHandle', String(keyboardStatus) + ',' + String(height));
135
+ if(!this.enabled){
136
+ return
137
+ }
138
+
139
+ if (this.keyboardStatus == KeyboardStatusType.HIDE) {
140
+ // 键盘隐藏
141
+ Logger.info('###turboModule keyboardControllerEventHandle');
142
+ this.eventListeners.includes(KeyboardControllerEventName.KEYBOARD_DID_HIDE) &&
143
+ this.ctx.rnInstance.emitDeviceEvent(KeyboardControllerEventName.KEYBOARD_DID_HIDE, {
144
+ duration: 0,
145
+ timestamp: new Date().getTime(),
146
+ target: 0,
147
+ height: height,
148
+ tag:0,
149
+ appearance:this.getKeyboardAppearance()
150
+ });
151
+ }
152
+ if (this.keyboardStatus == KeyboardStatusType.SHOW) {
153
+ // 键盘显示
154
+ Logger.info('###turboModule keyboardControllerEventHandle');
155
+ this.eventListeners.includes(KeyboardControllerEventName.KEYBOARD_DID_SHOW) &&
156
+ this.ctx.rnInstance.emitDeviceEvent(KeyboardControllerEventName.KEYBOARD_DID_SHOW, {
157
+ duration: 0,
158
+ timestamp: new Date().getTime(),
159
+ target: 0,
160
+ height:height,
161
+ tag:0,
162
+ appearance:this.getKeyboardAppearance()
163
+ });
164
+ }
165
+ }
166
+
167
+ private async startKeyboardObserver(open:boolean) {
168
+ Logger.info("###turboModule startKeyboardObserver",String(open));
169
+ this.enabled=open;
170
+ this.currentWindow = await window.getLastWindow(this.context);
171
+ if (!this.currentWindow) {
172
+ throw ('windowInstance is null')
173
+ return
174
+ }
175
+ if(!open){
176
+ try {
177
+ Logger.info("###turboModule Close KeyboardObserver");
178
+ this.currentWindow.off('keyboardHeightChange', (data) => {
179
+ this.keyboardStatus = KeyboardStatusType.HIDE;
180
+ this.keyboardHeight = 0;
181
+ Logger.info('### close keyboardHeightChange observer');
182
+ });
183
+ } catch (exception) {
184
+ Logger.error('### Failed to close the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
185
+ }
186
+ }else{
187
+ try {
188
+ this.currentWindow.on('keyboardHeightChange', (data) => {
189
+ const keyboardAvoidArea = this.currentWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD).bottomRect;
190
+ let height = Math.ceil(px2vp(keyboardAvoidArea.height))
191
+ if(open){
192
+ if(this.keyboardHeight == height ){
193
+ return
194
+ }
195
+ if (height > 0) {
196
+ this.keyboardStatus = KeyboardStatusType.SHOW;
197
+ } else {
198
+ this.keyboardStatus = KeyboardStatusType.HIDE;
199
+ }
200
+ this.keyboardHeight = height;
201
+ this.keyboardControllerEventHandle(this.keyboardStatus, height);
202
+ this.ctx.rnInstance.postMessageToCpp('keyboardHeightChange', height);
203
+ }
204
+
205
+ });
206
+ } catch (exception) {
207
+ Logger.error('Failed to enable the listener for keyboard height changes. Cause: ' + JSON.stringify(exception));
208
+ }
209
+ }
210
+
211
+ }
212
+
213
+ private getKeyboardAppearance(): String {
214
+ const colorMode = this.context.config.colorMode;
215
+ if (colorMode == ConfigurationConstant.ColorMode.COLOR_MODE_DARK) {
216
+ return "dark";
217
+ }
218
+ else if (colorMode == ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT) {
219
+ return "light";
220
+ }
221
+ return "default";
222
+ }
223
+
224
+ private async setWindowLayoutFullScreen(preserveEdgeToEdge:boolean){
225
+ let windowInstance: window.Window | undefined = undefined;
226
+ windowInstance = await window.getLastWindow(this.context);
227
+ try {
228
+ let promise = windowInstance.setWindowLayoutFullScreen(preserveEdgeToEdge);
229
+ promise.then(() => {
230
+ Logger.info('Succeeded in setWindowLayoutFullScreen .' + preserveEdgeToEdge);
231
+ }).catch((err: BusinessError) => {
232
+ Logger.error(`Failed to setWindowLayoutFullScreen. Cause code: ${err.code}, message: ${err.message}`);
233
+ });
234
+ } catch (exception) {
235
+ Logger.error(`Failed to setWindowLayoutFullScreen. Cause code: ${exception.code}, message: ${exception.message}`);
236
+ }
237
+ }
238
+ }
@@ -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,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';
8
+ export * from './src/main/ets/RNKeyboardControllerTurboModule';
9
+ export * from './src/main/ets/RNStatusBarManagerCompatTurboModule';
Binary file
@@ -0,0 +1,176 @@
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
+ preserveEdgeToEdge = true,
34
+ enabled: initiallyEnabled = true
35
+ }) => {
36
+ // state
37
+ const [enabled, setEnabled] = (0, _react.useState)(initiallyEnabled);
38
+ // animated values
39
+ const progress = (0, _internal.useAnimatedValue)(0);
40
+ const height = (0, _internal.useAnimatedValue)(0);
41
+ // shared values
42
+ const progressSV = (0, _reactNativeReanimated.useSharedValue)(0);
43
+ const heightSV = (0, _reactNativeReanimated.useSharedValue)(0);
44
+ const layout = (0, _reactNativeReanimated.useSharedValue)(null);
45
+ const [setKeyboardHandlers, broadcastKeyboardEvents] = (0, _internal.useSharedHandlers)();
46
+ const [setInputHandlers, broadcastInputEvents] = (0, _internal.useSharedHandlers)();
47
+ // memo
48
+ const context = (0, _react.useMemo)(() => ({
49
+ enabled,
50
+ animated: {
51
+ progress: progress,
52
+ height: _reactNative.Animated.multiply(height, -1)
53
+ },
54
+ reanimated: {
55
+ progress: progressSV,
56
+ height: heightSV
57
+ },
58
+ layout,
59
+ setKeyboardHandlers,
60
+ setInputHandlers,
61
+ setEnabled
62
+ }), [enabled]);
63
+ const style = (0, _react.useMemo)(() => [styles.hidden, {
64
+ transform: [{
65
+ translateX: height
66
+ }, {
67
+ translateY: progress
68
+ }]
69
+ }], []);
70
+ const onKeyboardMove = (0, _react.useMemo)(() => _reactNative.Animated.event([{
71
+ nativeEvent: {
72
+ progress,
73
+ height
74
+ }
75
+ }], {
76
+ useNativeDriver: _reactNative.Platform.OS == 'harmony' ? false : true
77
+ }), []);
78
+ // handlers
79
+ const updateSharedValues = (event, platforms) => {
80
+ "worklet";
81
+
82
+ if (platforms.includes(OS)) {
83
+ // eslint-disable-next-line react-compiler/react-compiler
84
+ progressSV.value = event.progress;
85
+ heightSV.value = -event.height;
86
+ }
87
+ };
88
+ const keyboardHandler = (0, _reanimated.useAnimatedKeyboardHandler)({
89
+ onKeyboardMoveStart: event => {
90
+ "worklet";
91
+
92
+ broadcastKeyboardEvents("onStart", event);
93
+ updateSharedValues(event, ["ios"]);
94
+ },
95
+ onKeyboardMove: event => {
96
+ "worklet";
97
+
98
+ broadcastKeyboardEvents("onMove", event);
99
+ updateSharedValues(event, ["android"]);
100
+ },
101
+ onKeyboardMoveEnd: event => {
102
+ "worklet";
103
+
104
+ broadcastKeyboardEvents("onEnd", event);
105
+ updateSharedValues(event, ['harmony']);
106
+ },
107
+ onKeyboardMoveInteractive: event => {
108
+ "worklet";
109
+
110
+ updateSharedValues(event, ["android", "ios"]);
111
+ broadcastKeyboardEvents("onInteractive", event);
112
+ }
113
+ }, []);
114
+ const inputLayoutHandler = (0, _reanimated.useFocusedInputLayoutHandler)({
115
+ onFocusedInputLayoutChanged: e => {
116
+ "worklet";
117
+
118
+ if (e.target !== -1) {
119
+ layout.value = e;
120
+ } else {
121
+ layout.value = null;
122
+ }
123
+ }
124
+ }, []);
125
+ const inputTextHandler = (0, _reanimated.useFocusedInputTextHandler)({
126
+ onFocusedInputTextChanged: e => {
127
+ "worklet";
128
+
129
+ broadcastInputEvents("onChangeText", e);
130
+ }
131
+ }, []);
132
+ const inputSelectionHandler = (0, _reanimated.useFocusedInputSelectionHandler)({
133
+ onFocusedInputSelectionChanged: e => {
134
+ "worklet";
135
+
136
+ broadcastInputEvents("onSelectionChange", e);
137
+ }
138
+ }, []);
139
+ // effects
140
+ (0, _react.useEffect)(() => {
141
+ if (enabled) {
142
+ (0, _monkeyPatch.applyMonkeyPatch)();
143
+ } else {
144
+ (0, _monkeyPatch.revertMonkeyPatch)();
145
+ }
146
+ }, [enabled]);
147
+ return /*#__PURE__*/_react.default.createElement(_context.KeyboardContext.Provider, {
148
+ value: context
149
+ }, /*#__PURE__*/_react.default.createElement(KeyboardControllerViewAnimated, {
150
+ enabled: enabled,
151
+ onKeyboardMoveReanimated: keyboardHandler,
152
+ onKeyboardMoveStart: OS === "ios" ? onKeyboardMove : undefined,
153
+ onKeyboardMove: OS === "android" ? onKeyboardMove : undefined,
154
+ onKeyboardMoveInteractive: onKeyboardMove,
155
+ onKeyboardMoveEnd: OS === "harmony" ? onKeyboardMove : undefined,
156
+ onFocusedInputLayoutChangedReanimated: inputLayoutHandler,
157
+ onFocusedInputTextChangedReanimated: inputTextHandler,
158
+ onFocusedInputSelectionChangedReanimated: inputSelectionHandler,
159
+ navigationBarTranslucent: navigationBarTranslucent,
160
+ statusBarTranslucent: statusBarTranslucent,
161
+ preserveEdgeToEdge: preserveEdgeToEdge,
162
+ style: styles.container
163
+ }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, null, children)), /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
164
+ // we are using this small hack, because if the component (where
165
+ // animated value has been used) is unmounted, then animation will
166
+ // stop receiving events (seems like it's react-native optimization).
167
+ // So we need to keep a reference to the animated value, to keep it's
168
+ // always mounted (keep a reference to an animated value).
169
+ //
170
+ // To test why it's needed, try to open screen which consumes Animated.Value
171
+ // then close it and open it again (for example 'Animated transition').
172
+ style: style
173
+ }));
174
+ };
175
+ exports.KeyboardProvider = KeyboardProvider;
176
+ //# sourceMappingURL=animated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_bindings","_context","_internal","_monkeyPatch","_reanimated","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","KeyboardControllerViewAnimated","Reanimated","createAnimatedComponent","Animated","KeyboardControllerView","styles","StyleSheet","create","container","flex","hidden","display","position","OS","Platform","KeyboardProvider","children","statusBarTranslucent","navigationBarTranslucent","preserveEdgeToEdge","enabled","initiallyEnabled","setEnabled","useState","progress","useAnimatedValue","height","progressSV","useSharedValue","heightSV","layout","setKeyboardHandlers","broadcastKeyboardEvents","useSharedHandlers","setInputHandlers","broadcastInputEvents","context","useMemo","animated","multiply","reanimated","style","transform","translateX","translateY","onKeyboardMove","event","nativeEvent","useNativeDriver","updateSharedValues","platforms","includes","value","keyboardHandler","useAnimatedKeyboardHandler","onKeyboardMoveStart","onKeyboardMoveEnd","onKeyboardMoveInteractive","inputLayoutHandler","useFocusedInputLayoutHandler","onFocusedInputLayoutChanged","target","inputTextHandler","useFocusedInputTextHandler","onFocusedInputTextChanged","inputSelectionHandler","useFocusedInputSelectionHandler","onFocusedInputSelectionChanged","useEffect","applyMonkeyPatch","revertMonkeyPatch","createElement","KeyboardContext","Provider","onKeyboardMoveReanimated","undefined","onFocusedInputLayoutChangedReanimated","onFocusedInputTextChangedReanimated","onFocusedInputSelectionChangedReanimated","View","exports"],"sources":["animated.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useState } from \"react\";\nimport { Animated, Platform, StyleSheet } from \"react-native\";\nimport Reanimated, { useSharedValue } from \"react-native-reanimated\";\n\nimport { KeyboardControllerView } from \"./bindings\";\nimport { KeyboardContext } from \"./context\";\nimport { useAnimatedValue, useSharedHandlers } from \"./internal\";\nimport { applyMonkeyPatch, revertMonkeyPatch } from \"./monkey-patch\";\nimport {\n useAnimatedKeyboardHandler,\n useFocusedInputLayoutHandler,\n useFocusedInputSelectionHandler,\n useFocusedInputTextHandler,\n} from \"./reanimated\";\n\nimport type { KeyboardAnimationContext } from \"./context\";\nimport type {\n FocusedInputHandler,\n FocusedInputLayoutChangedEvent,\n KeyboardControllerProps,\n KeyboardHandler,\n NativeEvent,\n} from \"./types\";\nimport type { ViewStyle } from \"react-native\";\n\nconst KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(\n Animated.createAnimatedComponent(\n KeyboardControllerView,\n ) as React.FC<KeyboardControllerProps>,\n);\n\ntype Styles = {\n container: ViewStyle;\n hidden: ViewStyle;\n};\n\nconst styles = StyleSheet.create<Styles>({\n container: {\n flex: 1,\n },\n hidden: {\n display: \"none\",\n position: \"absolute\",\n },\n});\n\ntype KeyboardProviderProps = {\n children: React.ReactNode;\n /**\n * Set the value to `true`, if you use translucent status bar on Android.\n * If you already control status bar translucency via `react-native-screens`\n * or `StatusBar` component from `react-native`, you can ignore it.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14\n * @platform android\n */\n statusBarTranslucent?: boolean;\n /**\n * Set the value to `true`, if you use translucent navigation bar on Android.\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119\n * @platform android\n */\n navigationBarTranslucent?: boolean;\n /**\n * A boolean property indicating whether to keep edge-to-edge mode always enabled (even when you disable the module).\n * Defaults to `false`.\n *\n * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/592\n * @platform android\n */\n preserveEdgeToEdge?: boolean;\n /**\n * A boolean prop indicating whether the module is enabled. It indicate only initial state,\n * i. e. if you try to change this prop after component mount it will not have any effect.\n * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.\n * Defaults to `true`.\n */\n enabled?: boolean;\n};\n\n// capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package\n// 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\nconst OS = Platform.OS;\n\nexport const KeyboardProvider = ({\n children,\n statusBarTranslucent,\n navigationBarTranslucent,\n preserveEdgeToEdge = true,\n enabled: initiallyEnabled = true,\n}: KeyboardProviderProps) => {\n // state\n const [enabled, setEnabled] = useState(initiallyEnabled);\n // animated values\n const progress = useAnimatedValue(0);\n const height = useAnimatedValue(0);\n // shared values\n const progressSV = useSharedValue(0);\n const heightSV = useSharedValue(0);\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n const [setKeyboardHandlers, broadcastKeyboardEvents] =\n useSharedHandlers<KeyboardHandler>();\n const [setInputHandlers, broadcastInputEvents] =\n useSharedHandlers<FocusedInputHandler>();\n // memo\n const context = useMemo<KeyboardAnimationContext>(\n () => ({\n enabled,\n animated: { progress: progress, height: Animated.multiply(height,-1) },\n reanimated: { progress: progressSV, height: heightSV },\n layout,\n setKeyboardHandlers,\n setInputHandlers,\n setEnabled,\n }),\n [enabled],\n );\n const style = useMemo(\n () => [\n styles.hidden,\n { transform: [{ translateX: height }, { translateY: progress }] },\n ],\n [],\n );\n const onKeyboardMove = useMemo(\n () =>\n Animated.event(\n [\n {\n nativeEvent: {\n progress,\n height,\n },\n },\n ],\n { useNativeDriver:Platform.OS as string=='harmony'?false:true },\n ),\n [],\n );\n // handlers\n const updateSharedValues = (event: NativeEvent, platforms: string[]) => {\n \"worklet\";\n\n if (platforms.includes(OS)) {\n // eslint-disable-next-line react-compiler/react-compiler\n progressSV.value = event.progress;\n heightSV.value = -event.height;\n }\n };\n const keyboardHandler = useAnimatedKeyboardHandler(\n {\n onKeyboardMoveStart: (event: NativeEvent) => {\n \"worklet\";\n\n broadcastKeyboardEvents(\"onStart\", event);\n updateSharedValues(event, [\"ios\"]);\n },\n onKeyboardMove: (event: NativeEvent) => {\n \"worklet\";\n\n broadcastKeyboardEvents(\"onMove\", event);\n updateSharedValues(event, [\"android\"]);\n },\n onKeyboardMoveEnd: (event: NativeEvent) => {\n \"worklet\";\n broadcastKeyboardEvents(\"onEnd\", event);\n updateSharedValues(event, ['harmony']);\n },\n onKeyboardMoveInteractive: (event: NativeEvent) => {\n \"worklet\";\n\n updateSharedValues(event, [\"android\", \"ios\"]);\n broadcastKeyboardEvents(\"onInteractive\", event);\n },\n },\n [],\n );\n const inputLayoutHandler = useFocusedInputLayoutHandler(\n {\n onFocusedInputLayoutChanged: (e) => {\n \"worklet\";\n\n if (e.target !== -1) {\n layout.value = e;\n } else {\n layout.value = null;\n }\n },\n },\n [],\n );\n const inputTextHandler = useFocusedInputTextHandler(\n {\n onFocusedInputTextChanged: (e) => {\n \"worklet\";\n\n broadcastInputEvents(\"onChangeText\", e);\n },\n },\n [],\n );\n const inputSelectionHandler = useFocusedInputSelectionHandler(\n {\n onFocusedInputSelectionChanged: (e) => {\n \"worklet\";\n broadcastInputEvents(\"onSelectionChange\", e);\n },\n },\n [],\n );\n // effects\n useEffect(() => {\n if (enabled) {\n applyMonkeyPatch();\n } else {\n revertMonkeyPatch();\n }\n }, [enabled]);\n\n return (\n <KeyboardContext.Provider value={context}>\n <KeyboardControllerViewAnimated\n enabled={enabled}\n onKeyboardMoveReanimated={keyboardHandler}\n onKeyboardMoveStart={OS === \"ios\" ? onKeyboardMove : undefined}\n onKeyboardMove={OS === \"android\" ? onKeyboardMove : undefined}\n onKeyboardMoveInteractive={onKeyboardMove}\n onKeyboardMoveEnd={ OS as string === \"harmony\"?onKeyboardMove:undefined}\n onFocusedInputLayoutChangedReanimated={inputLayoutHandler}\n onFocusedInputTextChangedReanimated={inputTextHandler}\n onFocusedInputSelectionChangedReanimated={inputSelectionHandler}\n navigationBarTranslucent={navigationBarTranslucent}\n statusBarTranslucent={statusBarTranslucent}\n preserveEdgeToEdge={preserveEdgeToEdge}\n style={styles.container}\n >\n <Reanimated.View>{children}</Reanimated.View>\n {/* {children} */}\n </KeyboardControllerViewAnimated>\n <Animated.View\n // we are using this small hack, because if the component (where\n // animated value has been used) is unmounted, then animation will\n // stop receiving events (seems like it's react-native optimization).\n // So we need to keep a reference to the animated value, to keep it's\n // always mounted (keep a reference to an animated value).\n //\n // To test why it's needed, try to open screen which consumes Animated.Value\n // then close it and open it again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