@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,253 @@
1
+ import React, { useEffect, useMemo, useState } from "react";
2
+ import { Animated, Platform, StyleSheet } from "react-native";
3
+ import Reanimated, { useSharedValue, Easing, withTiming } from "react-native-reanimated";
4
+
5
+ import { KeyboardControllerView } from "./bindings";
6
+ import { KeyboardContext } from "./context";
7
+ import { useAnimatedValue, useSharedHandlers } from "./internal";
8
+ import { applyMonkeyPatch, revertMonkeyPatch } from "./monkey-patch";
9
+ import {
10
+ useAnimatedKeyboardHandler,
11
+ useFocusedInputLayoutHandler,
12
+ useFocusedInputSelectionHandler,
13
+ useFocusedInputTextHandler,
14
+ } from "./reanimated";
15
+
16
+ import type { KeyboardAnimationContext } from "./context";
17
+ import type {
18
+ FocusedInputHandler,
19
+ FocusedInputLayoutChangedEvent,
20
+ KeyboardControllerProps,
21
+ KeyboardHandler,
22
+ NativeEvent,
23
+ } from "./types";
24
+ import type { ViewStyle } from "react-native";
25
+
26
+ const KeyboardControllerViewAnimated = Reanimated.createAnimatedComponent(
27
+ Animated.createAnimatedComponent(
28
+ KeyboardControllerView,
29
+ ) as React.FC<KeyboardControllerProps>,
30
+ );
31
+
32
+ type Styles = {
33
+ container: ViewStyle;
34
+ hidden: ViewStyle;
35
+ };
36
+
37
+ const styles = StyleSheet.create<Styles>({
38
+ container: {
39
+ flex: 1,
40
+ },
41
+ hidden: {
42
+ display: "none",
43
+ position: "absolute",
44
+ },
45
+ });
46
+
47
+ type KeyboardProviderProps = {
48
+ children: React.ReactNode;
49
+ /**
50
+ * Set the value to `true`, if you use translucent status bar on Android.
51
+ * If you already control status bar translucency via `react-native-screens`
52
+ * or `StatusBar` component from `react-native`, you can ignore it.
53
+ * Defaults to `false`.
54
+ *
55
+ * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/14
56
+ * @platform android
57
+ */
58
+ statusBarTranslucent?: boolean;
59
+ /**
60
+ * Set the value to `true`, if you use translucent navigation bar on Android.
61
+ * Defaults to `false`.
62
+ *
63
+ * @see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/119
64
+ * @platform android
65
+ */
66
+ navigationBarTranslucent?: boolean;
67
+ /**
68
+ * A boolean prop indicating whether the module is enabled. It indicate only initial state,
69
+ * i. e. if you try to change this prop after component mount it will not have any effect.
70
+ * To change the property in runtime use `useKeyboardController` hook and `setEnabled` method.
71
+ * Defaults to `true`.
72
+ */
73
+ enabled?: boolean;
74
+ };
75
+
76
+ // capture `Platform.OS` in separate variable to avoid deep workletization of entire RN package
77
+ // 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
78
+ const OS = Platform.OS;
79
+
80
+ export const KeyboardProvider = ({
81
+ children,
82
+ statusBarTranslucent,
83
+ navigationBarTranslucent,
84
+ enabled: initiallyEnabled = true,
85
+ }: KeyboardProviderProps) => {
86
+ // state
87
+ const [enabled, setEnabled] = useState(initiallyEnabled);
88
+ // animated values
89
+ const progress = useAnimatedValue(0);
90
+ const height = useAnimatedValue(0);
91
+ // shared values
92
+ const progressSV = useSharedValue(0);
93
+ const heightSV = useSharedValue(0);
94
+ const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
95
+ const [setKeyboardHandlers, broadcastKeyboardEvents] =
96
+ useSharedHandlers<KeyboardHandler>();
97
+ const [setInputHandlers, broadcastInputEvents] =
98
+ useSharedHandlers<FocusedInputHandler>();
99
+ // memo
100
+ const context = useMemo<KeyboardAnimationContext>(
101
+ () => ({
102
+ enabled,
103
+ animated: { progress: progress, height: Animated.multiply(height, -1) },
104
+ reanimated: { progress: progressSV, height: heightSV },
105
+ layout,
106
+ setKeyboardHandlers,
107
+ setInputHandlers,
108
+ setEnabled,
109
+ }),
110
+ [enabled],
111
+ );
112
+ const style = useMemo(
113
+ () => [
114
+ styles.hidden,
115
+ { transform: [{ translateX: height }, { translateY: progress }] },
116
+ ],
117
+ [],
118
+ );
119
+ const onKeyboardMove = useMemo(
120
+ () =>
121
+ Animated.event(
122
+ [
123
+ {
124
+ nativeEvent: {
125
+ progress,
126
+ height,
127
+ },
128
+ },
129
+ ],
130
+ { useNativeDriver: Platform.OS as string == 'harmony' ? false : true },
131
+ ),
132
+ [],
133
+ );
134
+ // handlers
135
+ const updateSharedValues = (event: NativeEvent, platforms: string[]) => {
136
+ "worklet";
137
+
138
+ if (platforms.includes(OS)) {
139
+ // eslint-disable-next-line react-compiler/react-compiler
140
+ if (Platform.OS as string == 'harmony') {
141
+ const dur = 460
142
+ progressSV.value = withTiming(event.progress, { duration: dur, easing: Easing.out(Easing.exp) });
143
+ heightSV.value = withTiming(-event.height, { duration: dur, easing: Easing.out(Easing.exp) });
144
+ } else {
145
+ progressSV.value = event.progress;
146
+ heightSV.value = -event.height;
147
+
148
+ }
149
+ }
150
+ };
151
+ const keyboardHandler = useAnimatedKeyboardHandler(
152
+ {
153
+ onKeyboardMoveStart: (event: NativeEvent) => {
154
+ "worklet";
155
+
156
+ broadcastKeyboardEvents("onStart", event);
157
+ updateSharedValues(event, ["ios"]);
158
+ },
159
+ onKeyboardMove: (event: NativeEvent) => {
160
+ "worklet";
161
+
162
+ broadcastKeyboardEvents("onMove", event);
163
+ updateSharedValues(event, ["android"]);
164
+ },
165
+ onKeyboardMoveEnd: (event: NativeEvent) => {
166
+ "worklet";
167
+ broadcastKeyboardEvents("onEnd", event);
168
+ updateSharedValues(event, ['harmony']);
169
+ },
170
+ onKeyboardMoveInteractive: (event: NativeEvent) => {
171
+ "worklet";
172
+
173
+ updateSharedValues(event, ["android", "ios"]);
174
+ broadcastKeyboardEvents("onInteractive", event);
175
+ },
176
+ },
177
+ [],
178
+ );
179
+ const inputLayoutHandler = useFocusedInputLayoutHandler(
180
+ {
181
+ onFocusedInputLayoutChanged: (e) => {
182
+ "worklet";
183
+
184
+ if (e.target !== -1) {
185
+ layout.value = e;
186
+ } else {
187
+ layout.value = null;
188
+ }
189
+ },
190
+ },
191
+ [],
192
+ );
193
+ const inputTextHandler = useFocusedInputTextHandler(
194
+ {
195
+ onFocusedInputTextChanged: (e) => {
196
+ "worklet";
197
+
198
+ broadcastInputEvents("onChangeText", e);
199
+ },
200
+ },
201
+ [],
202
+ );
203
+ const inputSelectionHandler = useFocusedInputSelectionHandler(
204
+ {
205
+ onFocusedInputSelectionChanged: (e) => {
206
+ "worklet";
207
+ broadcastInputEvents("onSelectionChange", e);
208
+ },
209
+ },
210
+ [],
211
+ );
212
+ // effects
213
+ useEffect(() => {
214
+ if (enabled) {
215
+ applyMonkeyPatch();
216
+ } else {
217
+ revertMonkeyPatch();
218
+ }
219
+ }, [enabled]);
220
+
221
+ return (
222
+ <KeyboardContext.Provider value={context}>
223
+ <KeyboardControllerViewAnimated
224
+ enabled={enabled}
225
+ onKeyboardMoveReanimated={keyboardHandler}
226
+ onKeyboardMoveStart={OS === "ios" ? onKeyboardMove : undefined}
227
+ onKeyboardMove={OS === "android" ? onKeyboardMove : undefined}
228
+ onKeyboardMoveInteractive={onKeyboardMove}
229
+ onKeyboardMoveEnd={OS as string === "harmony" ? onKeyboardMove : undefined}
230
+ onFocusedInputLayoutChangedReanimated={inputLayoutHandler}
231
+ onFocusedInputTextChangedReanimated={inputTextHandler}
232
+ onFocusedInputSelectionChangedReanimated={inputSelectionHandler}
233
+ navigationBarTranslucent={navigationBarTranslucent}
234
+ statusBarTranslucent={statusBarTranslucent}
235
+ style={styles.container}
236
+ >
237
+ <Reanimated.View style={styles.container}>{children}</Reanimated.View>
238
+ {/* {children} */}
239
+ </KeyboardControllerViewAnimated>
240
+ <Animated.View
241
+ // we are using this small hack, because if the component (where
242
+ // animated value has been used) is unmounted, then animation will
243
+ // stop receiving events (seems like it's react-native optimization).
244
+ // So we need to keep a reference to the animated value, to keep it's
245
+ // always mounted (keep a reference to an animated value).
246
+ //
247
+ // To test why it's needed, try to open screen which consumes Animated.Value
248
+ // then close it and open it again (for example 'Animated transition').
249
+ style={style}
250
+ />
251
+ </KeyboardContext.Provider>
252
+ );
253
+ };
@@ -0,0 +1,57 @@
1
+ import { NativeEventEmitter, Platform } from "react-native";
2
+
3
+ import type {
4
+ FocusedInputEventsModule,
5
+ KeyboardControllerModule,
6
+ KeyboardControllerProps,
7
+ KeyboardEventsModule,
8
+ KeyboardGestureAreaProps,
9
+ WindowDimensionsEventsModule,
10
+ } from "./types";
11
+
12
+ const LINKING_ERROR =
13
+ `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` +
14
+ Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
15
+ "- You rebuilt the app after installing the package\n" +
16
+ "- You are not using Expo Go\n";
17
+
18
+ const RCTKeyboardController =
19
+ require("./specs/NativeKeyboardController").default;
20
+ export const KeyboardController = (
21
+ RCTKeyboardController
22
+ ? RCTKeyboardController
23
+ : new Proxy(
24
+ {},
25
+ {
26
+ get() {
27
+ throw new Error(LINKING_ERROR);
28
+ },
29
+ },
30
+ )
31
+ ) as KeyboardControllerModule;
32
+
33
+ const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
34
+ const eventEmitter = new NativeEventEmitter(KeyboardController);
35
+
36
+ export const KeyboardEvents: KeyboardEventsModule = {
37
+ addListener: (name, cb) =>
38
+ eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
39
+ };
40
+ /**
41
+ * This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
42
+ * Use it with cautious.
43
+ */
44
+ export const FocusedInputEvents: FocusedInputEventsModule = {
45
+ addListener: (name, cb) =>
46
+ eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
47
+ };
48
+ export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
49
+ addListener: (name, cb) =>
50
+ eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),
51
+ };
52
+ export const KeyboardControllerView: React.FC<KeyboardControllerProps> =
53
+ require("./specs/KeyboardControllerViewNativeComponent").default;
54
+ export const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =
55
+ Platform.OS === "android" && Platform.Version >= 30
56
+ ? require("./specs/KeyboardGestureAreaNativeComponent").default
57
+ : ({ children }: KeyboardGestureAreaProps) => children;
@@ -0,0 +1,38 @@
1
+ import { View } from "react-native";
2
+
3
+ import type {
4
+ FocusedInputEventsModule,
5
+ KeyboardControllerModule,
6
+ KeyboardControllerProps,
7
+ KeyboardEventsModule,
8
+ KeyboardGestureAreaProps,
9
+ WindowDimensionsEventsModule,
10
+ } from "./types";
11
+ import type { EmitterSubscription } from "react-native";
12
+
13
+ const NOOP = () => {};
14
+ export const KeyboardController: KeyboardControllerModule = {
15
+ setDefaultMode: NOOP,
16
+ setInputMode: NOOP,
17
+ dismiss: NOOP,
18
+ setFocusTo: NOOP,
19
+ addListener: NOOP,
20
+ removeListeners: NOOP,
21
+ };
22
+ export const KeyboardEvents: KeyboardEventsModule = {
23
+ addListener: () => ({ remove: NOOP } as EmitterSubscription),
24
+ };
25
+ /**
26
+ * This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
27
+ * Use it with cautious.
28
+ */
29
+ export const FocusedInputEvents: FocusedInputEventsModule = {
30
+ addListener: () => ({ remove: NOOP } as EmitterSubscription),
31
+ };
32
+ export const WindowDimensionsEvents: WindowDimensionsEventsModule = {
33
+ addListener: () => ({ remove: NOOP } as EmitterSubscription),
34
+ };
35
+ export const KeyboardControllerView =
36
+ View as unknown as React.FC<KeyboardControllerProps>;
37
+ export const KeyboardGestureArea =
38
+ View as unknown as React.FC<KeyboardGestureAreaProps>;
@@ -0,0 +1,58 @@
1
+ import { useSharedValue } from "react-native-reanimated";
2
+
3
+ import {useKeyboardHandler} from "../../hooks";
4
+ import {useKeyboardContext} from "../../context";
5
+ import { Platform } from "react-native";
6
+
7
+ export const useKeyboardAnimation = () => {
8
+ const { reanimated } = useKeyboardContext();
9
+ const heightWhenOpened = useSharedValue(-reanimated.height.value);
10
+ const height = useSharedValue(-reanimated.height.value);
11
+ const progress = useSharedValue(reanimated.progress.value);
12
+ const isClosed = useSharedValue(reanimated.progress.value === 0);
13
+
14
+ useKeyboardHandler(
15
+ {
16
+ onStart: (e) => {
17
+ "worklet";
18
+
19
+ if (e.height > 0) {
20
+ // eslint-disable-next-line react-compiler/react-compiler
21
+ isClosed.value = false;
22
+ heightWhenOpened.value = e.height;
23
+ }
24
+ },
25
+ onMove: (e) => {
26
+ "worklet";
27
+
28
+ progress.value = e.progress;
29
+ height.value = e.height;
30
+ },
31
+ onEnd: (e) => {
32
+ "worklet";
33
+ if(Platform.OS as string === 'harmony'){
34
+ heightWhenOpened.value = e.height;
35
+ }
36
+
37
+ isClosed.value = e.height === 0;
38
+
39
+ // `height` update happens in `onMove` handler
40
+ // in `onEnd` we need to update only if `onMove`
41
+ // wasn't called (i. e. duration === 0)
42
+ //
43
+ // we can not call this code without condition below
44
+ // because in some corner cases (iOS with `secureTextEntry`)
45
+ // `onEnd` can be emitted before `onMove` and in this case
46
+ // it may lead to choppy/glitchy/jumpy UI
47
+ // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327
48
+ if (e.duration === 0) {
49
+ progress.value = e.progress;
50
+ height.value = e.height;
51
+ }
52
+ },
53
+ },
54
+ [],
55
+ );
56
+
57
+ return { height, progress, heightWhenOpened, isClosed };
58
+ };
@@ -0,0 +1,156 @@
1
+ import React, { forwardRef, useCallback, useMemo } from "react";
2
+ import { View } from "react-native";
3
+ import Reanimated, {
4
+ interpolate,
5
+ runOnUI,
6
+ useAnimatedStyle,
7
+ useDerivedValue,
8
+ useSharedValue,
9
+ } from "react-native-reanimated";
10
+
11
+ import { useWindowDimensions } from "../../hooks";
12
+
13
+ import { useKeyboardAnimation } from "./hooks";
14
+
15
+ import type { LayoutRectangle, ViewProps } from "react-native";
16
+
17
+ export type KeyboardAvoidingViewProps = {
18
+ /**
19
+ * Specify how to react to the presence of the keyboard.
20
+ */
21
+ behavior?: "height" | "position" | "padding";
22
+
23
+ /**
24
+ * Style of the content container when `behavior` is 'position'.
25
+ */
26
+ contentContainerStyle?: ViewProps["style"];
27
+
28
+ /**
29
+ * Controls whether this `KeyboardAvoidingView` instance should take effect.
30
+ * This is useful when more than one is on the screen. Defaults to true.
31
+ */
32
+ enabled?: boolean;
33
+
34
+ /**
35
+ * Distance between the top of the user screen and the React Native view. This
36
+ * may be non-zero in some cases. Defaults to 0.
37
+ */
38
+ keyboardVerticalOffset?: number;
39
+ } & ViewProps;
40
+
41
+ const defaultLayout: LayoutRectangle = {
42
+ x: 0,
43
+ y: 0,
44
+ width: 0,
45
+ height: 0,
46
+ };
47
+
48
+ /**
49
+ * View that moves out of the way when the keyboard appears by automatically
50
+ * adjusting its height, position, or bottom padding.
51
+ */
52
+ const KeyboardAvoidingView = forwardRef<
53
+ View,
54
+ React.PropsWithChildren<KeyboardAvoidingViewProps>
55
+ >(
56
+ (
57
+ {
58
+ behavior,
59
+ children,
60
+ contentContainerStyle,
61
+ enabled = true,
62
+ keyboardVerticalOffset = 0,
63
+ style,
64
+ onLayout: onLayoutProps,
65
+ ...props
66
+ },
67
+ ref,
68
+ ) => {
69
+ const initialFrame = useSharedValue<LayoutRectangle | null>(null);
70
+ const frame = useDerivedValue(() => initialFrame.value || defaultLayout);
71
+
72
+ const keyboard = useKeyboardAnimation();
73
+ const { height: screenHeight } = useWindowDimensions();
74
+
75
+ const relativeKeyboardHeight = useCallback(() => {
76
+ "worklet";
77
+
78
+ const keyboardY =
79
+ screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
80
+
81
+ return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
82
+ }, [screenHeight, keyboardVerticalOffset]);
83
+
84
+ const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {
85
+ "worklet";
86
+
87
+ if (keyboard.isClosed.value || initialFrame.value === null) {
88
+ // eslint-disable-next-line react-compiler/react-compiler
89
+ initialFrame.value = layout;
90
+ }
91
+ }, []);
92
+ const onLayout = useCallback<NonNullable<ViewProps["onLayout"]>>(
93
+ (e) => {
94
+ runOnUI(onLayoutWorklet)(e.nativeEvent.layout);
95
+ onLayoutProps?.(e);
96
+ },
97
+ [onLayoutProps],
98
+ );
99
+
100
+ const animatedStyle = useAnimatedStyle(() => {
101
+ const bottom = interpolate(
102
+ keyboard.progress.value,
103
+ [0, 1],
104
+ [0, relativeKeyboardHeight()],
105
+ );
106
+ const bottomHeight = enabled ? bottom : 0;
107
+
108
+ switch (behavior) {
109
+ case "height":
110
+ if (!keyboard.isClosed.value) {
111
+ return {
112
+ height: frame.value.height - bottomHeight,
113
+ flex: 0,
114
+ };
115
+ }
116
+
117
+ return {};
118
+
119
+ case "position":
120
+ return { bottom: bottomHeight };
121
+
122
+ case "padding":
123
+ return { paddingBottom: bottomHeight };
124
+ default:
125
+ return {};
126
+ }
127
+ }, [behavior, enabled, relativeKeyboardHeight]);
128
+ const isPositionBehavior = behavior === "position";
129
+ const containerStyle = isPositionBehavior ? contentContainerStyle : style;
130
+ const combinedStyles = useMemo(
131
+ () => [containerStyle, animatedStyle],
132
+ [containerStyle, animatedStyle],
133
+ );
134
+
135
+ if (isPositionBehavior) {
136
+ return (
137
+ <View ref={ref} style={style} onLayout={onLayout} {...props}>
138
+ <Reanimated.View style={combinedStyles}>{children}</Reanimated.View>
139
+ </View>
140
+ );
141
+ }
142
+
143
+ return (
144
+ <Reanimated.View
145
+ ref={ref}
146
+ onLayout={onLayout}
147
+ style={combinedStyles}
148
+ {...props}
149
+ >
150
+ {children}
151
+ </Reanimated.View>
152
+ );
153
+ },
154
+ );
155
+
156
+ export default KeyboardAvoidingView;