@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,84 @@
1
+ import { useCallback, useRef } from "react";
2
+ import { Animated } from "react-native";
3
+ import { useSharedValue } from "react-native-reanimated";
4
+
5
+ import type { Handlers } from "./types";
6
+
7
+ type UntypedHandler = Record<string, (event: never) => void>;
8
+ type SharedHandlersReturnType<T extends UntypedHandler> = [
9
+ (handler: Handlers<T>) => void,
10
+ <K extends keyof T>(type: K, event: Parameters<T[K]>[0]) => void,
11
+ ];
12
+
13
+ /**
14
+ * Hook for storing worklet handlers (objects with keys, where values are worklets).
15
+ * Returns methods for setting handlers and broadcasting events in them.
16
+ *
17
+ * T is a generic that looks like:
18
+ * @example
19
+ * {
20
+ * onEvent: () => {},
21
+ * onEvent2: () => {},
22
+ * }
23
+ */
24
+ export function useSharedHandlers<
25
+ T extends UntypedHandler,
26
+ >(): SharedHandlersReturnType<T> {
27
+ const handlers = useSharedValue<Handlers<T>>({});
28
+ const jsHandlers = useRef<Handlers<T>>({});
29
+
30
+ // since js -> worklet -> js call is asynchronous, we can not write handlers
31
+ // straight into shared variable (using current shared value as a previous result),
32
+ // since there may be a race condition in a call, and closure may have out-of-dated
33
+ // values. As a result, some of handlers may be not written to "all handlers" object.
34
+ // Below we are writing all handlers to `ref` and afterwards synchronize them with
35
+ // shared value (since `refs` are not referring to actual value in worklets).
36
+ // This approach allow us to update synchronously handlers in js thread (and it assures,
37
+ // that it will have all of them) and then update them in worklet thread (calls are
38
+ // happening in FIFO order, so we will always have actual value).
39
+ const updateSharedHandlers = () => {
40
+ // eslint-disable-next-line react-compiler/react-compiler
41
+ handlers.value = jsHandlers.current;
42
+ };
43
+ const setHandlers = useCallback((handler: Handlers<T>) => {
44
+ jsHandlers.current = {
45
+ ...jsHandlers.current,
46
+ ...handler,
47
+ };
48
+ updateSharedHandlers();
49
+ }, []);
50
+ const broadcast = <K extends keyof T>(
51
+ type: K,
52
+ event: Parameters<T[K]>[0],
53
+ ) => {
54
+ "worklet";
55
+
56
+ Object.keys(handlers.value).forEach((key) => {
57
+ handlers.value[key]?.[type]?.(event);
58
+ });
59
+ };
60
+
61
+ return [setHandlers, broadcast];
62
+ }
63
+
64
+ /**
65
+ * TS variant of `useAnimatedValue` hook which is added in RN 0.71
66
+ * A better alternative of storing animated values in refs, since
67
+ * it doesn't recreate a new `Animated.Value` object on every re-render
68
+ * and therefore consumes less memory. We can not use a variant from
69
+ * RN, since this library supports earlier versions of RN.
70
+ *
71
+ * @see https://github.com/facebook/react-native/commit/e22217fe8b9455e32695f88ca835e11442b0a937
72
+ */
73
+ export function useAnimatedValue(
74
+ initialValue: number,
75
+ config?: Animated.AnimatedConfig,
76
+ ): Animated.Value {
77
+ const ref = useRef<Animated.Value | null>(null);
78
+
79
+ if (ref.current == null) {
80
+ ref.current = new Animated.Value(initialValue, config);
81
+ }
82
+
83
+ return ref.current;
84
+ }
@@ -0,0 +1,44 @@
1
+ // @ts-expect-error because there is no corresponding type definition
2
+ import * as NativeAndroidManager from "react-native/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid";
3
+
4
+ const RCTStatusBarManagerCompat =
5
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
6
+ require("./specs/NativeStatusBarManagerCompat").default;
7
+
8
+ // Copy original default manager to keep its original state and methods
9
+ const OriginalNativeAndroidManager = { ...NativeAndroidManager.default };
10
+
11
+ // Create a new object that modifies the necessary methods
12
+ // On Android < 11 RN uses legacy API which breaks EdgeToEdge mode in RN, so
13
+ // in order to use library on all available platforms we have to monkey patch
14
+ // default RN implementation and use modern `WindowInsetsControllerCompat`.
15
+ const ModifiedNativeAndroidManager = {
16
+ ...NativeAndroidManager.default, // Spread original properties to keep existing functionality
17
+ setColor: (color: number, animated: boolean): void => {
18
+ RCTStatusBarManagerCompat.setColor(color, animated);
19
+ },
20
+ setTranslucent: (translucent: boolean): void => {
21
+ RCTStatusBarManagerCompat.setTranslucent(translucent);
22
+ },
23
+ /**
24
+ * - statusBarStyles can be:
25
+ * - 'default'
26
+ * - 'dark-content'
27
+ */
28
+ setStyle: (statusBarStyle?: string): void => {
29
+ RCTStatusBarManagerCompat.setStyle(statusBarStyle);
30
+ },
31
+ setHidden: (hidden: boolean): void => {
32
+ RCTStatusBarManagerCompat.setHidden(hidden);
33
+ },
34
+ };
35
+
36
+ // Define a function to apply the monkey patch
37
+ export const applyMonkeyPatch = () => {
38
+ Object.assign(NativeAndroidManager.default, ModifiedNativeAndroidManager);
39
+ };
40
+
41
+ // Define a function to revert changes back to the original state
42
+ export const revertMonkeyPatch = () => {
43
+ Object.assign(NativeAndroidManager.default, OriginalNativeAndroidManager);
44
+ };
@@ -0,0 +1,4 @@
1
+ // stub for all platforms
2
+ const NOOP = () => {};
3
+ export const applyMonkeyPatch = NOOP;
4
+ export const revertMonkeyPatch = NOOP;
@@ -0,0 +1,132 @@
1
+ import { useEvent, useHandler } from "react-native-reanimated";
2
+
3
+ import type {
4
+ EventWithName,
5
+ FocusedInputLayoutChangedEvent,
6
+ FocusedInputLayoutHandlerHook,
7
+ FocusedInputSelectionChangedEvent,
8
+ FocusedInputSelectionHandlerHook,
9
+ FocusedInputTextChangedEvent,
10
+ FocusedInputTextHandlerHook,
11
+ KeyboardHandlerHook,
12
+ NativeEvent,
13
+ } from "./types";
14
+
15
+ type EventContext = Record<string, unknown>;
16
+
17
+ export const useAnimatedKeyboardHandler: KeyboardHandlerHook<
18
+ EventContext,
19
+ EventWithName<NativeEvent>
20
+ > = (handlers, dependencies) => {
21
+ const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
22
+
23
+ return useEvent(
24
+ (event) => {
25
+ "worklet";
26
+ const {
27
+ onKeyboardMoveStart,
28
+ onKeyboardMove,
29
+ onKeyboardMoveEnd,
30
+ onKeyboardMoveInteractive,
31
+ } = handlers;
32
+
33
+ if (
34
+ onKeyboardMoveStart &&
35
+ event.eventName.endsWith("onKeyboardMoveStart")
36
+ ) {
37
+ onKeyboardMoveStart(event, context);
38
+ }
39
+
40
+ if (onKeyboardMove && event.eventName.endsWith("onKeyboardMove")) {
41
+ onKeyboardMove(event, context);
42
+ }
43
+
44
+ if (onKeyboardMoveEnd && event.eventName.endsWith("onKeyboardMoveEnd")) {
45
+ onKeyboardMoveEnd(event, context);
46
+ }
47
+
48
+ if (
49
+ onKeyboardMoveInteractive &&
50
+ event.eventName.endsWith("onKeyboardMoveInteractive")
51
+ ) {
52
+ onKeyboardMoveInteractive(event, context);
53
+ }
54
+ },
55
+ [
56
+ "onKeyboardMoveStart",
57
+ "onKeyboardMove",
58
+ "onKeyboardMoveEnd",
59
+ "onKeyboardMoveInteractive",
60
+ ],
61
+ doDependenciesDiffer,
62
+ );
63
+ };
64
+
65
+ export const useFocusedInputLayoutHandler: FocusedInputLayoutHandlerHook<
66
+ EventContext,
67
+ EventWithName<FocusedInputLayoutChangedEvent>
68
+ > = (handlers, dependencies) => {
69
+ const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
70
+
71
+ return useEvent(
72
+ (event) => {
73
+ "worklet";
74
+ const { onFocusedInputLayoutChanged } = handlers;
75
+
76
+ if (
77
+ onFocusedInputLayoutChanged &&
78
+ event.eventName.endsWith("onFocusedInputLayoutChanged")
79
+ ) {
80
+ onFocusedInputLayoutChanged(event, context);
81
+ }
82
+ },
83
+ ["onFocusedInputLayoutChanged"],
84
+ doDependenciesDiffer,
85
+ );
86
+ };
87
+
88
+ export const useFocusedInputTextHandler: FocusedInputTextHandlerHook<
89
+ EventContext,
90
+ EventWithName<FocusedInputTextChangedEvent>
91
+ > = (handlers, dependencies) => {
92
+ const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
93
+
94
+ return useEvent(
95
+ (event) => {
96
+ "worklet";
97
+ const { onFocusedInputTextChanged } = handlers;
98
+
99
+ if (
100
+ onFocusedInputTextChanged &&
101
+ event.eventName.endsWith("onFocusedInputTextChanged")
102
+ ) {
103
+ onFocusedInputTextChanged(event, context);
104
+ }
105
+ },
106
+ ["onFocusedInputTextChanged"],
107
+ doDependenciesDiffer,
108
+ );
109
+ };
110
+
111
+ export const useFocusedInputSelectionHandler: FocusedInputSelectionHandlerHook<
112
+ EventContext,
113
+ EventWithName<FocusedInputSelectionChangedEvent>
114
+ > = (handlers, dependencies) => {
115
+ const { context, doDependenciesDiffer } = useHandler(handlers, dependencies);
116
+
117
+ return useEvent(
118
+ (event) => {
119
+ "worklet";
120
+ const { onFocusedInputSelectionChanged } = handlers;
121
+
122
+ if (
123
+ onFocusedInputSelectionChanged &&
124
+ event.eventName.endsWith("onFocusedInputSelectionChanged")
125
+ ) {
126
+ onFocusedInputSelectionChanged(event, context);
127
+ }
128
+ },
129
+ ["onFocusedInputSelectionChanged"],
130
+ doDependenciesDiffer,
131
+ );
132
+ };
@@ -0,0 +1,29 @@
1
+ import type {
2
+ EventWithName,
3
+ FocusedInputLayoutChangedEvent,
4
+ FocusedInputLayoutHandlerHook,
5
+ FocusedInputSelectionChangedEvent,
6
+ FocusedInputSelectionHandlerHook,
7
+ FocusedInputTextChangedEvent,
8
+ FocusedInputTextHandlerHook,
9
+ KeyboardHandlerHook,
10
+ NativeEvent,
11
+ } from "./types";
12
+
13
+ const NOOP = () => () => {};
14
+ export const useAnimatedKeyboardHandler: KeyboardHandlerHook<
15
+ Record<string, unknown>,
16
+ EventWithName<NativeEvent>
17
+ > = NOOP;
18
+ export const useFocusedInputLayoutHandler: FocusedInputLayoutHandlerHook<
19
+ Record<string, unknown>,
20
+ EventWithName<FocusedInputLayoutChangedEvent>
21
+ > = NOOP;
22
+ export const useFocusedInputTextHandler: FocusedInputTextHandlerHook<
23
+ Record<string, unknown>,
24
+ EventWithName<FocusedInputTextChangedEvent>
25
+ > = NOOP;
26
+ export const useFocusedInputSelectionHandler: FocusedInputSelectionHandlerHook<
27
+ Record<string, unknown>,
28
+ EventWithName<FocusedInputSelectionChangedEvent>
29
+ > = NOOP;
@@ -0,0 +1,70 @@
1
+ import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
2
+
3
+ import type { HostComponent } from "react-native";
4
+ import type { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";
5
+ import type {
6
+ DirectEventHandler,
7
+ Double,
8
+ Int32,
9
+ } from "react-native/Libraries/Types/CodegenTypes";
10
+
11
+ type KeyboardMoveEvent = Readonly<{
12
+ height: Double;
13
+ progress: Double;
14
+ duration: Int32;
15
+ target: Int32;
16
+ }>;
17
+
18
+ type FocusedInputLayoutChangedEvent = Readonly<{
19
+ target: Int32;
20
+ parentScrollViewTarget: Int32;
21
+ layout: {
22
+ x: Double;
23
+ y: Double;
24
+ width: Double;
25
+ height: Double;
26
+ absoluteX: Double;
27
+ absoluteY: Double;
28
+ };
29
+ }>;
30
+
31
+ type FocusedInputTextChangedEvent = Readonly<{
32
+ text: string;
33
+ }>;
34
+
35
+ type FocusedInputSelectionChangedEvent = Readonly<{
36
+ target: Int32;
37
+ selection: {
38
+ start: {
39
+ x: Double;
40
+ y: Double;
41
+ position: Int32;
42
+ };
43
+ end: {
44
+ x: Double;
45
+ y: Double;
46
+ position: Int32;
47
+ };
48
+ };
49
+ }>;
50
+
51
+ export interface NativeProps extends ViewProps {
52
+ // props
53
+ enabled?: boolean;
54
+ statusBarTranslucent?: boolean;
55
+ navigationBarTranslucent?: boolean;
56
+ // callbacks
57
+ /// keyboard
58
+ onKeyboardMoveStart?: DirectEventHandler<KeyboardMoveEvent>;
59
+ onKeyboardMove?: DirectEventHandler<KeyboardMoveEvent>;
60
+ onKeyboardMoveEnd?: DirectEventHandler<KeyboardMoveEvent>;
61
+ onKeyboardMoveInteractive?: DirectEventHandler<KeyboardMoveEvent>;
62
+ /// focused input
63
+ onFocusedInputLayoutChanged?: DirectEventHandler<FocusedInputLayoutChangedEvent>;
64
+ onFocusedInputTextChanged?: DirectEventHandler<FocusedInputTextChangedEvent>;
65
+ onFocusedInputSelectionChanged?: DirectEventHandler<FocusedInputSelectionChangedEvent>;
66
+ }
67
+
68
+ export default codegenNativeComponent<NativeProps>(
69
+ "RNKeyboardControllerView",
70
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,15 @@
1
+ import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
2
+
3
+ import type { HostComponent } from "react-native";
4
+ import type { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";
5
+ import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
6
+
7
+ export interface NativeProps extends ViewProps {
8
+ interpolator?: WithDefault<"linear" | "ios", "linear">;
9
+ showOnSwipeUp?: boolean;
10
+ enableSwipeToDismiss?: boolean;
11
+ }
12
+
13
+ export default codegenNativeComponent<NativeProps>("RNKeyboardGestureArea", {
14
+ excludedPlatforms: ["iOS"],
15
+ }) as HostComponent<NativeProps>;
@@ -0,0 +1,19 @@
1
+ import { TurboModuleRegistry } from "react-native";
2
+
3
+ import type { TurboModule } from "react-native";
4
+
5
+ export interface Spec extends TurboModule {
6
+ readonly getConstants: () => {};
7
+
8
+ // methods
9
+ setInputMode(mode: number): void;
10
+ setDefaultMode(): void;
11
+ dismiss(): void;
12
+ setFocusTo(direction: string): void;
13
+
14
+ // event emitter
15
+ addListener: (eventName: string) => void;
16
+ removeListeners: (count: number) => void;
17
+ }
18
+
19
+ export default TurboModuleRegistry.get<Spec>("KeyboardController");
@@ -0,0 +1,14 @@
1
+ import { TurboModuleRegistry } from "react-native";
2
+
3
+ import type { TurboModule } from "react-native";
4
+
5
+ export interface Spec extends TurboModule {
6
+ readonly getConstants: () => {};
7
+
8
+ setHidden(hidden: boolean): void;
9
+ setColor(color: number, animated: boolean): void;
10
+ setTranslucent(translucent: boolean): void;
11
+ setStyle(style: string): void;
12
+ }
13
+
14
+ export default TurboModuleRegistry.get<Spec>("StatusBarManagerCompat");
package/src/types.ts ADDED
@@ -0,0 +1,211 @@
1
+ import type {
2
+ EmitterSubscription,
3
+ NativeSyntheticEvent,
4
+ ViewProps,
5
+ } from "react-native";
6
+
7
+ // DirectEventHandler events declaration
8
+ export type NativeEvent = {
9
+ progress: number;
10
+ height: number;
11
+ duration: number;
12
+ target: number;
13
+ };
14
+ export type FocusedInputLayoutChangedEvent = {
15
+ target: number;
16
+ parentScrollViewTarget: number;
17
+ layout: {
18
+ x: number;
19
+ y: number;
20
+ width: number;
21
+ height: number;
22
+ absoluteX: number;
23
+ absoluteY: number;
24
+ };
25
+ };
26
+ export type FocusedInputTextChangedEvent = {
27
+ text: string;
28
+ };
29
+ export type FocusedInputSelectionChangedEvent = {
30
+ target: number;
31
+ selection: {
32
+ start: {
33
+ x: number;
34
+ y: number;
35
+ position: number;
36
+ };
37
+ end: {
38
+ x: number;
39
+ y: number;
40
+ position: number;
41
+ };
42
+ };
43
+ };
44
+ export type EventWithName<T> = {
45
+ eventName: string;
46
+ } & T;
47
+
48
+ // native View/Module declarations
49
+ export type KeyboardControllerProps = {
50
+ // callback props
51
+ onKeyboardMoveStart?: (
52
+ e: NativeSyntheticEvent<EventWithName<NativeEvent>>,
53
+ ) => void;
54
+ onKeyboardMove?: (
55
+ e: NativeSyntheticEvent<EventWithName<NativeEvent>>,
56
+ ) => void;
57
+ onKeyboardMoveEnd?: (
58
+ e: NativeSyntheticEvent<EventWithName<NativeEvent>>,
59
+ ) => void;
60
+ onKeyboardMoveInteractive?: (
61
+ e: NativeSyntheticEvent<EventWithName<NativeEvent>>,
62
+ ) => void;
63
+ onFocusedInputLayoutChanged?: (
64
+ e: NativeSyntheticEvent<EventWithName<FocusedInputLayoutChangedEvent>>,
65
+ ) => void;
66
+ onFocusedInputTextChanged?: (
67
+ e: NativeSyntheticEvent<EventWithName<FocusedInputTextChangedEvent>>,
68
+ ) => void;
69
+ onFocusedInputSelectionChanged?: (
70
+ e: NativeSyntheticEvent<EventWithName<FocusedInputSelectionChangedEvent>>,
71
+ ) => void;
72
+ // fake props used to activate reanimated bindings
73
+ onKeyboardMoveReanimated?: (
74
+ e: NativeSyntheticEvent<EventWithName<NativeEvent>>,
75
+ ) => void;
76
+ onFocusedInputLayoutChangedReanimated?: (
77
+ e: NativeSyntheticEvent<EventWithName<FocusedInputLayoutChangedEvent>>,
78
+ ) => void;
79
+ onFocusedInputTextChangedReanimated?: (
80
+ e: NativeSyntheticEvent<EventWithName<FocusedInputTextChangedEvent>>,
81
+ ) => void;
82
+ onFocusedInputSelectionChangedReanimated?: (
83
+ e: NativeSyntheticEvent<EventWithName<FocusedInputSelectionChangedEvent>>,
84
+ ) => void;
85
+ // props
86
+ statusBarTranslucent?: boolean;
87
+ navigationBarTranslucent?: boolean;
88
+ enabled?: boolean;
89
+ } & ViewProps;
90
+
91
+ export type KeyboardGestureAreaProps = {
92
+ interpolator: "ios" | "linear";
93
+ /**
94
+ * Whether to allow to show a keyboard from dismissed state by swipe up.
95
+ * Default to `false`.
96
+ */
97
+ showOnSwipeUp?: boolean;
98
+ /**
99
+ * Whether to allow to control a keyboard by gestures. The strategy how
100
+ * it should be controlled is determined by `interpolator` property.
101
+ * Defaults to `true`.
102
+ */
103
+ enableSwipeToDismiss?: boolean;
104
+ } & ViewProps;
105
+
106
+ export type Direction = "next" | "prev" | "current";
107
+ export type KeyboardControllerModule = {
108
+ // android only
109
+ setDefaultMode: () => void;
110
+ setInputMode: (mode: number) => void;
111
+ // all platforms
112
+ dismiss: () => void;
113
+ setFocusTo: (direction: Direction) => void;
114
+ // native event module stuff
115
+ addListener: (eventName: string) => void;
116
+ removeListeners: (count: number) => void;
117
+ };
118
+
119
+ // Event module declarations
120
+ export type KeyboardControllerEvents =
121
+ | "keyboardWillShow"
122
+ | "keyboardDidShow"
123
+ | "keyboardWillHide"
124
+ | "keyboardDidHide";
125
+ export type KeyboardEventData = {
126
+ height: number;
127
+ duration: number;
128
+ timestamp: number;
129
+ target: number;
130
+ };
131
+ export type KeyboardEventsModule = {
132
+ addListener: (
133
+ name: KeyboardControllerEvents,
134
+ cb: (e: KeyboardEventData) => void,
135
+ ) => EmitterSubscription;
136
+ };
137
+ export type FocusedInputAvailableEvents = "focusDidSet";
138
+ export type FocusedInputEventData = {
139
+ current: number;
140
+ count: number;
141
+ };
142
+ export type FocusedInputEventsModule = {
143
+ addListener: (
144
+ name: FocusedInputAvailableEvents,
145
+ cb: (e: FocusedInputEventData) => void,
146
+ ) => EmitterSubscription;
147
+ };
148
+ export type WindowDimensionsAvailableEvents = "windowDidResize";
149
+ export type WindowDimensionsEventData = {
150
+ width: number;
151
+ height: number;
152
+ };
153
+ export type WindowDimensionsEventsModule = {
154
+ addListener: (
155
+ name: WindowDimensionsAvailableEvents,
156
+ cb: (e: WindowDimensionsEventData) => void,
157
+ ) => EmitterSubscription;
158
+ };
159
+
160
+ // reanimated hook declaration
161
+ export type KeyboardHandlerHook<TContext, Event> = (
162
+ handlers: {
163
+ onKeyboardMoveStart?: (e: NativeEvent, context: TContext) => void;
164
+ onKeyboardMove?: (e: NativeEvent, context: TContext) => void;
165
+ onKeyboardMoveEnd?: (e: NativeEvent, context: TContext) => void;
166
+ onKeyboardMoveInteractive?: (e: NativeEvent, context: TContext) => void;
167
+ },
168
+ dependencies?: unknown[],
169
+ ) => (e: NativeSyntheticEvent<Event>) => void;
170
+ export type FocusedInputLayoutHandlerHook<TContext, Event> = (
171
+ handlers: {
172
+ onFocusedInputLayoutChanged?: (
173
+ e: FocusedInputLayoutChangedEvent,
174
+ context: TContext,
175
+ ) => void;
176
+ },
177
+ dependencies?: unknown[],
178
+ ) => (e: NativeSyntheticEvent<Event>) => void;
179
+ export type FocusedInputTextHandlerHook<TContext, Event> = (
180
+ handlers: {
181
+ onFocusedInputTextChanged?: (
182
+ e: FocusedInputTextChangedEvent,
183
+ context: TContext,
184
+ ) => void;
185
+ },
186
+ dependencies?: unknown[],
187
+ ) => (e: NativeSyntheticEvent<Event>) => void;
188
+ export type FocusedInputSelectionHandlerHook<TContext, Event> = (
189
+ handlers: {
190
+ onFocusedInputSelectionChanged?: (
191
+ e: FocusedInputSelectionChangedEvent,
192
+ context: TContext,
193
+ ) => void;
194
+ },
195
+ dependencies?: unknown[],
196
+ ) => (e: NativeSyntheticEvent<Event>) => void;
197
+
198
+ // package types
199
+ export type Handlers<T> = Record<string, T | undefined>;
200
+ export type KeyboardHandler = Partial<{
201
+ onStart: (e: NativeEvent) => void;
202
+ onMove: (e: NativeEvent) => void;
203
+ onEnd: (e: NativeEvent) => void;
204
+ onInteractive: (e: NativeEvent) => void;
205
+ }>;
206
+ export type KeyboardHandlers = Handlers<KeyboardHandler>;
207
+ export type FocusedInputHandler = Partial<{
208
+ onChangeText: (e: FocusedInputTextChangedEvent) => void;
209
+ onSelectionChange: (e: FocusedInputSelectionChangedEvent) => void;
210
+ }>;
211
+ export type FocusedInputHandlers = Handlers<FocusedInputHandler>;
package/src/utils.ts ADDED
@@ -0,0 +1 @@
1
+ export const uuid = () => Math.random().toString(36).slice(-6);