@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,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useKeyboardAnimation = void 0;
7
+ var _reactNativeReanimated = require("react-native-reanimated");
8
+ var _hooks = require("../../hooks");
9
+ var _context = require("../../context");
10
+ var _reactNative = require("react-native");
11
+ const useKeyboardAnimation = () => {
12
+ const {
13
+ reanimated
14
+ } = (0, _context.useKeyboardContext)();
15
+ const heightWhenOpened = (0, _reactNativeReanimated.useSharedValue)(-reanimated.height.value);
16
+ const height = (0, _reactNativeReanimated.useSharedValue)(-reanimated.height.value);
17
+ const progress = (0, _reactNativeReanimated.useSharedValue)(reanimated.progress.value);
18
+ const isClosed = (0, _reactNativeReanimated.useSharedValue)(reanimated.progress.value === 0);
19
+ (0, _hooks.useKeyboardHandler)({
20
+ onStart: e => {
21
+ "worklet";
22
+
23
+ if (e.height > 0) {
24
+ // eslint-disable-next-line react-compiler/react-compiler
25
+ isClosed.value = false;
26
+ heightWhenOpened.value = e.height;
27
+ }
28
+ },
29
+ onMove: e => {
30
+ "worklet";
31
+
32
+ progress.value = e.progress;
33
+ height.value = e.height;
34
+ },
35
+ onEnd: e => {
36
+ "worklet";
37
+
38
+ if (_reactNative.Platform.OS === 'harmony') {
39
+ heightWhenOpened.value = e.height;
40
+ }
41
+ isClosed.value = e.height === 0;
42
+
43
+ // `height` update happens in `onMove` handler
44
+ // in `onEnd` we need to update only if `onMove`
45
+ // wasn't called (i. e. duration === 0)
46
+ //
47
+ // we can not call this code without condition below
48
+ // because in some corner cases (iOS with `secureTextEntry`)
49
+ // `onEnd` can be emitted before `onMove` and in this case
50
+ // it may lead to choppy/glitchy/jumpy UI
51
+ // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327
52
+ if (e.duration === 0) {
53
+ progress.value = e.progress;
54
+ height.value = e.height;
55
+ }
56
+ }
57
+ }, []);
58
+ return {
59
+ height,
60
+ progress,
61
+ heightWhenOpened,
62
+ isClosed
63
+ };
64
+ };
65
+ exports.useKeyboardAnimation = useKeyboardAnimation;
66
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNativeReanimated","require","_hooks","_context","_reactNative","useKeyboardAnimation","reanimated","useKeyboardContext","heightWhenOpened","useSharedValue","height","value","progress","isClosed","useKeyboardHandler","onStart","e","onMove","onEnd","Platform","OS","duration","exports"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\r\n\r\nimport {useKeyboardHandler} from \"../../hooks\";\r\nimport {useKeyboardContext} from \"../../context\";\r\nimport { Platform } from \"react-native\";\r\n\r\nexport const useKeyboardAnimation = () => {\r\n const { reanimated } = useKeyboardContext();\r\n const heightWhenOpened = useSharedValue(-reanimated.height.value);\r\n const height = useSharedValue(-reanimated.height.value);\r\n const progress = useSharedValue(reanimated.progress.value);\r\n const isClosed = useSharedValue(reanimated.progress.value === 0);\r\n\r\n useKeyboardHandler(\r\n {\r\n onStart: (e) => {\r\n \"worklet\";\r\n\r\n if (e.height > 0) {\r\n // eslint-disable-next-line react-compiler/react-compiler\r\n isClosed.value = false;\r\n heightWhenOpened.value = e.height;\r\n }\r\n },\r\n onMove: (e) => {\r\n \"worklet\";\r\n \r\n progress.value = e.progress;\r\n height.value = e.height;\r\n },\r\n onEnd: (e) => {\r\n \"worklet\";\r\n if(Platform.OS as string === 'harmony'){\r\n heightWhenOpened.value = e.height;\r\n }\r\n \r\n isClosed.value = e.height === 0;\r\n\r\n // `height` update happens in `onMove` handler\r\n // in `onEnd` we need to update only if `onMove`\r\n // wasn't called (i. e. duration === 0)\r\n //\r\n // we can not call this code without condition below\r\n // because in some corner cases (iOS with `secureTextEntry`)\r\n // `onEnd` can be emitted before `onMove` and in this case\r\n // it may lead to choppy/glitchy/jumpy UI\r\n // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327\r\n if (e.duration === 0) {\r\n progress.value = e.progress;\r\n height.value = e.height;\r\n }\r\n },\r\n },\r\n [],\r\n );\r\n\r\n return { height, progress, heightWhenOpened, isClosed };\r\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;MAE/B;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,IAAIM,CAAC,CAACK,QAAQ,KAAK,CAAC,EAAE;QACpBT,QAAQ,CAACD,KAAK,GAAGK,CAAC,CAACJ,QAAQ;QAC3BF,MAAM,CAACC,KAAK,GAAGK,CAAC,CAACN,MAAM;MACzB;IACF;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEA,MAAM;IAAEE,QAAQ;IAAEJ,gBAAgB;IAAEK;EAAS,CAAC;AACzD,CAAC;AAACS,OAAA,CAAAjB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
10
+ var _hooks = require("../../hooks");
11
+ var _hooks2 = require("./hooks");
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
14
+ const defaultLayout = {
15
+ x: 0,
16
+ y: 0,
17
+ width: 0,
18
+ height: 0
19
+ };
20
+
21
+ /**
22
+ * View that moves out of the way when the keyboard appears by automatically
23
+ * adjusting its height, position, or bottom padding.
24
+ */
25
+ const KeyboardAvoidingView = /*#__PURE__*/(0, _react.forwardRef)(({
26
+ behavior,
27
+ children,
28
+ contentContainerStyle,
29
+ enabled = true,
30
+ keyboardVerticalOffset = 0,
31
+ style,
32
+ onLayout: onLayoutProps,
33
+ ...props
34
+ }, ref) => {
35
+ const initialFrame = (0, _reactNativeReanimated.useSharedValue)(null);
36
+ const frame = (0, _reactNativeReanimated.useDerivedValue)(() => initialFrame.value || defaultLayout);
37
+ const keyboard = (0, _hooks2.useKeyboardAnimation)();
38
+ const {
39
+ height: screenHeight
40
+ } = (0, _hooks.useWindowDimensions)();
41
+ const relativeKeyboardHeight = (0, _react.useCallback)(() => {
42
+ "worklet";
43
+
44
+ const keyboardY = screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
45
+ return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
46
+ }, [screenHeight, keyboardVerticalOffset]);
47
+ const onLayoutWorklet = (0, _react.useCallback)(layout => {
48
+ "worklet";
49
+
50
+ if (keyboard.isClosed.value || initialFrame.value === null) {
51
+ // eslint-disable-next-line react-compiler/react-compiler
52
+ initialFrame.value = layout;
53
+ }
54
+ }, []);
55
+ const onLayout = (0, _react.useCallback)(e => {
56
+ (0, _reactNativeReanimated.runOnUI)(onLayoutWorklet)(e.nativeEvent.layout);
57
+ onLayoutProps === null || onLayoutProps === void 0 || onLayoutProps(e);
58
+ }, [onLayoutProps]);
59
+ const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
60
+ const bottom = (0, _reactNativeReanimated.interpolate)(keyboard.progress.value, [0, 1], [0, relativeKeyboardHeight()]);
61
+ const bottomHeight = enabled ? bottom : 0;
62
+ switch (behavior) {
63
+ case "height":
64
+ if (!keyboard.isClosed.value) {
65
+ return {
66
+ height: frame.value.height - bottomHeight,
67
+ flex: 0
68
+ };
69
+ }
70
+ return {};
71
+ case "position":
72
+ return {
73
+ bottom: bottomHeight
74
+ };
75
+ case "padding":
76
+ return {
77
+ paddingBottom: bottomHeight
78
+ };
79
+ default:
80
+ return {};
81
+ }
82
+ }, [behavior, enabled, relativeKeyboardHeight]);
83
+ const isPositionBehavior = behavior === "position";
84
+ const containerStyle = isPositionBehavior ? contentContainerStyle : style;
85
+ const combinedStyles = (0, _react.useMemo)(() => [containerStyle, animatedStyle], [containerStyle, animatedStyle]);
86
+ if (isPositionBehavior) {
87
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({
88
+ ref: ref,
89
+ style: style,
90
+ onLayout: onLayout
91
+ }, props), /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
92
+ style: combinedStyles
93
+ }, children));
94
+ }
95
+ return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, _extends({
96
+ ref: ref,
97
+ onLayout: onLayout,
98
+ style: combinedStyles
99
+ }, props), children);
100
+ });
101
+ var _default = exports.default = KeyboardAvoidingView;
102
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_hooks","_hooks2","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","defaultLayout","x","y","width","height","KeyboardAvoidingView","forwardRef","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","ref","initialFrame","useSharedValue","frame","useDerivedValue","value","keyboard","useKeyboardAnimation","screenHeight","useWindowDimensions","relativeKeyboardHeight","useCallback","keyboardY","heightWhenOpened","Math","max","onLayoutWorklet","layout","isClosed","runOnUI","nativeEvent","animatedStyle","useAnimatedStyle","bottom","interpolate","progress","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles","useMemo","createElement","View","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\r\nimport { View } from \"react-native\";\r\nimport Reanimated, {\r\n interpolate,\r\n runOnUI,\r\n useAnimatedStyle,\r\n useDerivedValue,\r\n useSharedValue,\r\n} from \"react-native-reanimated\";\r\n\r\nimport { useWindowDimensions } from \"../../hooks\";\r\n\r\nimport { useKeyboardAnimation } from \"./hooks\";\r\n\r\nimport type { LayoutRectangle, ViewProps } from \"react-native\";\r\n\r\nexport type KeyboardAvoidingViewProps = {\r\n /**\r\n * Specify how to react to the presence of the keyboard.\r\n */\r\n behavior?: \"height\" | \"position\" | \"padding\";\r\n\r\n /**\r\n * Style of the content container when `behavior` is 'position'.\r\n */\r\n contentContainerStyle?: ViewProps[\"style\"];\r\n\r\n /**\r\n * Controls whether this `KeyboardAvoidingView` instance should take effect.\r\n * This is useful when more than one is on the screen. Defaults to true.\r\n */\r\n enabled?: boolean;\r\n\r\n /**\r\n * Distance between the top of the user screen and the React Native view. This\r\n * may be non-zero in some cases. Defaults to 0.\r\n */\r\n keyboardVerticalOffset?: number;\r\n} & ViewProps;\r\n\r\nconst defaultLayout: LayoutRectangle = {\r\n x: 0,\r\n y: 0,\r\n width: 0,\r\n height: 0,\r\n};\r\n\r\n/**\r\n * View that moves out of the way when the keyboard appears by automatically\r\n * adjusting its height, position, or bottom padding.\r\n */\r\nconst KeyboardAvoidingView = forwardRef<\r\n View,\r\n React.PropsWithChildren<KeyboardAvoidingViewProps>\r\n>(\r\n (\r\n {\r\n behavior,\r\n children,\r\n contentContainerStyle,\r\n enabled = true,\r\n keyboardVerticalOffset = 0,\r\n style,\r\n onLayout: onLayoutProps,\r\n ...props\r\n },\r\n ref,\r\n ) => {\r\n const initialFrame = useSharedValue<LayoutRectangle | null>(null);\r\n const frame = useDerivedValue(() => initialFrame.value || defaultLayout);\r\n\r\n const keyboard = useKeyboardAnimation();\r\n const { height: screenHeight } = useWindowDimensions();\r\n\r\n const relativeKeyboardHeight = useCallback(() => {\r\n \"worklet\";\r\n\r\n const keyboardY =\r\n screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;\r\n\r\n return Math.max(frame.value.y + frame.value.height - keyboardY, 0);\r\n }, [screenHeight, keyboardVerticalOffset]);\r\n\r\n const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {\r\n \"worklet\";\r\n\r\n if (keyboard.isClosed.value || initialFrame.value === null) {\r\n // eslint-disable-next-line react-compiler/react-compiler\r\n initialFrame.value = layout;\r\n }\r\n }, []);\r\n const onLayout = useCallback<NonNullable<ViewProps[\"onLayout\"]>>(\r\n (e) => {\r\n runOnUI(onLayoutWorklet)(e.nativeEvent.layout);\r\n onLayoutProps?.(e);\r\n },\r\n [onLayoutProps],\r\n );\r\n\r\n const animatedStyle = useAnimatedStyle(() => {\r\n const bottom = interpolate(\r\n keyboard.progress.value,\r\n [0, 1],\r\n [0, relativeKeyboardHeight()],\r\n );\r\n const bottomHeight = enabled ? bottom : 0;\r\n\r\n switch (behavior) {\r\n case \"height\":\r\n if (!keyboard.isClosed.value) {\r\n return {\r\n height: frame.value.height - bottomHeight,\r\n flex: 0,\r\n };\r\n }\r\n\r\n return {};\r\n\r\n case \"position\":\r\n return { bottom: bottomHeight };\r\n\r\n case \"padding\":\r\n return { paddingBottom: bottomHeight };\r\n default:\r\n return {};\r\n }\r\n }, [behavior, enabled, relativeKeyboardHeight]);\r\n const isPositionBehavior = behavior === \"position\";\r\n const containerStyle = isPositionBehavior ? contentContainerStyle : style;\r\n const combinedStyles = useMemo(\r\n () => [containerStyle, animatedStyle],\r\n [containerStyle, animatedStyle],\r\n );\r\n\r\n if (isPositionBehavior) {\r\n return (\r\n <View ref={ref} style={style} onLayout={onLayout} {...props}>\r\n <Reanimated.View style={combinedStyles}>{children}</Reanimated.View>\r\n </View>\r\n );\r\n }\r\n\r\n return (\r\n <Reanimated.View\r\n ref={ref}\r\n onLayout={onLayout}\r\n style={combinedStyles}\r\n {...props}\r\n >\r\n {children}\r\n </Reanimated.View>\r\n );\r\n },\r\n);\r\n\r\nexport default KeyboardAvoidingView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KAAK,SAAS;QACZ,OAAO;UAAEE,aAAa,EAAEF;QAAa,CAAC;MACxC;QACE,OAAO,CAAC,CAAC;IACb;EACF,CAAC,EAAE,CAACnC,QAAQ,EAAEG,OAAO,EAAEgB,sBAAsB,CAAC,CAAC;EAC/C,MAAMmB,kBAAkB,GAAGtC,QAAQ,KAAK,UAAU;EAClD,MAAMuC,cAAc,GAAGD,kBAAkB,GAAGpC,qBAAqB,GAAGG,KAAK;EACzE,MAAMmC,cAAc,GAAG,IAAAC,cAAO,EAC5B,MAAM,CAACF,cAAc,EAAET,aAAa,CAAC,EACrC,CAACS,cAAc,EAAET,aAAa,CAChC,CAAC;EAED,IAAIQ,kBAAkB,EAAE;IACtB,oBACE7E,MAAA,CAAAiB,OAAA,CAAAgE,aAAA,CAAC9E,YAAA,CAAA+E,IAAI,EAAAxD,QAAA;MAACsB,GAAG,EAAEA,GAAI;MAACJ,KAAK,EAAEA,KAAM;MAACC,QAAQ,EAAEA;IAAS,GAAKE,KAAK,gBACzD/C,MAAA,CAAAiB,OAAA,CAAAgE,aAAA,CAAC7E,sBAAA,CAAAa,OAAU,CAACiE,IAAI;MAACtC,KAAK,EAAEmC;IAAe,GAAEvC,QAA0B,CAC/D,CAAC;EAEX;EAEA,oBACExC,MAAA,CAAAiB,OAAA,CAAAgE,aAAA,CAAC7E,sBAAA,CAAAa,OAAU,CAACiE,IAAI,EAAAxD,QAAA;IACdsB,GAAG,EAAEA,GAAI;IACTH,QAAQ,EAAEA,QAAS;IACnBD,KAAK,EAAEmC;EAAe,GAClBhC,KAAK,GAERP,QACc,CAAC;AAEtB,CACF,CAAC;AAAC,IAAA2C,QAAA,GAAAC,OAAA,CAAAnE,OAAA,GAEaoB,oBAAoB","ignoreList":[]}
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
10
+ var _hooks = require("../../hooks");
11
+ var _useSmoothKeyboardHandler = require("./useSmoothKeyboardHandler");
12
+ var _utils = require("./utils");
13
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
15
+ /*
16
+ * Everything begins from `onStart` handler. This handler is called every time,
17
+ * when keyboard changes its size or when focused `TextInput` was changed. In
18
+ * this handler we are calculating/memoizing values which later will be used
19
+ * during layout movement. For that we calculate:
20
+ * - layout of focused field (`layout`) - to understand whether there will be overlap
21
+ * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation
22
+ * - future keyboard height (`keyboardHeight`) - used in scroll interpolation
23
+ * - current scroll position (`scrollPosition`) - used to scroll from this point
24
+ *
25
+ * Once we've calculated all necessary variables - we can actually start to use them.
26
+ * It happens in `onMove` handler - this function simply calls `maybeScroll` with
27
+ * current keyboard frame height. This functions makes the smooth transition.
28
+ *
29
+ * When the transition has finished we go to `onEnd` handler. In this handler
30
+ * we verify, that the current field is not overlapped within a keyboard frame.
31
+ * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,
32
+ * however there could be some cases, when `onMove` is not called:
33
+ * - on iOS when TextInput was changed - keyboard transition is instant
34
+ * - on Android when TextInput was changed and keyboard size wasn't changed
35
+ * So `onEnd` handler handle the case, when `onMove` wasn't triggered.
36
+ *
37
+ * ====================================================================================================================+
38
+ * -----------------------------------------------------Flow chart-----------------------------------------------------+
39
+ * ====================================================================================================================+
40
+ *
41
+ * +============================+ +============================+ +==================================+
42
+ * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>
43
+ * + + + (run `onStart`) + + `onMove` is getting called +
44
+ * +============================+ +============================+ +==================================+
45
+ *
46
+ *
47
+ * +============================+ +============================+ +=====================================+
48
+ * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +
49
+ * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +
50
+ * +============================+ +============================+ +=====================================+
51
+ *
52
+ */
53
+ const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)(({
54
+ children,
55
+ onLayout,
56
+ bottomOffset = 0,
57
+ disableScrollOnKeyboardHide = false,
58
+ enabled = true,
59
+ extraKeyboardSpace = 0,
60
+ ...rest
61
+ }, ref) => {
62
+ const scrollViewAnimatedRef = (0, _reactNativeReanimated.useAnimatedRef)();
63
+ const scrollViewTarget = (0, _reactNativeReanimated.useSharedValue)(null);
64
+ const scrollPosition = (0, _reactNativeReanimated.useSharedValue)(0);
65
+ const position = (0, _reactNativeReanimated.useScrollViewOffset)(scrollViewAnimatedRef);
66
+ const currentKeyboardFrameHeight = (0, _reactNativeReanimated.useSharedValue)(0);
67
+ const keyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
68
+ const keyboardWillAppear = (0, _reactNativeReanimated.useSharedValue)(false);
69
+ const tag = (0, _reactNativeReanimated.useSharedValue)(-1);
70
+ const initialKeyboardSize = (0, _reactNativeReanimated.useSharedValue)(0);
71
+ const scrollBeforeKeyboardMovement = (0, _reactNativeReanimated.useSharedValue)(0);
72
+ const {
73
+ input
74
+ } = (0, _hooks.useReanimatedFocusedInput)();
75
+ const layout = (0, _reactNativeReanimated.useSharedValue)(null);
76
+ const {
77
+ height
78
+ } = (0, _hooks.useWindowDimensions)();
79
+ const onRef = (0, _react.useCallback)(assignedRef => {
80
+ if (typeof ref === "function") {
81
+ ref(assignedRef);
82
+ } else if (ref) {
83
+ ref.current = assignedRef;
84
+ }
85
+ scrollViewAnimatedRef(assignedRef);
86
+ }, []);
87
+ const onScrollViewLayout = (0, _react.useCallback)(e => {
88
+ scrollViewTarget.value = (0, _reactNative.findNodeHandle)(scrollViewAnimatedRef.current);
89
+ onLayout === null || onLayout === void 0 || onLayout(e);
90
+ }, [onLayout]);
91
+
92
+ /**
93
+ * Function that will scroll a ScrollView as keyboard gets moving
94
+ */
95
+ const maybeScroll = (0, _react.useCallback)((e, animated = false) => {
96
+ "worklet";
97
+
98
+ var _layout$value, _layout$value2, _layout$value3;
99
+ if (!enabled) {
100
+ return 0;
101
+ }
102
+
103
+ // input belongs to ScrollView
104
+ if (((_layout$value = layout.value) === null || _layout$value === void 0 ? void 0 : _layout$value.parentScrollViewTarget) !== scrollViewTarget.value) {
105
+ return 0;
106
+ }
107
+ const visibleRect = height - keyboardHeight.value;
108
+ const absoluteY = ((_layout$value2 = layout.value) === null || _layout$value2 === void 0 ? void 0 : _layout$value2.layout.absoluteY) || 0;
109
+ const inputHeight = ((_layout$value3 = layout.value) === null || _layout$value3 === void 0 ? void 0 : _layout$value3.layout.height) || 0;
110
+ const point = absoluteY + inputHeight;
111
+ if (visibleRect - point <= bottomOffset) {
112
+ const relativeScrollTo = keyboardHeight.value - (height - point) + bottomOffset;
113
+ const interpolatedScrollTo = (0, _reactNativeReanimated.interpolate)(e, [initialKeyboardSize.value, keyboardHeight.value], [0, (0, _utils.scrollDistanceWithRespectToSnapPoints)(relativeScrollTo + scrollPosition.value, rest.snapToOffsets) - scrollPosition.value]);
114
+ const targetScrollY = Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
115
+ (0, _reactNativeReanimated.scrollTo)(scrollViewAnimatedRef, 0, targetScrollY, animated);
116
+ return interpolatedScrollTo;
117
+ }
118
+ if (absoluteY < 0) {
119
+ const positionOnScreen = visibleRect - inputHeight - bottomOffset;
120
+ const topOfScreen = scrollPosition.value + absoluteY;
121
+ (0, _reactNativeReanimated.scrollTo)(scrollViewAnimatedRef, 0, topOfScreen - positionOnScreen, animated);
122
+ }
123
+ return 0;
124
+ }, [bottomOffset, enabled, height, rest.snapToOffsets]);
125
+ const scrollFromCurrentPosition = (0, _react.useCallback)(customHeight => {
126
+ "worklet";
127
+
128
+ var _input$value;
129
+ const prevScrollPosition = scrollPosition.value;
130
+ const prevLayout = layout.value;
131
+ if (!((_input$value = input.value) !== null && _input$value !== void 0 && _input$value.layout)) {
132
+ return;
133
+ }
134
+
135
+ // eslint-disable-next-line react-compiler/react-compiler
136
+ layout.value = {
137
+ ...input.value,
138
+ layout: {
139
+ ...input.value.layout,
140
+ height: customHeight ?? input.value.layout.height
141
+ }
142
+ };
143
+ scrollPosition.value = position.value;
144
+ maybeScroll(keyboardHeight.value, true);
145
+ scrollPosition.value = prevScrollPosition;
146
+ layout.value = prevLayout;
147
+ }, [maybeScroll]);
148
+ const onChangeText = (0, _react.useCallback)(() => {
149
+ "worklet";
150
+
151
+ // if typing a text caused layout shift, then we need to ignore this handler
152
+ // because this event will be handled in `useAnimatedReaction` below
153
+ var _layout$value4, _input$value2;
154
+ if (((_layout$value4 = layout.value) === null || _layout$value4 === void 0 ? void 0 : _layout$value4.layout.height) !== ((_input$value2 = input.value) === null || _input$value2 === void 0 ? void 0 : _input$value2.layout.height)) {
155
+ return;
156
+ }
157
+ scrollFromCurrentPosition();
158
+ }, [scrollFromCurrentPosition]);
159
+ const onSelectionChange = (0, _react.useCallback)(e => {
160
+ "worklet";
161
+
162
+ if (e.selection.start.position !== e.selection.end.position) {
163
+ scrollFromCurrentPosition(e.selection.end.y);
164
+ }
165
+ }, [scrollFromCurrentPosition]);
166
+ const onChangeTextHandler = (0, _react.useMemo)(() => (0, _utils.debounce)(onChangeText, 200), [onChangeText]);
167
+ (0, _hooks.useFocusedInputHandler)({
168
+ onChangeText: onChangeTextHandler,
169
+ onSelectionChange: onSelectionChange
170
+ }, [onChangeTextHandler, onSelectionChange]);
171
+ (0, _useSmoothKeyboardHandler.useSmoothKeyboardHandler)({
172
+ onStart: e => {
173
+ "worklet";
174
+
175
+ const keyboardWillChangeSize = keyboardHeight.value !== e.height && e.height > 0;
176
+ keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;
177
+ const keyboardWillHide = e.height === 0;
178
+ const focusWasChanged = tag.value !== e.target && e.target !== -1 || keyboardWillChangeSize;
179
+ if (keyboardWillChangeSize) {
180
+ initialKeyboardSize.value = keyboardHeight.value;
181
+ }
182
+ if (keyboardWillHide) {
183
+ // on back transition need to interpolate as [0, keyboardHeight]
184
+ initialKeyboardSize.value = 0;
185
+ scrollPosition.value = scrollBeforeKeyboardMovement.value;
186
+ }
187
+ if (keyboardWillAppear.value || keyboardWillChangeSize || focusWasChanged) {
188
+ // persist scroll value
189
+ scrollPosition.value = position.value;
190
+ // just persist height - later will be used in interpolation
191
+ keyboardHeight.value = e.height;
192
+ }
193
+
194
+ // focus was changed
195
+ if (focusWasChanged) {
196
+ tag.value = e.target;
197
+
198
+ // save position of focused text input when keyboard starts to move
199
+ layout.value = input.value;
200
+ // save current scroll position - when keyboard will hide we'll reuse
201
+ // this value to achieve smooth hide effect
202
+ scrollBeforeKeyboardMovement.value = position.value;
203
+ }
204
+ if (focusWasChanged && !keyboardWillAppear.value) {
205
+ // update position on scroll value, so `onEnd` handler
206
+ // will pick up correct values
207
+ position.value += maybeScroll(e.height, true);
208
+ }
209
+ },
210
+ onMove: e => {
211
+ "worklet";
212
+
213
+ const keyboardFrame = (0, _reactNativeReanimated.interpolate)(e.height, [0, keyboardHeight.value], [0, keyboardHeight.value + extraKeyboardSpace]);
214
+ currentKeyboardFrameHeight.value = keyboardFrame;
215
+
216
+ // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens
217
+ if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {
218
+ maybeScroll(e.height);
219
+ }
220
+ },
221
+ onEnd: e => {
222
+ "worklet";
223
+
224
+ keyboardHeight.value = e.height;
225
+ scrollPosition.value = position.value;
226
+ }
227
+ }, [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace]);
228
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => input.value, (current, previous) => {
229
+ if ((current === null || current === void 0 ? void 0 : current.target) === (previous === null || previous === void 0 ? void 0 : previous.target) && (current === null || current === void 0 ? void 0 : current.layout.height) !== (previous === null || previous === void 0 ? void 0 : previous.layout.height)) {
230
+ const prevLayout = layout.value;
231
+ layout.value = input.value;
232
+ scrollPosition.value += maybeScroll(keyboardHeight.value, true);
233
+ layout.value = prevLayout;
234
+ }
235
+ }, []);
236
+ const view = (0, _reactNativeReanimated.useAnimatedStyle)(() => enabled ? {
237
+ // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
238
+ // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
239
+ // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
240
+ // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
241
+ // re-calculation on every animation frame and it helps to achieve smooth animation.
242
+ // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
243
+ paddingBottom: currentKeyboardFrameHeight.value + 1
244
+ } : {}, [enabled]);
245
+ return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.ScrollView, _extends({
246
+ ref: onRef
247
+ }, rest, {
248
+ onLayout: onScrollViewLayout,
249
+ scrollEventThrottle: 16
250
+ }), children, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
251
+ style: view
252
+ }));
253
+ });
254
+ var _default = exports.default = KeyboardAwareScrollView;
255
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_hooks","_useSmoothKeyboardHandler","_utils","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","KeyboardAwareScrollView","forwardRef","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","rest","ref","scrollViewAnimatedRef","useAnimatedRef","scrollViewTarget","useSharedValue","scrollPosition","position","useScrollViewOffset","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","useReanimatedFocusedInput","layout","height","useWindowDimensions","onRef","useCallback","assignedRef","current","onScrollViewLayout","value","findNodeHandle","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","interpolate","scrollDistanceWithRespectToSnapPoints","snapToOffsets","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","scrollFromCurrentPosition","customHeight","_input$value","prevScrollPosition","prevLayout","onChangeText","_layout$value4","_input$value2","onSelectionChange","selection","start","end","y","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","keyboardFrame","onEnd","useAnimatedReaction","previous","view","useAnimatedStyle","paddingBottom","createElement","ScrollView","scrollEventThrottle","View","style","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\r\nimport { findNodeHandle } from \"react-native\";\r\nimport Reanimated, {\r\n interpolate,\r\n scrollTo,\r\n useAnimatedReaction,\r\n useAnimatedRef,\r\n useAnimatedStyle,\r\n useScrollViewOffset,\r\n useSharedValue,\r\n} from \"react-native-reanimated\";\r\n\r\nimport {\r\n useFocusedInputHandler,\r\n useReanimatedFocusedInput,\r\n useWindowDimensions,\r\n} from \"../../hooks\";\r\n\r\nimport { useSmoothKeyboardHandler } from \"./useSmoothKeyboardHandler\";\r\nimport { debounce, scrollDistanceWithRespectToSnapPoints } from \"./utils\";\r\n\r\nimport type {\r\n LayoutChangeEvent,\r\n ScrollView,\r\n ScrollViewProps,\r\n} from \"react-native\";\r\nimport type {\r\n FocusedInputLayoutChangedEvent,\r\n FocusedInputSelectionChangedEvent,\r\n} from \"..//../types\";\r\n\r\nexport type KeyboardAwareScrollViewProps = {\r\n /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\r\n bottomOffset?: number;\r\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\r\n disableScrollOnKeyboardHide?: boolean;\r\n /** Controls whether this `KeyboardAwareScrollView` instance should take effect. Default is `true` */\r\n enabled?: boolean;\r\n /** Adjusting the bottom spacing of KeyboardAwareScrollView. Default is `0` */\r\n extraKeyboardSpace?: number;\r\n} & ScrollViewProps;\r\n\r\n/*\r\n * Everything begins from `onStart` handler. This handler is called every time,\r\n * when keyboard changes its size or when focused `TextInput` was changed. In\r\n * this handler we are calculating/memoizing values which later will be used\r\n * during layout movement. For that we calculate:\r\n * - layout of focused field (`layout`) - to understand whether there will be overlap\r\n * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation\r\n * - future keyboard height (`keyboardHeight`) - used in scroll interpolation\r\n * - current scroll position (`scrollPosition`) - used to scroll from this point\r\n *\r\n * Once we've calculated all necessary variables - we can actually start to use them.\r\n * It happens in `onMove` handler - this function simply calls `maybeScroll` with\r\n * current keyboard frame height. This functions makes the smooth transition.\r\n *\r\n * When the transition has finished we go to `onEnd` handler. In this handler\r\n * we verify, that the current field is not overlapped within a keyboard frame.\r\n * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,\r\n * however there could be some cases, when `onMove` is not called:\r\n * - on iOS when TextInput was changed - keyboard transition is instant\r\n * - on Android when TextInput was changed and keyboard size wasn't changed\r\n * So `onEnd` handler handle the case, when `onMove` wasn't triggered.\r\n *\r\n * ====================================================================================================================+\r\n * -----------------------------------------------------Flow chart-----------------------------------------------------+\r\n * ====================================================================================================================+\r\n *\r\n * +============================+ +============================+ +==================================+\r\n * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>\r\n * + + + (run `onStart`) + + `onMove` is getting called +\r\n * +============================+ +============================+ +==================================+\r\n *\r\n *\r\n * +============================+ +============================+ +=====================================+\r\n * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +\r\n * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +\r\n * +============================+ +============================+ +=====================================+\r\n *\r\n */\r\nconst KeyboardAwareScrollView = forwardRef<\r\n ScrollView,\r\n React.PropsWithChildren<KeyboardAwareScrollViewProps>\r\n>(\r\n (\r\n {\r\n children,\r\n onLayout,\r\n bottomOffset = 0,\r\n disableScrollOnKeyboardHide = false,\r\n enabled = true,\r\n extraKeyboardSpace = 0,\r\n ...rest\r\n },\r\n ref,\r\n ) => {\r\n const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();\r\n const scrollViewTarget = useSharedValue<number | null>(null);\r\n const scrollPosition = useSharedValue(0);\r\n const position = useScrollViewOffset(scrollViewAnimatedRef);\r\n const currentKeyboardFrameHeight = useSharedValue(0);\r\n const keyboardHeight = useSharedValue(0);\r\n const keyboardWillAppear = useSharedValue(false);\r\n const tag = useSharedValue(-1);\r\n const initialKeyboardSize = useSharedValue(0);\r\n const scrollBeforeKeyboardMovement = useSharedValue(0);\r\n const { input } = useReanimatedFocusedInput();\r\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\r\n\r\n const { height } = useWindowDimensions();\r\n\r\n const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {\r\n if (typeof ref === \"function\") {\r\n ref(assignedRef);\r\n } else if (ref) {\r\n ref.current = assignedRef;\r\n }\r\n\r\n scrollViewAnimatedRef(assignedRef);\r\n }, []);\r\n const onScrollViewLayout = useCallback(\r\n (e: LayoutChangeEvent) => {\r\n scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);\r\n\r\n onLayout?.(e);\r\n },\r\n [onLayout],\r\n );\r\n\r\n /**\r\n * Function that will scroll a ScrollView as keyboard gets moving\r\n */\r\n const maybeScroll = useCallback(\r\n (e: number, animated: boolean = false) => {\r\n \"worklet\";\r\n\r\n if (!enabled) {\r\n return 0;\r\n }\r\n\r\n // input belongs to ScrollView\r\n if (layout.value?.parentScrollViewTarget !== scrollViewTarget.value) {\r\n return 0;\r\n }\r\n\r\n const visibleRect = height - keyboardHeight.value;\r\n const absoluteY = layout.value?.layout.absoluteY || 0;\r\n const inputHeight = layout.value?.layout.height || 0;\r\n const point = absoluteY + inputHeight;\r\n\r\n if (visibleRect - point <= bottomOffset) {\r\n const relativeScrollTo =\r\n keyboardHeight.value - (height - point) + bottomOffset;\r\n const interpolatedScrollTo = interpolate(\r\n e,\r\n [initialKeyboardSize.value, keyboardHeight.value],\r\n [\r\n 0,\r\n scrollDistanceWithRespectToSnapPoints(\r\n relativeScrollTo + scrollPosition.value,\r\n rest.snapToOffsets,\r\n ) - scrollPosition.value,\r\n ],\r\n );\r\n const targetScrollY =\r\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\r\n scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);\r\n\r\n return interpolatedScrollTo;\r\n }\r\n\r\n if (absoluteY < 0) {\r\n const positionOnScreen = visibleRect - inputHeight - bottomOffset;\r\n const topOfScreen = scrollPosition.value + absoluteY;\r\n\r\n scrollTo(\r\n scrollViewAnimatedRef,\r\n 0,\r\n topOfScreen - positionOnScreen,\r\n animated,\r\n );\r\n }\r\n\r\n return 0;\r\n },\r\n [bottomOffset, enabled, height, rest.snapToOffsets],\r\n );\r\n\r\n const scrollFromCurrentPosition = useCallback(\r\n (customHeight?: number) => {\r\n \"worklet\";\r\n\r\n const prevScrollPosition = scrollPosition.value;\r\n const prevLayout = layout.value;\r\n\r\n if (!input.value?.layout) {\r\n return;\r\n }\r\n\r\n // eslint-disable-next-line react-compiler/react-compiler\r\n layout.value = {\r\n ...input.value,\r\n layout: {\r\n ...input.value.layout,\r\n height: customHeight ?? input.value.layout.height,\r\n },\r\n };\r\n scrollPosition.value = position.value;\r\n maybeScroll(keyboardHeight.value, true);\r\n scrollPosition.value = prevScrollPosition;\r\n layout.value = prevLayout;\r\n },\r\n [maybeScroll],\r\n );\r\n const onChangeText = useCallback(() => {\r\n \"worklet\";\r\n\r\n // if typing a text caused layout shift, then we need to ignore this handler\r\n // because this event will be handled in `useAnimatedReaction` below\r\n if (layout.value?.layout.height !== input.value?.layout.height) {\r\n return;\r\n }\r\n\r\n scrollFromCurrentPosition();\r\n }, [scrollFromCurrentPosition]);\r\n const onSelectionChange = useCallback(\r\n (e: FocusedInputSelectionChangedEvent) => {\r\n \"worklet\";\r\n\r\n if (e.selection.start.position !== e.selection.end.position) {\r\n scrollFromCurrentPosition(e.selection.end.y);\r\n }\r\n },\r\n [scrollFromCurrentPosition],\r\n );\r\n\r\n const onChangeTextHandler = useMemo(\r\n () => debounce(onChangeText, 200),\r\n [onChangeText],\r\n );\r\n\r\n useFocusedInputHandler(\r\n {\r\n onChangeText: onChangeTextHandler,\r\n onSelectionChange: onSelectionChange,\r\n },\r\n [onChangeTextHandler, onSelectionChange],\r\n );\r\n\r\n useSmoothKeyboardHandler(\r\n {\r\n onStart: (e) => {\r\n \"worklet\";\r\n\r\n const keyboardWillChangeSize =\r\n keyboardHeight.value !== e.height && e.height > 0;\r\n keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\r\n const keyboardWillHide = e.height === 0;\r\n const focusWasChanged =\r\n (tag.value !== e.target && e.target !== -1) ||\r\n keyboardWillChangeSize;\r\n\r\n if (keyboardWillChangeSize) {\r\n initialKeyboardSize.value = keyboardHeight.value;\r\n }\r\n\r\n if (keyboardWillHide) {\r\n // on back transition need to interpolate as [0, keyboardHeight]\r\n initialKeyboardSize.value = 0;\r\n scrollPosition.value = scrollBeforeKeyboardMovement.value;\r\n }\r\n\r\n if (\r\n keyboardWillAppear.value ||\r\n keyboardWillChangeSize ||\r\n focusWasChanged\r\n ) {\r\n // persist scroll value\r\n scrollPosition.value = position.value;\r\n // just persist height - later will be used in interpolation\r\n keyboardHeight.value = e.height;\r\n }\r\n\r\n // focus was changed\r\n if (focusWasChanged) {\r\n tag.value = e.target;\r\n\r\n // save position of focused text input when keyboard starts to move\r\n layout.value = input.value;\r\n // save current scroll position - when keyboard will hide we'll reuse\r\n // this value to achieve smooth hide effect\r\n scrollBeforeKeyboardMovement.value = position.value;\r\n }\r\n\r\n if (focusWasChanged && !keyboardWillAppear.value) {\r\n // update position on scroll value, so `onEnd` handler\r\n // will pick up correct values\r\n position.value += maybeScroll(e.height, true);\r\n }\r\n },\r\n onMove: (e) => {\r\n \"worklet\";\r\n\r\n const keyboardFrame = interpolate(\r\n e.height,\r\n [0, keyboardHeight.value],\r\n [0, keyboardHeight.value + extraKeyboardSpace],\r\n );\r\n currentKeyboardFrameHeight.value = keyboardFrame;\r\n\r\n // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\r\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\r\n maybeScroll(e.height);\r\n }\r\n },\r\n onEnd: (e) => {\r\n \"worklet\";\r\n\r\n keyboardHeight.value = e.height;\r\n scrollPosition.value = position.value;\r\n },\r\n },\r\n [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace],\r\n );\r\n\r\n useAnimatedReaction(\r\n () => input.value,\r\n (current, previous) => {\r\n if (\r\n current?.target === previous?.target &&\r\n current?.layout.height !== previous?.layout.height\r\n ) {\r\n const prevLayout = layout.value;\r\n\r\n layout.value = input.value;\r\n scrollPosition.value += maybeScroll(keyboardHeight.value, true);\r\n layout.value = prevLayout;\r\n }\r\n },\r\n [],\r\n );\r\n\r\n const view = useAnimatedStyle(\r\n () =>\r\n enabled\r\n ? {\r\n // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)\r\n // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding\r\n // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation\r\n // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout\r\n // re-calculation on every animation frame and it helps to achieve smooth animation.\r\n // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342\r\n paddingBottom: currentKeyboardFrameHeight.value + 1,\r\n }\r\n : {},\r\n [enabled],\r\n );\r\n\r\n return (\r\n <Reanimated.ScrollView\r\n ref={onRef}\r\n {...rest}\r\n onLayout={onScrollViewLayout}\r\n scrollEventThrottle={16}\r\n >\r\n {children}\r\n <Reanimated.View style={view} />\r\n </Reanimated.ScrollView>\r\n );\r\n },\r\n);\r\n\r\nexport default KeyboardAwareScrollView;\r\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAUA,IAAAG,MAAA,GAAAH,OAAA;AAMA,IAAAI,yBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAA0E,SAAAD,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAA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E,WAAW,CAACjB,cAAc,CAACe,KAAK,EAAE,IAAI,CAAC;MAC/DR,MAAM,CAACQ,KAAK,GAAG2B,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMwB,IAAI,GAAG,IAAAC,uCAAgB,EAC3B,MACE/E,OAAO,GACH;IACA;IACA;IACA;IACA;IACA;IACA;IACAgF,aAAa,EAAErE,0BAA0B,CAACgB,KAAK,GAAG;EACpD,CAAC,GACC,CAAC,CAAC,EACR,CAAC3B,OAAO,CACV,CAAC;EAED,oBACEvC,MAAA,CAAAkB,OAAA,CAAAsG,aAAA,CAACpH,sBAAA,CAAAc,OAAU,CAACuG,UAAU,EAAA9F,QAAA;IACpBe,GAAG,EAAEmB;EAAM,GACPpB,IAAI;IACRL,QAAQ,EAAE6B,kBAAmB;IAC7ByD,mBAAmB,EAAE;EAAG,IAEvBvF,QAAQ,eACTnC,MAAA,CAAAkB,OAAA,CAAAsG,aAAA,CAACpH,sBAAA,CAAAc,OAAU,CAACyG,IAAI;IAACC,KAAK,EAAEP;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAAC,IAAAQ,QAAA,GAAAC,OAAA,CAAA5G,OAAA,GAEae,uBAAuB","ignoreList":[]}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSmoothKeyboardHandler = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _reactNativeReanimated = require("react-native-reanimated");
9
+ var _hooks = require("../../hooks");
10
+ const IS_ANDROID_ELEVEN_OR_HIGHER = _reactNative.Platform.OS === "android" && _reactNative.Platform.Version >= 30;
11
+ // on these platforms keyboard transitions will be smooth
12
+ const IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS = IS_ANDROID_ELEVEN_OR_HIGHER || _reactNative.Platform.OS === "ios" || _reactNative.Platform.OS === 'harmony';
13
+ // on Android Telegram is not using androidx.core values and uses custom interpolation
14
+ // duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39
15
+ // and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40
16
+ const TELEGRAM_ANDROID_TIMING_CONFIG = {
17
+ duration: 250,
18
+ easing: _reactNativeReanimated.Easing.bezier(0.19919472913616398, 0.010644531250000006, 0.27920937042459737, 0.91025390625)
19
+ };
20
+
21
+ /**
22
+ * Hook that uses default transitions for iOS and Android > 11, and uses
23
+ * custom interpolation on Android < 11 to achieve more smooth animation
24
+ */
25
+ const useSmoothKeyboardHandler = (handler, deps) => {
26
+ const target = (0, _reactNativeReanimated.useSharedValue)(-1);
27
+ const height = (0, _reactNativeReanimated.useSharedValue)(0);
28
+ const persistedHeight = (0, _reactNativeReanimated.useSharedValue)(0);
29
+ const animatedKeyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
30
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => {
31
+ if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
32
+ return;
33
+ }
34
+ if (persistedHeight.value === 0) {
35
+ return;
36
+ }
37
+ const event = {
38
+ // it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`
39
+ duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
40
+ target: target.value,
41
+ height: animatedKeyboardHeight.value,
42
+ progress: animatedKeyboardHeight.value / persistedHeight.value
43
+ };
44
+ return event;
45
+ }, evt => {
46
+ var _handler$onMove;
47
+ if (!evt) {
48
+ return;
49
+ }
50
+ (_handler$onMove = handler.onMove) === null || _handler$onMove === void 0 || _handler$onMove.call(handler, evt);
51
+
52
+ // dispatch `onEnd`
53
+ if (evt.height === height.value) {
54
+ var _handler$onEnd;
55
+ (_handler$onEnd = handler.onEnd) === null || _handler$onEnd === void 0 || _handler$onEnd.call(handler, evt);
56
+ // eslint-disable-next-line react-compiler/react-compiler
57
+ persistedHeight.value = height.value;
58
+ }
59
+ },
60
+ // REA uses own version of `DependencyList` and it's not compatible with the same type from React
61
+ deps);
62
+ (0, _hooks.useKeyboardHandler)({
63
+ onStart: e => {
64
+ "worklet";
65
+
66
+ // immediately dispatch onStart/onEnd events if onStart dispatched with the same height
67
+ // and don't wait for animation 250ms
68
+ var _handler$onStart2;
69
+ if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS && e.height === persistedHeight.value) {
70
+ var _handler$onStart, _handler$onEnd2;
71
+ (_handler$onStart = handler.onStart) === null || _handler$onStart === void 0 || _handler$onStart.call(handler, e);
72
+ (_handler$onEnd2 = handler.onEnd) === null || _handler$onEnd2 === void 0 || _handler$onEnd2.call(handler, e);
73
+ return;
74
+ }
75
+ target.value = e.target;
76
+ height.value = e.height;
77
+ if (e.height > 0) {
78
+ persistedHeight.value = e.height;
79
+ }
80
+ // if we are running on Android < 9, then we are using custom interpolation
81
+ // to achieve smoother animation and use `animatedKeyboardHeight` as animation
82
+ // driver
83
+ if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
84
+ animatedKeyboardHeight.value = (0, _reactNativeReanimated.withTiming)(e.height, TELEGRAM_ANDROID_TIMING_CONFIG);
85
+ }
86
+ (_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 || _handler$onStart2.call(handler, {
87
+ ...e,
88
+ duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS ? e.duration : TELEGRAM_ANDROID_TIMING_CONFIG.duration
89
+ });
90
+ },
91
+ onMove: e => {
92
+ "worklet";
93
+
94
+ if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
95
+ var _handler$onMove2;
96
+ (_handler$onMove2 = handler.onMove) === null || _handler$onMove2 === void 0 || _handler$onMove2.call(handler, e);
97
+ }
98
+ },
99
+ onEnd: e => {
100
+ "worklet";
101
+
102
+ if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
103
+ var _handler$onEnd3;
104
+ (_handler$onEnd3 = handler.onEnd) === null || _handler$onEnd3 === void 0 || _handler$onEnd3.call(handler, e);
105
+ }
106
+ }
107
+ }, deps);
108
+ };
109
+ exports.useSmoothKeyboardHandler = useSmoothKeyboardHandler;
110
+ //# sourceMappingURL=useSmoothKeyboardHandler.js.map