@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,95 @@
1
+ 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); }
2
+ import React, { forwardRef, useCallback, useMemo } from "react";
3
+ import { View } from "react-native";
4
+ import Reanimated, { interpolate, runOnUI, useAnimatedStyle, useDerivedValue, useSharedValue } from "react-native-reanimated";
5
+ import { useWindowDimensions } from "../../hooks";
6
+ import { useKeyboardAnimation } from "./hooks";
7
+ const defaultLayout = {
8
+ x: 0,
9
+ y: 0,
10
+ width: 0,
11
+ height: 0
12
+ };
13
+
14
+ /**
15
+ * View that moves out of the way when the keyboard appears by automatically
16
+ * adjusting its height, position, or bottom padding.
17
+ */
18
+ const KeyboardAvoidingView = /*#__PURE__*/forwardRef(({
19
+ behavior,
20
+ children,
21
+ contentContainerStyle,
22
+ enabled = true,
23
+ keyboardVerticalOffset = 0,
24
+ style,
25
+ onLayout: onLayoutProps,
26
+ ...props
27
+ }, ref) => {
28
+ const initialFrame = useSharedValue(null);
29
+ const frame = useDerivedValue(() => initialFrame.value || defaultLayout);
30
+ const keyboard = useKeyboardAnimation();
31
+ const {
32
+ height: screenHeight
33
+ } = useWindowDimensions();
34
+ const relativeKeyboardHeight = useCallback(() => {
35
+ "worklet";
36
+
37
+ const keyboardY = screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
38
+ return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
39
+ }, [screenHeight, keyboardVerticalOffset]);
40
+ const onLayoutWorklet = useCallback(layout => {
41
+ "worklet";
42
+
43
+ if (keyboard.isClosed.value || initialFrame.value === null) {
44
+ // eslint-disable-next-line react-compiler/react-compiler
45
+ initialFrame.value = layout;
46
+ }
47
+ }, []);
48
+ const onLayout = useCallback(e => {
49
+ runOnUI(onLayoutWorklet)(e.nativeEvent.layout);
50
+ onLayoutProps === null || onLayoutProps === void 0 || onLayoutProps(e);
51
+ }, [onLayoutProps]);
52
+ const animatedStyle = useAnimatedStyle(() => {
53
+ const bottom = interpolate(keyboard.progress.value, [0, 1], [0, relativeKeyboardHeight()]);
54
+ const bottomHeight = enabled ? bottom : 0;
55
+ switch (behavior) {
56
+ case "height":
57
+ if (!keyboard.isClosed.value) {
58
+ return {
59
+ height: frame.value.height - bottomHeight,
60
+ flex: 0
61
+ };
62
+ }
63
+ return {};
64
+ case "position":
65
+ return {
66
+ bottom: bottomHeight
67
+ };
68
+ case "padding":
69
+ return {
70
+ paddingBottom: bottomHeight
71
+ };
72
+ default:
73
+ return {};
74
+ }
75
+ }, [behavior, enabled, relativeKeyboardHeight]);
76
+ const isPositionBehavior = behavior === "position";
77
+ const containerStyle = isPositionBehavior ? contentContainerStyle : style;
78
+ const combinedStyles = useMemo(() => [containerStyle, animatedStyle], [containerStyle, animatedStyle]);
79
+ if (isPositionBehavior) {
80
+ return /*#__PURE__*/React.createElement(View, _extends({
81
+ ref: ref,
82
+ style: style,
83
+ onLayout: onLayout
84
+ }, props), /*#__PURE__*/React.createElement(Reanimated.View, {
85
+ style: combinedStyles
86
+ }, children));
87
+ }
88
+ return /*#__PURE__*/React.createElement(Reanimated.View, _extends({
89
+ ref: ref,
90
+ onLayout: onLayout,
91
+ style: combinedStyles
92
+ }, props), children);
93
+ });
94
+ export default KeyboardAvoidingView;
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","forwardRef","useCallback","useMemo","View","Reanimated","interpolate","runOnUI","useAnimatedStyle","useDerivedValue","useSharedValue","useWindowDimensions","useKeyboardAnimation","defaultLayout","x","y","width","height","KeyboardAvoidingView","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","ref","initialFrame","frame","value","keyboard","screenHeight","relativeKeyboardHeight","keyboardY","heightWhenOpened","Math","max","onLayoutWorklet","layout","isClosed","e","nativeEvent","animatedStyle","bottom","progress","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles","createElement","_extends"],"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 </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CAAC;IACb;EACF,CAAC,EAAE,CAAC5B,QAAQ,EAAEG,OAAO,EAAEY,sBAAsB,CAAC,CAAC;EAC/C,MAAMgB,kBAAkB,GAAG/B,QAAQ,KAAK,UAAU;EAClD,MAAMgC,cAAc,GAAGD,kBAAkB,GAAG7B,qBAAqB,GAAGG,KAAK;EACzE,MAAM4B,cAAc,GAAGjD,OAAO,CAC5B,MAAM,CAACgD,cAAc,EAAEP,aAAa,CAAC,EACrC,CAACO,cAAc,EAAEP,aAAa,CAChC,CAAC;EAED,IAAIM,kBAAkB,EAAE;IACtB,oBACElD,KAAA,CAAAqD,aAAA,CAACjD,IAAI,EAAAkD,QAAA;MAAC1B,GAAG,EAAEA,GAAI;MAACJ,KAAK,EAAEA,KAAM;MAACC,QAAQ,EAAEA;IAAS,GAAKE,KAAK,gBACzD3B,KAAA,CAAAqD,aAAA,CAAChD,UAAU,CAACD,IAAI;MAACoB,KAAK,EAAE4B;IAAe,GAAEhC,QAA0B,CAC/D,CAAC;EAEX;EAEA,oBACEpB,KAAA,CAAAqD,aAAA,CAAChD,UAAU,CAACD,IAAI,EAAAkD,QAAA;IACd1B,GAAG,EAAEA,GAAI;IACTH,QAAQ,EAAEA,QAAS;IACnBD,KAAK,EAAE4B;EAAe,GAClBzB,KAAK,GAERP,QACc,CAAC;AAEtB,CACF,CAAC;AAED,eAAeF,oBAAoB","ignoreList":[]}
@@ -0,0 +1,248 @@
1
+ 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); }
2
+ import React, { forwardRef, useCallback, useMemo } from "react";
3
+ import { findNodeHandle } from "react-native";
4
+ import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedStyle, useScrollViewOffset, useSharedValue } from "react-native-reanimated";
5
+ import { useFocusedInputHandler, useReanimatedFocusedInput, useWindowDimensions } from "../../hooks";
6
+ import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
7
+ import { debounce, scrollDistanceWithRespectToSnapPoints } from "./utils";
8
+ /*
9
+ * Everything begins from `onStart` handler. This handler is called every time,
10
+ * when keyboard changes its size or when focused `TextInput` was changed. In
11
+ * this handler we are calculating/memoizing values which later will be used
12
+ * during layout movement. For that we calculate:
13
+ * - layout of focused field (`layout`) - to understand whether there will be overlap
14
+ * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation
15
+ * - future keyboard height (`keyboardHeight`) - used in scroll interpolation
16
+ * - current scroll position (`scrollPosition`) - used to scroll from this point
17
+ *
18
+ * Once we've calculated all necessary variables - we can actually start to use them.
19
+ * It happens in `onMove` handler - this function simply calls `maybeScroll` with
20
+ * current keyboard frame height. This functions makes the smooth transition.
21
+ *
22
+ * When the transition has finished we go to `onEnd` handler. In this handler
23
+ * we verify, that the current field is not overlapped within a keyboard frame.
24
+ * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,
25
+ * however there could be some cases, when `onMove` is not called:
26
+ * - on iOS when TextInput was changed - keyboard transition is instant
27
+ * - on Android when TextInput was changed and keyboard size wasn't changed
28
+ * So `onEnd` handler handle the case, when `onMove` wasn't triggered.
29
+ *
30
+ * ====================================================================================================================+
31
+ * -----------------------------------------------------Flow chart-----------------------------------------------------+
32
+ * ====================================================================================================================+
33
+ *
34
+ * +============================+ +============================+ +==================================+
35
+ * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>
36
+ * + + + (run `onStart`) + + `onMove` is getting called +
37
+ * +============================+ +============================+ +==================================+
38
+ *
39
+ *
40
+ * +============================+ +============================+ +=====================================+
41
+ * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +
42
+ * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +
43
+ * +============================+ +============================+ +=====================================+
44
+ *
45
+ */
46
+ const KeyboardAwareScrollView = /*#__PURE__*/forwardRef(({
47
+ children,
48
+ onLayout,
49
+ bottomOffset = 0,
50
+ disableScrollOnKeyboardHide = false,
51
+ enabled = true,
52
+ extraKeyboardSpace = 0,
53
+ ...rest
54
+ }, ref) => {
55
+ const scrollViewAnimatedRef = useAnimatedRef();
56
+ const scrollViewTarget = useSharedValue(null);
57
+ const scrollPosition = useSharedValue(0);
58
+ const position = useScrollViewOffset(scrollViewAnimatedRef);
59
+ const currentKeyboardFrameHeight = useSharedValue(0);
60
+ const keyboardHeight = useSharedValue(0);
61
+ const keyboardWillAppear = useSharedValue(false);
62
+ const tag = useSharedValue(-1);
63
+ const initialKeyboardSize = useSharedValue(0);
64
+ const scrollBeforeKeyboardMovement = useSharedValue(0);
65
+ const {
66
+ input
67
+ } = useReanimatedFocusedInput();
68
+ const layout = useSharedValue(null);
69
+ const {
70
+ height
71
+ } = useWindowDimensions();
72
+ const onRef = useCallback(assignedRef => {
73
+ if (typeof ref === "function") {
74
+ ref(assignedRef);
75
+ } else if (ref) {
76
+ ref.current = assignedRef;
77
+ }
78
+ scrollViewAnimatedRef(assignedRef);
79
+ }, []);
80
+ const onScrollViewLayout = useCallback(e => {
81
+ scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);
82
+ onLayout === null || onLayout === void 0 || onLayout(e);
83
+ }, [onLayout]);
84
+
85
+ /**
86
+ * Function that will scroll a ScrollView as keyboard gets moving
87
+ */
88
+ const maybeScroll = useCallback((e, animated = false) => {
89
+ "worklet";
90
+
91
+ var _layout$value, _layout$value2, _layout$value3;
92
+ if (!enabled) {
93
+ return 0;
94
+ }
95
+
96
+ // input belongs to ScrollView
97
+ if (((_layout$value = layout.value) === null || _layout$value === void 0 ? void 0 : _layout$value.parentScrollViewTarget) !== scrollViewTarget.value) {
98
+ return 0;
99
+ }
100
+ const visibleRect = height - keyboardHeight.value;
101
+ const absoluteY = ((_layout$value2 = layout.value) === null || _layout$value2 === void 0 ? void 0 : _layout$value2.layout.absoluteY) || 0;
102
+ const inputHeight = ((_layout$value3 = layout.value) === null || _layout$value3 === void 0 ? void 0 : _layout$value3.layout.height) || 0;
103
+ const point = absoluteY + inputHeight;
104
+ if (visibleRect - point <= bottomOffset) {
105
+ const relativeScrollTo = keyboardHeight.value - (height - point) + bottomOffset;
106
+ const interpolatedScrollTo = interpolate(e, [initialKeyboardSize.value, keyboardHeight.value], [0, scrollDistanceWithRespectToSnapPoints(relativeScrollTo + scrollPosition.value, rest.snapToOffsets) - scrollPosition.value]);
107
+ const targetScrollY = Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
108
+ scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);
109
+ return interpolatedScrollTo;
110
+ }
111
+ if (absoluteY < 0) {
112
+ const positionOnScreen = visibleRect - inputHeight - bottomOffset;
113
+ const topOfScreen = scrollPosition.value + absoluteY;
114
+ scrollTo(scrollViewAnimatedRef, 0, topOfScreen - positionOnScreen, animated);
115
+ }
116
+ return 0;
117
+ }, [bottomOffset, enabled, height, rest.snapToOffsets]);
118
+ const scrollFromCurrentPosition = useCallback(customHeight => {
119
+ "worklet";
120
+
121
+ var _input$value;
122
+ const prevScrollPosition = scrollPosition.value;
123
+ const prevLayout = layout.value;
124
+ if (!((_input$value = input.value) !== null && _input$value !== void 0 && _input$value.layout)) {
125
+ return;
126
+ }
127
+
128
+ // eslint-disable-next-line react-compiler/react-compiler
129
+ layout.value = {
130
+ ...input.value,
131
+ layout: {
132
+ ...input.value.layout,
133
+ height: customHeight ?? input.value.layout.height
134
+ }
135
+ };
136
+ scrollPosition.value = position.value;
137
+ maybeScroll(keyboardHeight.value, true);
138
+ scrollPosition.value = prevScrollPosition;
139
+ layout.value = prevLayout;
140
+ }, [maybeScroll]);
141
+ const onChangeText = useCallback(() => {
142
+ "worklet";
143
+
144
+ // if typing a text caused layout shift, then we need to ignore this handler
145
+ // because this event will be handled in `useAnimatedReaction` below
146
+ var _layout$value4, _input$value2;
147
+ 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)) {
148
+ return;
149
+ }
150
+ scrollFromCurrentPosition();
151
+ }, [scrollFromCurrentPosition]);
152
+ const onSelectionChange = useCallback(e => {
153
+ "worklet";
154
+
155
+ if (e.selection.start.position !== e.selection.end.position) {
156
+ scrollFromCurrentPosition(e.selection.end.y);
157
+ }
158
+ }, [scrollFromCurrentPosition]);
159
+ const onChangeTextHandler = useMemo(() => debounce(onChangeText, 200), [onChangeText]);
160
+ useFocusedInputHandler({
161
+ onChangeText: onChangeTextHandler,
162
+ onSelectionChange: onSelectionChange
163
+ }, [onChangeTextHandler, onSelectionChange]);
164
+ useSmoothKeyboardHandler({
165
+ onStart: e => {
166
+ "worklet";
167
+
168
+ const keyboardWillChangeSize = keyboardHeight.value !== e.height && e.height > 0;
169
+ keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;
170
+ const keyboardWillHide = e.height === 0;
171
+ const focusWasChanged = tag.value !== e.target && e.target !== -1 || keyboardWillChangeSize;
172
+ if (keyboardWillChangeSize) {
173
+ initialKeyboardSize.value = keyboardHeight.value;
174
+ }
175
+ if (keyboardWillHide) {
176
+ // on back transition need to interpolate as [0, keyboardHeight]
177
+ initialKeyboardSize.value = 0;
178
+ scrollPosition.value = scrollBeforeKeyboardMovement.value;
179
+ }
180
+ if (keyboardWillAppear.value || keyboardWillChangeSize || focusWasChanged) {
181
+ // persist scroll value
182
+ scrollPosition.value = position.value;
183
+ // just persist height - later will be used in interpolation
184
+ keyboardHeight.value = e.height;
185
+ }
186
+
187
+ // focus was changed
188
+ if (focusWasChanged) {
189
+ tag.value = e.target;
190
+
191
+ // save position of focused text input when keyboard starts to move
192
+ layout.value = input.value;
193
+ // save current scroll position - when keyboard will hide we'll reuse
194
+ // this value to achieve smooth hide effect
195
+ scrollBeforeKeyboardMovement.value = position.value;
196
+ }
197
+ if (focusWasChanged && !keyboardWillAppear.value) {
198
+ // update position on scroll value, so `onEnd` handler
199
+ // will pick up correct values
200
+ position.value += maybeScroll(e.height, true);
201
+ }
202
+ },
203
+ onMove: e => {
204
+ "worklet";
205
+
206
+ const keyboardFrame = interpolate(e.height, [0, keyboardHeight.value], [0, keyboardHeight.value + extraKeyboardSpace]);
207
+ currentKeyboardFrameHeight.value = keyboardFrame;
208
+
209
+ // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens
210
+ if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {
211
+ maybeScroll(e.height);
212
+ }
213
+ },
214
+ onEnd: e => {
215
+ "worklet";
216
+
217
+ keyboardHeight.value = e.height;
218
+ scrollPosition.value = position.value;
219
+ }
220
+ }, [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace]);
221
+ useAnimatedReaction(() => input.value, (current, previous) => {
222
+ 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)) {
223
+ const prevLayout = layout.value;
224
+ layout.value = input.value;
225
+ scrollPosition.value += maybeScroll(keyboardHeight.value, true);
226
+ layout.value = prevLayout;
227
+ }
228
+ }, []);
229
+ const view = useAnimatedStyle(() => enabled ? {
230
+ // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
231
+ // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
232
+ // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
233
+ // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
234
+ // re-calculation on every animation frame and it helps to achieve smooth animation.
235
+ // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
236
+ paddingBottom: currentKeyboardFrameHeight.value + 1
237
+ } : {}, [enabled]);
238
+ return /*#__PURE__*/React.createElement(Reanimated.ScrollView, _extends({
239
+ ref: onRef
240
+ }, rest, {
241
+ onLayout: onScrollViewLayout,
242
+ scrollEventThrottle: 16
243
+ }), children, /*#__PURE__*/React.createElement(Reanimated.View, {
244
+ style: view
245
+ }));
246
+ });
247
+ export default KeyboardAwareScrollView;
248
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","forwardRef","useCallback","useMemo","findNodeHandle","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedStyle","useScrollViewOffset","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useWindowDimensions","useSmoothKeyboardHandler","debounce","scrollDistanceWithRespectToSnapPoints","KeyboardAwareScrollView","children","onLayout","bottomOffset","disableScrollOnKeyboardHide","enabled","extraKeyboardSpace","rest","ref","scrollViewAnimatedRef","scrollViewTarget","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","onRef","assignedRef","current","onScrollViewLayout","e","value","maybeScroll","animated","_layout$value","_layout$value2","_layout$value3","parentScrollViewTarget","visibleRect","absoluteY","inputHeight","point","relativeScrollTo","interpolatedScrollTo","snapToOffsets","targetScrollY","Math","max","positionOnScreen","topOfScreen","scrollFromCurrentPosition","customHeight","_input$value","prevScrollPosition","prevLayout","onChangeText","_layout$value4","_input$value2","onSelectionChange","selection","start","end","y","onChangeTextHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","target","onMove","keyboardFrame","onEnd","previous","view","paddingBottom","createElement","ScrollView","_extends","scrollEventThrottle","View","style"],"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,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAC/D,SAASC,cAAc,QAAQ,cAAc;AAC7C,OAAOC,UAAU,IACfC,WAAW,EACXC,QAAQ,EACRC,mBAAmB,EACnBC,cAAc,EACdC,gBAAgB,EAChBC,mBAAmB,EACnBC,cAAc,QACT,yBAAyB;AAEhC,SACEC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,QACd,aAAa;AAEpB,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,QAAQ,EAAEC,qCAAqC,QAAQ,SAAS;AAuBzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,gBAAGlB,UAAU,CAIxC,CACE;EACEmB,QAAQ;EACRC,QAAQ;EACRC,YAAY,GAAG,CAAC;EACh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AAI,GAAG9E,gBAAgB,CAC3B,MACEc,OAAO,GACH;IACA;IACA;IACA;IACA;IACA;IACA;IACAiE,aAAa,EAAEzD,0BAA0B,CAACc,KAAK,GAAG;EACpD,CAAC,GACC,CAAC,CAAC,EACR,CAACtB,OAAO,CACV,CAAC;EAED,oBACExB,KAAA,CAAA0F,aAAA,CAACrF,UAAU,CAACsF,UAAU,EAAAC,QAAA;IACpBjE,GAAG,EAAEc;EAAM,GACPf,IAAI;IACRL,QAAQ,EAAEuB,kBAAmB;IAC7BiD,mBAAmB,EAAE;EAAG,IAEvBzE,QAAQ,eACTpB,KAAA,CAAA0F,aAAA,CAACrF,UAAU,CAACyF,IAAI;IAACC,KAAK,EAAEP;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAED,eAAerE,uBAAuB","ignoreList":[]}
@@ -0,0 +1,103 @@
1
+ import { Platform } from "react-native";
2
+ import { Easing, useAnimatedReaction, useSharedValue, withTiming } from "react-native-reanimated";
3
+ import { useKeyboardHandler } from "../../hooks";
4
+ const IS_ANDROID_ELEVEN_OR_HIGHER = Platform.OS === "android" && Platform.Version >= 30;
5
+ // on these platforms keyboard transitions will be smooth
6
+ const IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS = IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === "ios" || Platform.OS === 'harmony';
7
+ // on Android Telegram is not using androidx.core values and uses custom interpolation
8
+ // duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39
9
+ // and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40
10
+ const TELEGRAM_ANDROID_TIMING_CONFIG = {
11
+ duration: 250,
12
+ easing: Easing.bezier(0.19919472913616398, 0.010644531250000006, 0.27920937042459737, 0.91025390625)
13
+ };
14
+
15
+ /**
16
+ * Hook that uses default transitions for iOS and Android > 11, and uses
17
+ * custom interpolation on Android < 11 to achieve more smooth animation
18
+ */
19
+ export const useSmoothKeyboardHandler = (handler, deps) => {
20
+ const target = useSharedValue(-1);
21
+ const height = useSharedValue(0);
22
+ const persistedHeight = useSharedValue(0);
23
+ const animatedKeyboardHeight = useSharedValue(0);
24
+ useAnimatedReaction(() => {
25
+ if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
26
+ return;
27
+ }
28
+ if (persistedHeight.value === 0) {
29
+ return;
30
+ }
31
+ const event = {
32
+ // it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`
33
+ duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
34
+ target: target.value,
35
+ height: animatedKeyboardHeight.value,
36
+ progress: animatedKeyboardHeight.value / persistedHeight.value
37
+ };
38
+ return event;
39
+ }, evt => {
40
+ var _handler$onMove;
41
+ if (!evt) {
42
+ return;
43
+ }
44
+ (_handler$onMove = handler.onMove) === null || _handler$onMove === void 0 || _handler$onMove.call(handler, evt);
45
+
46
+ // dispatch `onEnd`
47
+ if (evt.height === height.value) {
48
+ var _handler$onEnd;
49
+ (_handler$onEnd = handler.onEnd) === null || _handler$onEnd === void 0 || _handler$onEnd.call(handler, evt);
50
+ // eslint-disable-next-line react-compiler/react-compiler
51
+ persistedHeight.value = height.value;
52
+ }
53
+ },
54
+ // REA uses own version of `DependencyList` and it's not compatible with the same type from React
55
+ deps);
56
+ useKeyboardHandler({
57
+ onStart: e => {
58
+ "worklet";
59
+
60
+ // immediately dispatch onStart/onEnd events if onStart dispatched with the same height
61
+ // and don't wait for animation 250ms
62
+ var _handler$onStart2;
63
+ if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS && e.height === persistedHeight.value) {
64
+ var _handler$onStart, _handler$onEnd2;
65
+ (_handler$onStart = handler.onStart) === null || _handler$onStart === void 0 || _handler$onStart.call(handler, e);
66
+ (_handler$onEnd2 = handler.onEnd) === null || _handler$onEnd2 === void 0 || _handler$onEnd2.call(handler, e);
67
+ return;
68
+ }
69
+ target.value = e.target;
70
+ height.value = e.height;
71
+ if (e.height > 0) {
72
+ persistedHeight.value = e.height;
73
+ }
74
+ // if we are running on Android < 9, then we are using custom interpolation
75
+ // to achieve smoother animation and use `animatedKeyboardHeight` as animation
76
+ // driver
77
+ if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
78
+ animatedKeyboardHeight.value = withTiming(e.height, TELEGRAM_ANDROID_TIMING_CONFIG);
79
+ }
80
+ (_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 || _handler$onStart2.call(handler, {
81
+ ...e,
82
+ duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS ? e.duration : TELEGRAM_ANDROID_TIMING_CONFIG.duration
83
+ });
84
+ },
85
+ onMove: e => {
86
+ "worklet";
87
+
88
+ if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
89
+ var _handler$onMove2;
90
+ (_handler$onMove2 = handler.onMove) === null || _handler$onMove2 === void 0 || _handler$onMove2.call(handler, e);
91
+ }
92
+ },
93
+ onEnd: e => {
94
+ "worklet";
95
+
96
+ if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
97
+ var _handler$onEnd3;
98
+ (_handler$onEnd3 = handler.onEnd) === null || _handler$onEnd3 === void 0 || _handler$onEnd3.call(handler, e);
99
+ }
100
+ }
101
+ }, deps);
102
+ };
103
+ //# sourceMappingURL=useSmoothKeyboardHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Platform","Easing","useAnimatedReaction","useSharedValue","withTiming","useKeyboardHandler","IS_ANDROID_ELEVEN_OR_HIGHER","OS","Version","IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS","TELEGRAM_ANDROID_TIMING_CONFIG","duration","easing","bezier","useSmoothKeyboardHandler","handler","deps","target","height","persistedHeight","animatedKeyboardHeight","value","event","progress","evt","_handler$onMove","onMove","call","_handler$onEnd","onEnd","onStart","e","_handler$onStart2","_handler$onStart","_handler$onEnd2","_handler$onMove2","_handler$onEnd3"],"sources":["useSmoothKeyboardHandler.ts"],"sourcesContent":["import { Platform } from \"react-native\";\r\nimport {\r\n Easing,\r\n useAnimatedReaction,\r\n useSharedValue,\r\n withTiming,\r\n} from \"react-native-reanimated\";\r\n\r\nimport { useKeyboardHandler } from \"../../hooks\";\r\n\r\nconst IS_ANDROID_ELEVEN_OR_HIGHER =\r\n Platform.OS === \"android\" && Platform.Version >= 30;\r\n// on these platforms keyboard transitions will be smooth\r\nconst IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS =\r\n IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === \"ios\" || Platform.OS as string === 'harmony';\r\n// on Android Telegram is not using androidx.core values and uses custom interpolation\r\n// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39\r\n// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40\r\nconst TELEGRAM_ANDROID_TIMING_CONFIG = {\r\n duration: 250,\r\n easing: Easing.bezier(\r\n 0.19919472913616398,\r\n 0.010644531250000006,\r\n 0.27920937042459737,\r\n 0.91025390625,\r\n ),\r\n};\r\n\r\n/**\r\n * Hook that uses default transitions for iOS and Android > 11, and uses\r\n * custom interpolation on Android < 11 to achieve more smooth animation\r\n */\r\nexport const useSmoothKeyboardHandler: typeof useKeyboardHandler = (\r\n handler,\r\n deps,\r\n) => {\r\n const target = useSharedValue(-1);\r\n const height = useSharedValue(0);\r\n const persistedHeight = useSharedValue(0);\r\n const animatedKeyboardHeight = useSharedValue(0);\r\n\r\n useAnimatedReaction(\r\n () => {\r\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\r\n return;\r\n }\r\n if (persistedHeight.value === 0) {\r\n return;\r\n }\r\n const event = {\r\n // it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`\r\n duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,\r\n target: target.value,\r\n height: animatedKeyboardHeight.value,\r\n progress: animatedKeyboardHeight.value / persistedHeight.value,\r\n };\r\n return event;\r\n },\r\n (evt) => {\r\n if (!evt) {\r\n return;\r\n }\r\n handler.onMove?.(evt);\r\n\r\n // dispatch `onEnd`\r\n if (evt.height === height.value) {\r\n handler.onEnd?.(evt);\r\n // eslint-disable-next-line react-compiler/react-compiler\r\n persistedHeight.value = height.value;\r\n }\r\n },\r\n // REA uses own version of `DependencyList` and it's not compatible with the same type from React\r\n deps as unknown[],\r\n );\r\n\r\n useKeyboardHandler(\r\n {\r\n onStart: (e) => {\r\n \"worklet\";\r\n\r\n // immediately dispatch onStart/onEnd events if onStart dispatched with the same height\r\n // and don't wait for animation 250ms\r\n if (\r\n !IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS &&\r\n e.height === persistedHeight.value\r\n ) {\r\n handler.onStart?.(e);\r\n handler.onEnd?.(e);\r\n\r\n return;\r\n }\r\n\r\n target.value = e.target;\r\n height.value = e.height;\r\n\r\n if (e.height > 0) {\r\n persistedHeight.value = e.height;\r\n }\r\n // if we are running on Android < 9, then we are using custom interpolation\r\n // to achieve smoother animation and use `animatedKeyboardHeight` as animation\r\n // driver\r\n if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\r\n animatedKeyboardHeight.value = withTiming(\r\n e.height,\r\n TELEGRAM_ANDROID_TIMING_CONFIG,\r\n );\r\n }\r\n\r\n handler.onStart?.({\r\n ...e,\r\n duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS\r\n ? e.duration\r\n : TELEGRAM_ANDROID_TIMING_CONFIG.duration,\r\n });\r\n },\r\n onMove: (e) => {\r\n \"worklet\";\r\n\r\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\r\n handler.onMove?.(e);\r\n }\r\n },\r\n onEnd: (e) => {\r\n \"worklet\";\r\n\r\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\r\n handler.onEnd?.(e);\r\n }\r\n },\r\n },\r\n deps,\r\n );\r\n};\r\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SACEC,MAAM,EACNC,mBAAmB,EACnBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAEhC,SAASC,kBAAkB,QAAQ,aAAa;AAEhD,MAAMC,2BAA2B,GAC/BN,QAAQ,CAACO,EAAE,KAAK,SAAS,IAAIP,QAAQ,CAACQ,OAAO,IAAI,EAAE;AACrD;AACA,MAAMC,kCAAkC,GACtCH,2BAA2B,IAAIN,QAAQ,CAACO,EAAE,KAAK,KAAK,IAAIP,QAAQ,CAACO,EAAE,KAAe,SAAS;AAC7F;AACA;AACA;AACA,MAAMG,8BAA8B,GAAG;EACrCC,QAAQ,EAAE,GAAG;EACbC,MAAM,EAAEX,MAAM,CAACY,MAAM,CACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,aACF;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAmD,GAAGA,CACjEC,OAAO,EACPC,IAAI,KACD;EACH,MAAMC,MAAM,GAAGd,cAAc,CAAC,CAAC,CAAC,CAAC;EACjC,MAAMe,MAAM,GAAGf,cAAc,CAAC,CAAC,CAAC;EAChC,MAAMgB,eAAe,GAAGhB,cAAc,CAAC,CAAC,CAAC;EACzC,MAAMiB,sBAAsB,GAAGjB,cAAc,CAAC,CAAC,CAAC;EAEhDD,mBAAmB,CACjB,MAAM;IACJ,IAAIO,kCAAkC,EAAE;MACtC;IACF;IACA,IAAIU,eAAe,CAACE,KAAK,KAAK,CAAC,EAAE;MAC/B;IACF;IACA,MAA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GU,CAAC,CAACd,MAAM;MACvBC,MAAM,CAACG,KAAK,GAAGU,CAAC,CAACb,MAAM;MAEvB,IAAIa,CAAC,CAACb,MAAM,GAAG,CAAC,EAAE;QAChBC,eAAe,CAACE,KAAK,GAAGU,CAAC,CAACb,MAAM;MAClC;MACA;MACA;MACA;MACA,IAAI,CAACT,kCAAkC,EAAE;QACvCW,sBAAsB,CAACC,KAAK,GAAGjB,UAAU,CACvC2B,CAAC,CAACb,MAAM,EACRR,8BACF,CAAC;MACH;MAEA,CAAAsB,iBAAA,GAAAjB,OAAO,CAACe,OAAO,cAAAE,iBAAA,eAAfA,iBAAA,CAAAL,IAAA,CAAAZ,OAAO,EAAW;QAChB,GAAGgB,CAAC;QACJpB,QAAQ,EAAEF,kCAAkC,GACxCsB,CAAC,CAACpB,QAAQ,GACVD,8BAA8B,CAACC;MACrC,CAAC,CAAC;IACJ,CAAC;IACDe,MAAM,EAAGK,CAAC,IAAK;MACb,SAAS;;MAET,IAAItB,kCAAkC,EAAE;QAAA,IAAA0B,gBAAA;QACtC,CAAAA,gBAAA,GAAApB,OAAO,CAACW,MAAM,cAAAS,gBAAA,eAAdA,gBAAA,CAAAR,IAAA,CAAAZ,OAAO,EAAUgB,CAAC,CAAC;MACrB;IACF,CAAC;IACDF,KAAK,EAAGE,CAAC,IAAK;MACZ,SAAS;;MAET,IAAItB,kCAAkC,EAAE;QAAA,IAAA2B,eAAA;QACtC,CAAAA,eAAA,GAAArB,OAAO,CAACc,KAAK,cAAAO,eAAA,eAAbA,eAAA,CAAAT,IAAA,CAAAZ,OAAO,EAASgB,CAAC,CAAC;MACpB;IACF;EACF,CAAC,EACDf,IACF,CAAC;AACH,CAAC","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ export const debounce = (worklet, wait = 0) => {
2
+ "worklet";
3
+
4
+ const value = {
5
+ time: 0
6
+ };
7
+ return (...args) => {
8
+ "worklet";
9
+
10
+ const t = Date.now();
11
+ const now = t - value.time;
12
+ if (now < wait) {
13
+ value.time = t;
14
+ return;
15
+ }
16
+ value.time = t;
17
+ return worklet(...args);
18
+ };
19
+ };
20
+ export const scrollDistanceWithRespectToSnapPoints = (defaultScrollValue, snapPoints) => {
21
+ "worklet";
22
+
23
+ let snapPoint;
24
+ if (snapPoints) {
25
+ snapPoint = snapPoints.find(offset => offset >= defaultScrollValue);
26
+ }
27
+ return snapPoint ?? defaultScrollValue;
28
+ };
29
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["debounce","worklet","wait","value","time","args","t","Date","now","scrollDistanceWithRespectToSnapPoints","defaultScrollValue","snapPoints","snapPoint","find","offset"],"sources":["utils.ts"],"sourcesContent":["export const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(\r\n worklet: F,\r\n wait = 0,\r\n) => {\r\n \"worklet\";\r\n\r\n const value = {\r\n time: 0,\r\n };\r\n\r\n return (...args: Parameters<F>): ReturnType<F> | void => {\r\n \"worklet\";\r\n\r\n const t = Date.now();\r\n const now = t - value.time;\r\n\r\n if (now < wait) {\r\n value.time = t;\r\n return;\r\n }\r\n\r\n value.time = t;\r\n\r\n return worklet(...args);\r\n };\r\n};\r\n\r\nexport const scrollDistanceWithRespectToSnapPoints = (\r\n defaultScrollValue: number,\r\n snapPoints?: number[],\r\n) => {\r\n \"worklet\";\r\n\r\n let snapPoint: number | undefined;\r\n\r\n if (snapPoints) {\r\n snapPoint = snapPoints.find((offset) => offset >= defaultScrollValue);\r\n }\r\n\r\n return snapPoint ?? defaultScrollValue;\r\n};\r\n"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,GAAGA,CACtBC,OAAU,EACVC,IAAI,GAAG,CAAC,KACL;EACH,SAAS;;EAET,MAAMC,KAAK,GAAG;IACZC,IAAI,EAAE;EACR,CAAC;EAED,OAAO,CAAC,GAAGC,IAAmB,KAA2B;IACvD,SAAS;;IAET,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;IACpB,MAAMA,GAAG,GAAGF,CAAC,GAAGH,KAAK,CAACC,IAAI;IAE1B,IAAII,GAAG,GAAGN,IAAI,EAAE;MACdC,KAAK,CAACC,IAAI,GAAGE,CAAC;MACd;IACF;IAEAH,KAAK,CAACC,IAAI,GAAGE,CAAC;IAEd,OAAOL,OAAO,CAAC,GAAGI,IAAI,CAAC;EACzB,CAAC;AACH,CAAC;AAED,OAAO,MAAMI,qCAAqC,GAAGA,CACnDC,kBAA0B,EAC1BC,UAAqB,KAClB;EACH,SAAS;;EAET,IAAIC,SAA6B;EAEjC,IAAID,UAAU,EAAE;IACdC,SAAS,GAAGD,UAAU,CAACE,IAAI,CAAEC,MAAM,IAAKA,MAAM,IAAIJ,kBAAkB,CAAC;EACvE;EAEA,OAAOE,SAAS,IAAIF,kBAAkB;AACxC,CAAC","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ 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); }
2
+ import React, { forwardRef, useMemo } from "react";
3
+ import Reanimated, { interpolate, useAnimatedStyle } from "react-native-reanimated";
4
+ import { useReanimatedKeyboardAnimation } from "../../hooks";
5
+ const KeyboardStickyView = /*#__PURE__*/forwardRef(({
6
+ children,
7
+ offset: {
8
+ closed = 0,
9
+ opened = 0
10
+ } = {},
11
+ style,
12
+ ...props
13
+ }, ref) => {
14
+ const {
15
+ height,
16
+ progress
17
+ } = useReanimatedKeyboardAnimation();
18
+ const stickyViewStyle = useAnimatedStyle(() => {
19
+ const offset = interpolate(progress.value, [0, 1], [closed, opened]);
20
+ return {
21
+ transform: [{
22
+ translateY: height.value + offset
23
+ }]
24
+ };
25
+ }, [closed, opened]);
26
+ const styles = useMemo(() => [style, stickyViewStyle], [style, stickyViewStyle]);
27
+ return /*#__PURE__*/React.createElement(Reanimated.View, _extends({
28
+ ref: ref,
29
+ style: styles
30
+ }, props), children);
31
+ });
32
+ export default KeyboardStickyView;
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","forwardRef","useMemo","Reanimated","interpolate","useAnimatedStyle","useReanimatedKeyboardAnimation","KeyboardStickyView","children","offset","closed","opened","style","props","ref","height","progress","stickyViewStyle","value","transform","translateY","styles","createElement","View","_extends"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useMemo } from \"react\";\r\nimport Reanimated, {\r\n interpolate,\r\n useAnimatedStyle,\r\n} from \"react-native-reanimated\";\r\n\r\nimport { useReanimatedKeyboardAnimation } from \"../../hooks\";\r\n\r\nimport type { View, ViewProps } from \"react-native\";\r\n\r\nexport type KeyboardStickyViewProps = {\r\n /**\r\n * Specify additional offset to the view for given keyboard state.\r\n */\r\n offset?: {\r\n /**\r\n * Adds additional `translateY` when keyboard is close. By default `0`.\r\n */\r\n closed?: number;\r\n /**\r\n * Adds additional `translateY` when keyboard is open. By default `0`.\r\n */\r\n opened?: number;\r\n };\r\n} & ViewProps;\r\n\r\nconst KeyboardStickyView = forwardRef<\r\n View,\r\n React.PropsWithChildren<KeyboardStickyViewProps>\r\n>(\r\n (\r\n { children, offset: { closed = 0, opened = 0 } = {}, style, ...props },\r\n ref,\r\n ) => {\r\n const { height, progress } = useReanimatedKeyboardAnimation();\r\n const stickyViewStyle = useAnimatedStyle(() => {\r\n const offset = interpolate(progress.value, [0, 1], [closed, opened]);\r\n\r\n return {\r\n transform: [{ translateY: height.value + offset }],\r\n };\r\n }, [closed, opened]);\r\n\r\n const styles = useMemo(\r\n () => [style, stickyViewStyle],\r\n [style, stickyViewStyle],\r\n );\r\n\r\n return (\r\n <Reanimated.View ref={ref} style={styles} {...props}>\r\n {children}\r\n </Reanimated.View>\r\n );\r\n },\r\n);\r\n\r\nexport default KeyboardStickyView;\r\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAClD,OAAOC,UAAU,IACfC,WAAW,EACXC,gBAAgB,QACX,yBAAyB;AAEhC,SAASC,8BAA8B,QAAQ,aAAa;AAoB5D,MAAMC,kBAAkB,gBAAGN,UAAU,CAInC,CACE;EAAEO,QAAQ;EAAEC,MAAM,EAAE;IAAEC,MAAM,GAAG,CAAC;IAAEC,MAAM,GAAG;EAAE,CAAC,GAAG,CAAC,CAAC;EAAEC,KAAK;EAAE,GAAGC;AAAM,CAAC,EACtEC,GAAG,KACA;EACH,MAAM;IAAEC,MAAM;IAAEC;EAAS,CAAC,GAAGV,8BAA8B,CAAC,CAAC;EAC7D,MAAMW,eAAe,GAAGZ,gBAAgB,CAAC,MAAM;IAC7C,MAAMI,MAAM,GAAGL,WAAW,CAACY,QAAQ,CAACE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAACR,MAAM,EAAEC,MAAM,CAAC,CAAC;IAEpE,OAAO;MACLQ,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEL,MAAM,CAACG,KAAK,GAAGT;MAAO,CAAC;IACnD,CAAC;EACH,CAAC,EAAE,CAACC,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,MAAMU,MAAM,GAAGnB,OAAO,CACpB,MAAM,CAACU,KAAK,EAAEK,eAAe,CAAC,EAC9B,CAACL,KAAK,EAAEK,eAAe,CACzB,CAAC;EAED,oBACEjB,KAAA,CAAAsB,aAAA,CAACnB,UAAU,CAACoB,IAAI,EAAAC,QAAA;IAACV,GAAG,EAAEA,GAAI;IAACF,KAAK,EAAES;EAAO,GAAKR,KAAK,GAChDL,QACc,CAAC;AAEtB,CACF,CAAC;AAED,eAAeD,kBAAkB","ignoreList":[]}