@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,90 @@
1
+ import { useEffect } from "react";
2
+
3
+ import { KeyboardController } from "../bindings";
4
+ import { AndroidSoftInputModes } from "../constants";
5
+ import { useKeyboardContext } from "../context";
6
+ import { uuid } from "../utils";
7
+
8
+ import type { AnimatedContext, ReanimatedContext } from "../context";
9
+ import type { FocusedInputHandler, KeyboardHandler } from "../types";
10
+ import type { DependencyList } from "react";
11
+
12
+ export const useResizeMode = () => {
13
+ useEffect(() => {
14
+ KeyboardController.setInputMode(
15
+ AndroidSoftInputModes.SOFT_INPUT_ADJUST_RESIZE,
16
+ );
17
+
18
+ return () => KeyboardController.setDefaultMode();
19
+ }, []);
20
+ };
21
+
22
+ export const useKeyboardAnimation = (): AnimatedContext => {
23
+ useResizeMode();
24
+ const context = useKeyboardContext();
25
+
26
+ return context.animated;
27
+ };
28
+
29
+ export const useReanimatedKeyboardAnimation = (): ReanimatedContext => {
30
+ useResizeMode();
31
+ const context = useKeyboardContext();
32
+
33
+ return context.reanimated;
34
+ };
35
+
36
+ export function useGenericKeyboardHandler(
37
+ handler: KeyboardHandler,
38
+ deps?: DependencyList,
39
+ ) {
40
+ const context = useKeyboardContext();
41
+
42
+ useEffect(() => {
43
+ const key = uuid();
44
+
45
+ context.setKeyboardHandlers({ [key]: handler });
46
+
47
+ return () => {
48
+ context.setKeyboardHandlers({ [key]: undefined });
49
+ };
50
+ }, deps);
51
+ }
52
+
53
+ export function useKeyboardHandler(
54
+ handler: KeyboardHandler,
55
+ deps?: DependencyList,
56
+ ) {
57
+ useResizeMode();
58
+ useGenericKeyboardHandler(handler, deps);
59
+ }
60
+
61
+ export function useKeyboardController() {
62
+ const context = useKeyboardContext();
63
+
64
+ return { setEnabled: context.setEnabled, enabled: context.enabled };
65
+ }
66
+
67
+ export function useReanimatedFocusedInput() {
68
+ const context = useKeyboardContext();
69
+
70
+ return { input: context.layout };
71
+ }
72
+
73
+ export function useFocusedInputHandler(
74
+ handler?: FocusedInputHandler,
75
+ deps?: DependencyList,
76
+ ) {
77
+ const context = useKeyboardContext();
78
+
79
+ useEffect(() => {
80
+ const key = uuid();
81
+
82
+ context.setInputHandlers({ [key]: handler });
83
+
84
+ return () => {
85
+ context.setInputHandlers({ [key]: undefined });
86
+ };
87
+ }, deps);
88
+ }
89
+
90
+ export * from "./useWindowDimensions";
@@ -0,0 +1,33 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import { WindowDimensionsEvents } from "../../bindings";
4
+
5
+ import type { WindowDimensionsEventData } from "../../types";
6
+
7
+ let initialDimensions: WindowDimensionsEventData = {
8
+ width: 0,
9
+ height: 0,
10
+ };
11
+
12
+ WindowDimensionsEvents.addListener("windowDidResize", (e) => {
13
+ initialDimensions = e;
14
+ });
15
+
16
+ export const useWindowDimensions = () => {
17
+ const [dimensions, setDimensions] = useState(initialDimensions);
18
+
19
+ useEffect(() => {
20
+ const subscription = WindowDimensionsEvents.addListener(
21
+ "windowDidResize",
22
+ (e) => {
23
+ setDimensions(e);
24
+ },
25
+ );
26
+
27
+ return () => {
28
+ subscription.remove();
29
+ };
30
+ }, []);
31
+
32
+ return dimensions;
33
+ };
@@ -0,0 +1 @@
1
+ export { useWindowDimensions } from "react-native";
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ export * from "./bindings";
2
+ export * from "./animated";
3
+ export * from "./context";
4
+ export * from "./hooks";
5
+ export * from "./constants";
6
+ export * from "./types";
7
+
8
+ export {
9
+ KeyboardAvoidingView,
10
+ KeyboardStickyView,
11
+ KeyboardAwareScrollView,
12
+ // keyboard toolbar
13
+ KeyboardToolbar,
14
+ DefaultKeyboardToolbarTheme,
15
+ } from "./components";
16
+ export type {
17
+ KeyboardAvoidingViewProps,
18
+ KeyboardStickyViewProps,
19
+ KeyboardAwareScrollViewProps,
20
+ KeyboardToolbarProps,
21
+ } from "./components";
@@ -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");