@react-native-ohos/react-native-keyboard-controller 1.16.6-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) 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 +7 -0
  6. package/harmony/keyboard_controller/ResourceTable.txt +1 -0
  7. package/harmony/keyboard_controller/build-profile.json5 +31 -0
  8. package/harmony/keyboard_controller/consumer-rules.txt +0 -0
  9. package/harmony/keyboard_controller/hvigorfile.ts +6 -0
  10. package/harmony/keyboard_controller/obfuscation-rules.txt +18 -0
  11. package/harmony/keyboard_controller/oh-package.json5 +11 -0
  12. package/harmony/keyboard_controller/src/main/cpp/CMakeLists.txt +7 -0
  13. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.cpp +96 -0
  14. package/harmony/keyboard_controller/src/main/cpp/EventEmitters.h +90 -0
  15. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentDescriptor.h +73 -0
  16. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.cpp +172 -0
  17. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewComponentInstance.h +76 -0
  18. package/harmony/keyboard_controller/src/main/cpp/KeyboardControllerViewJSIBinder.h +44 -0
  19. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentDescriptor.h +58 -0
  20. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.cpp +87 -0
  21. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaComponentInstance.h +62 -0
  22. package/harmony/keyboard_controller/src/main/cpp/KeyboardGestureAreaJSIBinder.h +39 -0
  23. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.cpp +25 -0
  24. package/harmony/keyboard_controller/src/main/cpp/RNKeyboardController.h +27 -0
  25. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.cpp +24 -0
  26. package/harmony/keyboard_controller/src/main/cpp/RNStatusBarManagerCompat.h +28 -0
  27. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.cpp +43 -0
  28. package/harmony/keyboard_controller/src/main/cpp/keyboardControllerPackage.h +56 -0
  29. package/harmony/keyboard_controller/src/main/ets/Logger.ts +46 -0
  30. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerPackage.ts +45 -0
  31. package/harmony/keyboard_controller/src/main/ets/RNKeyboardControllerTurboModule.ts +238 -0
  32. package/harmony/keyboard_controller/src/main/ets/RNStatusBarManagerCompatTurboModule.ts +98 -0
  33. package/harmony/keyboard_controller/src/main/ets/Type.ts +41 -0
  34. package/harmony/keyboard_controller/src/main/module.json5 +11 -0
  35. package/harmony/keyboard_controller/src/main/resources/base/element/string.json +8 -0
  36. package/harmony/keyboard_controller/src/main/resources/en_US/element/string.json +8 -0
  37. package/harmony/keyboard_controller/src/main/resources/zh_CN/element/string.json +8 -0
  38. package/harmony/keyboard_controller/ts.ts +9 -0
  39. package/harmony/keyboard_controller.har +0 -0
  40. package/lib/commonjs/animated.js +176 -0
  41. package/lib/commonjs/animated.js.map +1 -0
  42. package/lib/commonjs/bindings.js +39 -0
  43. package/lib/commonjs/bindings.js.map +1 -0
  44. package/lib/commonjs/bindings.native.js +39 -0
  45. package/lib/commonjs/bindings.native.js.map +1 -0
  46. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +126 -0
  47. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -0
  48. package/lib/commonjs/components/KeyboardAvoidingView/index.js +120 -0
  49. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -0
  50. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +262 -0
  51. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -0
  52. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +110 -0
  53. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  54. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +37 -0
  55. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -0
  56. package/lib/commonjs/components/KeyboardStickyView/index.js +41 -0
  57. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -0
  58. package/lib/commonjs/components/KeyboardToolbar/Arrow.js +76 -0
  59. package/lib/commonjs/components/KeyboardToolbar/Arrow.js.map +1 -0
  60. package/lib/commonjs/components/KeyboardToolbar/Button.js +70 -0
  61. package/lib/commonjs/components/KeyboardToolbar/Button.js.map +1 -0
  62. package/lib/commonjs/components/KeyboardToolbar/colors.js +21 -0
  63. package/lib/commonjs/components/KeyboardToolbar/colors.js.map +1 -0
  64. package/lib/commonjs/components/KeyboardToolbar/colors.native.js +40 -0
  65. package/lib/commonjs/components/KeyboardToolbar/colors.native.js.map +1 -0
  66. package/lib/commonjs/components/KeyboardToolbar/index.js +161 -0
  67. package/lib/commonjs/components/KeyboardToolbar/index.js.map +1 -0
  68. package/lib/commonjs/components/KeyboardToolbar/types.js +6 -0
  69. package/lib/commonjs/components/KeyboardToolbar/types.js.map +1 -0
  70. package/lib/commonjs/components/hooks/useColorScheme.js +10 -0
  71. package/lib/commonjs/components/hooks/useColorScheme.js.map +1 -0
  72. package/lib/commonjs/components/index.js +42 -0
  73. package/lib/commonjs/components/index.js.map +1 -0
  74. package/lib/commonjs/constants.js +27 -0
  75. package/lib/commonjs/constants.js.map +1 -0
  76. package/lib/commonjs/context.js +45 -0
  77. package/lib/commonjs/context.js.map +1 -0
  78. package/lib/commonjs/hooks/index.js +104 -0
  79. package/lib/commonjs/hooks/index.js.map +1 -0
  80. package/lib/commonjs/hooks/useWindowDimensions/index.android.js +34 -0
  81. package/lib/commonjs/hooks/useWindowDimensions/index.android.js.map +1 -0
  82. package/lib/commonjs/hooks/useWindowDimensions/index.js +13 -0
  83. package/lib/commonjs/hooks/useWindowDimensions/index.js.map +1 -0
  84. package/lib/commonjs/index.js +136 -0
  85. package/lib/commonjs/index.js.map +1 -0
  86. package/lib/commonjs/internal.js +73 -0
  87. package/lib/commonjs/internal.js.map +1 -0
  88. package/lib/commonjs/module.js +47 -0
  89. package/lib/commonjs/module.js.map +1 -0
  90. package/lib/commonjs/monkey-patch.android.js +57 -0
  91. package/lib/commonjs/monkey-patch.android.js.map +1 -0
  92. package/lib/commonjs/monkey-patch.js +11 -0
  93. package/lib/commonjs/monkey-patch.js.map +1 -0
  94. package/lib/commonjs/reanimated.js +12 -0
  95. package/lib/commonjs/reanimated.js.map +1 -0
  96. package/lib/commonjs/reanimated.native.js +88 -0
  97. package/lib/commonjs/reanimated.native.js.map +1 -0
  98. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +10 -0
  99. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  100. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +12 -0
  101. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  102. package/lib/commonjs/specs/NativeKeyboardController.js +9 -0
  103. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -0
  104. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +9 -0
  105. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -0
  106. package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js +10 -0
  107. package/lib/commonjs/specs/OverKeyboardViewNativeComponent.js.map +1 -0
  108. package/lib/commonjs/types.js +6 -0
  109. package/lib/commonjs/types.js.map +1 -0
  110. package/lib/commonjs/utils.js +9 -0
  111. package/lib/commonjs/utils.js.map +1 -0
  112. package/lib/commonjs/views/OverKeyboardView/index.js +42 -0
  113. package/lib/commonjs/views/OverKeyboardView/index.js.map +1 -0
  114. package/lib/commonjs/views/index.js +14 -0
  115. package/lib/commonjs/views/index.js.map +1 -0
  116. package/lib/module/animated.js +168 -0
  117. package/lib/module/animated.js.map +1 -0
  118. package/lib/module/bindings.js +33 -0
  119. package/lib/module/bindings.js.map +1 -0
  120. package/lib/module/bindings.native.js +33 -0
  121. package/lib/module/bindings.native.js.map +1 -0
  122. package/lib/module/components/KeyboardAvoidingView/hooks.js +118 -0
  123. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -0
  124. package/lib/module/components/KeyboardAvoidingView/index.js +113 -0
  125. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -0
  126. package/lib/module/components/KeyboardAwareScrollView/index.js +255 -0
  127. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -0
  128. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +103 -0
  129. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -0
  130. package/lib/module/components/KeyboardAwareScrollView/utils.js +29 -0
  131. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -0
  132. package/lib/module/components/KeyboardStickyView/index.js +34 -0
  133. package/lib/module/components/KeyboardStickyView/index.js.map +1 -0
  134. package/lib/module/components/KeyboardToolbar/Arrow.js +68 -0
  135. package/lib/module/components/KeyboardToolbar/Arrow.js.map +1 -0
  136. package/lib/module/components/KeyboardToolbar/Button.js +62 -0
  137. package/lib/module/components/KeyboardToolbar/Button.js.map +1 -0
  138. package/lib/module/components/KeyboardToolbar/colors.js +15 -0
  139. package/lib/module/components/KeyboardToolbar/colors.js.map +1 -0
  140. package/lib/module/components/KeyboardToolbar/colors.native.js +34 -0
  141. package/lib/module/components/KeyboardToolbar/colors.native.js.map +1 -0
  142. package/lib/module/components/KeyboardToolbar/index.js +149 -0
  143. package/lib/module/components/KeyboardToolbar/index.js.map +1 -0
  144. package/lib/module/components/KeyboardToolbar/types.js +2 -0
  145. package/lib/module/components/KeyboardToolbar/types.js.map +1 -0
  146. package/lib/module/components/hooks/useColorScheme.js +4 -0
  147. package/lib/module/components/hooks/useColorScheme.js.map +1 -0
  148. package/lib/module/components/index.js +5 -0
  149. package/lib/module/components/index.js.map +1 -0
  150. package/lib/module/constants.js +21 -0
  151. package/lib/module/constants.js.map +1 -0
  152. package/lib/module/context.js +38 -0
  153. package/lib/module/context.js.map +1 -0
  154. package/lib/module/hooks/index.js +68 -0
  155. package/lib/module/hooks/index.js.map +1 -0
  156. package/lib/module/hooks/useWindowDimensions/index.android.js +27 -0
  157. package/lib/module/hooks/useWindowDimensions/index.android.js.map +1 -0
  158. package/lib/module/hooks/useWindowDimensions/index.js +2 -0
  159. package/lib/module/hooks/useWindowDimensions/index.js.map +1 -0
  160. package/lib/module/index.js +12 -0
  161. package/lib/module/index.js.map +1 -0
  162. package/lib/module/internal.js +66 -0
  163. package/lib/module/internal.js.map +1 -0
  164. package/lib/module/module.js +41 -0
  165. package/lib/module/module.js.map +1 -0
  166. package/lib/module/monkey-patch.android.js +47 -0
  167. package/lib/module/monkey-patch.android.js.map +1 -0
  168. package/lib/module/monkey-patch.js +5 -0
  169. package/lib/module/monkey-patch.js.map +1 -0
  170. package/lib/module/reanimated.js +6 -0
  171. package/lib/module/reanimated.js.map +1 -0
  172. package/lib/module/reanimated.native.js +78 -0
  173. package/lib/module/reanimated.native.js.map +1 -0
  174. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +3 -0
  175. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -0
  176. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +5 -0
  177. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -0
  178. package/lib/module/specs/NativeKeyboardController.js +3 -0
  179. package/lib/module/specs/NativeKeyboardController.js.map +1 -0
  180. package/lib/module/specs/NativeStatusBarManagerCompat.js +3 -0
  181. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -0
  182. package/lib/module/specs/OverKeyboardViewNativeComponent.js +3 -0
  183. package/lib/module/specs/OverKeyboardViewNativeComponent.js.map +1 -0
  184. package/lib/module/types.js +2 -0
  185. package/lib/module/types.js.map +1 -0
  186. package/lib/module/utils.js +2 -0
  187. package/lib/module/utils.js.map +1 -0
  188. package/lib/module/views/OverKeyboardView/index.js +35 -0
  189. package/lib/module/views/OverKeyboardView/index.js.map +1 -0
  190. package/lib/module/views/index.js +2 -0
  191. package/lib/module/views/index.js.map +1 -0
  192. package/lib/typescript/animated.d.ts +39 -0
  193. package/lib/typescript/bindings.d.ts +12 -0
  194. package/lib/typescript/bindings.native.d.ts +12 -0
  195. package/lib/typescript/components/KeyboardAvoidingView/hooks.d.ts +10 -0
  196. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +40 -0
  197. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +29 -0
  198. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +6 -0
  199. package/lib/typescript/components/KeyboardAwareScrollView/utils.d.ts +2 -0
  200. package/lib/typescript/components/KeyboardStickyView/index.d.ts +39 -0
  201. package/lib/typescript/components/KeyboardToolbar/Arrow.d.ts +9 -0
  202. package/lib/typescript/components/KeyboardToolbar/Button.d.ts +16 -0
  203. package/lib/typescript/components/KeyboardToolbar/colors.d.ts +2 -0
  204. package/lib/typescript/components/KeyboardToolbar/colors.native.d.ts +2 -0
  205. package/lib/typescript/components/KeyboardToolbar/index.d.ts +52 -0
  206. package/lib/typescript/components/KeyboardToolbar/types.d.ts +18 -0
  207. package/lib/typescript/components/hooks/useColorScheme.d.ts +2 -0
  208. package/lib/typescript/components/index.d.ts +8 -0
  209. package/lib/typescript/constants.d.ts +16 -0
  210. package/lib/typescript/context.d.ts +23 -0
  211. package/lib/typescript/hooks/index.d.ts +17 -0
  212. package/lib/typescript/hooks/useWindowDimensions/index.android.d.ts +2 -0
  213. package/lib/typescript/hooks/useWindowDimensions/index.d.ts +1 -0
  214. package/lib/typescript/index.d.ts +10 -0
  215. package/lib/typescript/internal.d.ts +30 -0
  216. package/lib/typescript/module.d.ts +2 -0
  217. package/lib/typescript/monkey-patch.android.d.ts +2 -0
  218. package/lib/typescript/monkey-patch.d.ts +2 -0
  219. package/lib/typescript/reanimated.d.ts +5 -0
  220. package/lib/typescript/reanimated.native.d.ts +7 -0
  221. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +54 -0
  222. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +12 -0
  223. package/lib/typescript/specs/NativeKeyboardController.d.ts +12 -0
  224. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +10 -0
  225. package/lib/typescript/specs/OverKeyboardViewNativeComponent.d.ts +7 -0
  226. package/lib/typescript/types.d.ts +161 -0
  227. package/lib/typescript/utils.d.ts +1 -0
  228. package/lib/typescript/views/OverKeyboardView/index.d.ts +5 -0
  229. package/lib/typescript/views/index.d.ts +1 -0
  230. package/package.json +173 -0
  231. package/react-native-keyboard-controller.podspec +61 -0
  232. package/src/animated.tsx +256 -0
  233. package/src/bindings.native.ts +62 -0
  234. package/src/bindings.ts +42 -0
  235. package/src/components/KeyboardAvoidingView/hooks.ts +123 -0
  236. package/src/components/KeyboardAvoidingView/index.tsx +188 -0
  237. package/src/components/KeyboardAwareScrollView/index.tsx +389 -0
  238. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +133 -0
  239. package/src/components/KeyboardAwareScrollView/utils.ts +41 -0
  240. package/src/components/KeyboardStickyView/index.tsx +66 -0
  241. package/src/components/KeyboardToolbar/Arrow.tsx +80 -0
  242. package/src/components/KeyboardToolbar/Button.tsx +98 -0
  243. package/src/components/KeyboardToolbar/colors.native.ts +37 -0
  244. package/src/components/KeyboardToolbar/colors.ts +16 -0
  245. package/src/components/KeyboardToolbar/index.tsx +223 -0
  246. package/src/components/KeyboardToolbar/types.ts +40 -0
  247. package/src/components/hooks/useColorScheme.ts +5 -0
  248. package/src/components/index.ts +11 -0
  249. package/src/constants.ts +19 -0
  250. package/src/context.ts +68 -0
  251. package/src/hooks/index.ts +90 -0
  252. package/src/hooks/useWindowDimensions/index.android.ts +38 -0
  253. package/src/hooks/useWindowDimensions/index.ts +1 -0
  254. package/src/index.ts +23 -0
  255. package/src/internal.ts +84 -0
  256. package/src/module.ts +52 -0
  257. package/src/monkey-patch.android.ts +44 -0
  258. package/src/monkey-patch.ts +4 -0
  259. package/src/reanimated.native.ts +132 -0
  260. package/src/reanimated.ts +29 -0
  261. package/src/specs/KeyboardControllerViewNativeComponent.ts +71 -0
  262. package/src/specs/KeyboardGestureAreaNativeComponent.ts +20 -0
  263. package/src/specs/NativeKeyboardController.ts +19 -0
  264. package/src/specs/NativeStatusBarManagerCompat.ts +14 -0
  265. package/src/specs/OverKeyboardViewNativeComponent.ts +12 -0
  266. package/src/types.ts +243 -0
  267. package/src/utils.ts +1 -0
  268. package/src/views/OverKeyboardView/index.tsx +43 -0
  269. package/src/views/index.ts +1 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WindowDimensionsEvents = exports.RCTOverKeyboardView = exports.KeyboardGestureArea = exports.KeyboardEvents = exports.KeyboardControllerView = exports.KeyboardControllerNative = exports.FocusedInputEvents = void 0;
7
+ var _reactNative = require("react-native");
8
+ const NOOP = () => {};
9
+ const KeyboardControllerNative = exports.KeyboardControllerNative = {
10
+ setDefaultMode: NOOP,
11
+ setInputMode: NOOP,
12
+ dismiss: NOOP,
13
+ setFocusTo: NOOP,
14
+ addListener: NOOP,
15
+ removeListeners: NOOP
16
+ };
17
+ const KeyboardEvents = exports.KeyboardEvents = {
18
+ addListener: () => ({
19
+ remove: NOOP
20
+ })
21
+ };
22
+ /**
23
+ * This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
24
+ * Use it with cautious.
25
+ */
26
+ const FocusedInputEvents = exports.FocusedInputEvents = {
27
+ addListener: () => ({
28
+ remove: NOOP
29
+ })
30
+ };
31
+ const WindowDimensionsEvents = exports.WindowDimensionsEvents = {
32
+ addListener: () => ({
33
+ remove: NOOP
34
+ })
35
+ };
36
+ const KeyboardControllerView = exports.KeyboardControllerView = _reactNative.View;
37
+ const KeyboardGestureArea = exports.KeyboardGestureArea = _reactNative.View;
38
+ const RCTOverKeyboardView = exports.RCTOverKeyboardView = _reactNative.View;
39
+ //# sourceMappingURL=bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","NOOP","KeyboardControllerNative","exports","setDefaultMode","setInputMode","dismiss","setFocusTo","addListener","removeListeners","KeyboardEvents","remove","FocusedInputEvents","WindowDimensionsEvents","KeyboardControllerView","View","KeyboardGestureArea","RCTOverKeyboardView"],"sources":["bindings.ts"],"sourcesContent":["import { View } from \"react-native\";\n\nimport type {\n FocusedInputEventsModule,\n KeyboardControllerNativeModule,\n KeyboardControllerProps,\n KeyboardEventsModule,\n KeyboardGestureAreaProps,\n OverKeyboardViewProps,\n WindowDimensionsEventsModule,\n} from \"./types\";\nimport type { EmitterSubscription } from \"react-native\";\n\nconst NOOP = () => {};\n\nexport const KeyboardControllerNative: KeyboardControllerNativeModule = {\n setDefaultMode: NOOP,\n setInputMode: NOOP,\n dismiss: NOOP,\n setFocusTo: NOOP,\n addListener: NOOP,\n removeListeners: NOOP,\n};\nexport const KeyboardEvents: KeyboardEventsModule = {\n addListener: () => ({ remove: NOOP } as EmitterSubscription),\n};\n/**\n * This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.\n * Use it with cautious.\n */\nexport const FocusedInputEvents: FocusedInputEventsModule = {\n addListener: () => ({ remove: NOOP } as EmitterSubscription),\n};\nexport const WindowDimensionsEvents: WindowDimensionsEventsModule = {\n addListener: () => ({ remove: NOOP } as EmitterSubscription),\n};\nexport const KeyboardControllerView =\n View as unknown as React.FC<KeyboardControllerProps>;\nexport const KeyboardGestureArea =\n View as unknown as React.FC<KeyboardGestureAreaProps>;\nexport const RCTOverKeyboardView =\n View as unknown as React.FC<OverKeyboardViewProps>;\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAaA,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAEd,MAAMC,wBAAwD,GAAAC,OAAA,CAAAD,wBAAA,GAAG;EACtEE,cAAc,EAAEH,IAAI;EACpBI,YAAY,EAAEJ,IAAI;EAClBK,OAAO,EAAEL,IAAI;EACbM,UAAU,EAAEN,IAAI;EAChBO,WAAW,EAAEP,IAAI;EACjBQ,eAAe,EAAER;AACnB,CAAC;AACM,MAAMS,cAAoC,GAAAP,OAAA,CAAAO,cAAA,GAAG;EAClDF,WAAW,EAAEA,CAAA,MAAO;IAAEG,MAAM,EAAEV;EAAK,CAAC;AACtC,CAAC;AACD;AACA;AACA;AACA;AACO,MAAMW,kBAA4C,GAAAT,OAAA,CAAAS,kBAAA,GAAG;EAC1DJ,WAAW,EAAEA,CAAA,MAAO;IAAEG,MAAM,EAAEV;EAAK,CAAC;AACtC,CAAC;AACM,MAAMY,sBAAoD,GAAAV,OAAA,CAAAU,sBAAA,GAAG;EAClEL,WAAW,EAAEA,CAAA,MAAO;IAAEG,MAAM,EAAEV;EAAK,CAAC;AACtC,CAAC;AACM,MAAMa,sBAAsB,GAAAX,OAAA,CAAAW,sBAAA,GACjCC,iBAAoD;AAC/C,MAAMC,mBAAmB,GAAAb,OAAA,CAAAa,mBAAA,GAC9BD,iBAAqD;AAChD,MAAME,mBAAmB,GAAAd,OAAA,CAAAc,mBAAA,GAC9BF,iBAAkD","ignoreList":[]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WindowDimensionsEvents = exports.RCTOverKeyboardView = exports.KeyboardGestureArea = exports.KeyboardEvents = exports.KeyboardControllerView = exports.KeyboardControllerNative = exports.FocusedInputEvents = void 0;
7
+ var _reactNative = require("react-native");
8
+ const LINKING_ERROR = `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
9
+ ios: "- You have run 'pod install'\n",
10
+ default: ""
11
+ }) + "- You rebuilt the app after installing the package\n" + "- You are not using Expo Go\n";
12
+ const RCTKeyboardController = require("./specs/NativeKeyboardController").default;
13
+ const KeyboardControllerNative = exports.KeyboardControllerNative = RCTKeyboardController ? RCTKeyboardController : new Proxy({}, {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ }
17
+ });
18
+ const KEYBOARD_CONTROLLER_NAMESPACE = "KeyboardController::";
19
+ const eventEmitter = new _reactNative.NativeEventEmitter(KeyboardControllerNative);
20
+ const KeyboardEvents = exports.KeyboardEvents = {
21
+ addListener: (name, cb) => eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb)
22
+ };
23
+
24
+ /**
25
+ * This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.
26
+ * Use it with cautious.
27
+ */
28
+ const FocusedInputEvents = exports.FocusedInputEvents = {
29
+ addListener: (name, cb) => eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb)
30
+ };
31
+ const WindowDimensionsEvents = exports.WindowDimensionsEvents = {
32
+ addListener: (name, cb) => eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb)
33
+ };
34
+ const KeyboardControllerView = exports.KeyboardControllerView = require("./specs/KeyboardControllerViewNativeComponent").default;
35
+ const KeyboardGestureArea = exports.KeyboardGestureArea = _reactNative.Platform.OS === "android" && _reactNative.Platform.Version >= 30 || _reactNative.Platform.OS === "ios" ? require("./specs/KeyboardGestureAreaNativeComponent").default : ({
36
+ children
37
+ }) => children;
38
+ const RCTOverKeyboardView = exports.RCTOverKeyboardView = require("./specs/OverKeyboardViewNativeComponent").default;
39
+ //# sourceMappingURL=bindings.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","RCTKeyboardController","KeyboardControllerNative","exports","Proxy","get","Error","KEYBOARD_CONTROLLER_NAMESPACE","eventEmitter","NativeEventEmitter","KeyboardEvents","addListener","name","cb","FocusedInputEvents","WindowDimensionsEvents","KeyboardControllerView","KeyboardGestureArea","OS","Version","children","RCTOverKeyboardView"],"sources":["bindings.native.ts"],"sourcesContent":["import { NativeEventEmitter, Platform } from \"react-native\";\n\nimport type {\n FocusedInputEventsModule,\n KeyboardControllerNativeModule,\n KeyboardControllerProps,\n KeyboardEventsModule,\n KeyboardGestureAreaProps,\n OverKeyboardViewProps,\n WindowDimensionsEventsModule,\n} from \"./types\";\n\nconst LINKING_ERROR =\n `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: \"\" }) +\n \"- You rebuilt the app after installing the package\\n\" +\n \"- You are not using Expo Go\\n\";\n\nconst RCTKeyboardController =\n require(\"./specs/NativeKeyboardController\").default;\n\nexport const KeyboardControllerNative = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n },\n )\n) as KeyboardControllerNativeModule;\n\nconst KEYBOARD_CONTROLLER_NAMESPACE = \"KeyboardController::\";\nconst eventEmitter = new NativeEventEmitter(KeyboardControllerNative);\n\nexport const KeyboardEvents: KeyboardEventsModule = {\n addListener: (name, cb) =>\n eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),\n};\n\n/**\n * This API is not documented, it's for internal usage only (for now), and is a subject to potential breaking changes in future.\n * Use it with cautious.\n */\nexport const FocusedInputEvents: FocusedInputEventsModule = {\n addListener: (name, cb) =>\n eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),\n};\nexport const WindowDimensionsEvents: WindowDimensionsEventsModule = {\n addListener: (name, cb) =>\n eventEmitter.addListener(KEYBOARD_CONTROLLER_NAMESPACE + name, cb),\n};\nexport const KeyboardControllerView: React.FC<KeyboardControllerProps> =\n require(\"./specs/KeyboardControllerViewNativeComponent\").default;\nexport const KeyboardGestureArea: React.FC<KeyboardGestureAreaProps> =\n (Platform.OS === \"android\" && Platform.Version >= 30) || Platform.OS === \"ios\"\n ? require(\"./specs/KeyboardGestureAreaNativeComponent\").default\n : ({ children }: KeyboardGestureAreaProps) => children;\nexport const RCTOverKeyboardView: React.FC<OverKeyboardViewProps> =\n require(\"./specs/OverKeyboardViewNativeComponent\").default;\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAYA,MAAMC,aAAa,GACjB,2FAA2F,GAC3FC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,qBAAqB,GACzBN,OAAO,CAAC,kCAAkC,CAAC,CAACK,OAAO;AAE9C,MAAME,wBAAwB,GAAAC,OAAA,CAAAD,wBAAA,GACnCD,qBAAqB,GACjBA,qBAAqB,GACrB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;EAChC;AACF,CACF,CAC6B;AAEnC,MAAMW,6BAA6B,GAAG,sBAAsB;AAC5D,MAAMC,YAAY,GAAG,IAAIC,+BAAkB,CAACP,wBAAwB,CAAC;AAE9D,MAAMQ,cAAoC,GAAAP,OAAA,CAAAO,cAAA,GAAG;EAClDC,WAAW,EAAEA,CAACC,IAAI,EAAEC,EAAE,KACpBL,YAAY,CAACG,WAAW,CAACJ,6BAA6B,GAAGK,IAAI,EAAEC,EAAE;AACrE,CAAC;;AAED;AACA;AACA;AACA;AACO,MAAMC,kBAA4C,GAAAX,OAAA,CAAAW,kBAAA,GAAG;EAC1DH,WAAW,EAAEA,CAACC,IAAI,EAAEC,EAAE,KACpBL,YAAY,CAACG,WAAW,CAACJ,6BAA6B,GAAGK,IAAI,EAAEC,EAAE;AACrE,CAAC;AACM,MAAME,sBAAoD,GAAAZ,OAAA,CAAAY,sBAAA,GAAG;EAClEJ,WAAW,EAAEA,CAACC,IAAI,EAAEC,EAAE,KACpBL,YAAY,CAACG,WAAW,CAACJ,6BAA6B,GAAGK,IAAI,EAAEC,EAAE;AACrE,CAAC;AACM,MAAMG,sBAAyD,GAAAb,OAAA,CAAAa,sBAAA,GACpErB,OAAO,CAAC,+CAA+C,CAAC,CAACK,OAAO;AAC3D,MAAMiB,mBAAuD,GAAAd,OAAA,CAAAc,mBAAA,GACjEpB,qBAAQ,CAACqB,EAAE,KAAK,SAAS,IAAIrB,qBAAQ,CAACsB,OAAO,IAAI,EAAE,IAAKtB,qBAAQ,CAACqB,EAAE,KAAK,KAAK,GAC1EvB,OAAO,CAAC,4CAA4C,CAAC,CAACK,OAAO,GAC7D,CAAC;EAAEoB;AAAmC,CAAC,KAAKA,QAAQ;AACnD,MAAMC,mBAAoD,GAAAlB,OAAA,CAAAkB,mBAAA,GAC/D1B,OAAO,CAAC,yCAAyC,CAAC,CAACK,OAAO","ignoreList":[]}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTranslateAnimation = exports.useKeyboardAnimation = void 0;
7
+ var _reactNativeReanimated = require("react-native-reanimated");
8
+ var _hooks = require("../../hooks");
9
+ var _context = require("../../context");
10
+ var _react = require("react");
11
+ var _reactNative = require("react-native");
12
+ const OS = _reactNative.Platform.OS;
13
+ const useKeyboardAnimation = () => {
14
+ const {
15
+ reanimated
16
+ } = (0, _context.useKeyboardContext)();
17
+ // calculate it only once on mount, to avoid `SharedValue` reads during a render
18
+ const [initialHeight] = (0, _react.useState)(() => -reanimated.height.value);
19
+ const [initialProgress] = (0, _react.useState)(() => reanimated.progress.value);
20
+ const heightWhenOpened = (0, _reactNativeReanimated.useSharedValue)(initialHeight);
21
+ const height = (0, _reactNativeReanimated.useSharedValue)(initialHeight);
22
+ const progress = (0, _reactNativeReanimated.useSharedValue)(initialProgress);
23
+ const isClosed = (0, _reactNativeReanimated.useSharedValue)(initialProgress === 0);
24
+ (0, _hooks.useKeyboardHandler)({
25
+ onStart: e => {
26
+ "worklet";
27
+
28
+ if (e.height > 0) {
29
+ // eslint-disable-next-line react-compiler/react-compiler
30
+ isClosed.value = false;
31
+ heightWhenOpened.value = e.height;
32
+ }
33
+ },
34
+ onMove: e => {
35
+ "worklet";
36
+
37
+ progress.value = e.progress;
38
+ height.value = e.height;
39
+ },
40
+ onInteractive: e => {
41
+ "worklet";
42
+
43
+ progress.value = e.progress;
44
+ height.value = e.height;
45
+ },
46
+ onEnd: e => {
47
+ "worklet";
48
+
49
+ if (_reactNative.Platform.OS === 'harmony') {
50
+ heightWhenOpened.value = e.height;
51
+ }
52
+ isClosed.value = e.height === 0;
53
+
54
+ // `height` update happens in `onMove` handler
55
+ // in `onEnd` we need to update only if `onMove`
56
+ // wasn't called (i. e. duration === 0)
57
+ //
58
+ // we can not call this code without condition below
59
+ // because in some corner cases (iOS with `secureTextEntry`)
60
+ // `onEnd` can be emitted before `onMove` and in this case
61
+ // it may lead to choppy/glitchy/jumpy UI
62
+ // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327
63
+ if (e.duration === 0) {
64
+ progress.value = e.progress;
65
+ height.value = e.height;
66
+ }
67
+ }
68
+ }, []);
69
+ return {
70
+ height,
71
+ progress,
72
+ heightWhenOpened,
73
+ isClosed
74
+ };
75
+ };
76
+ exports.useKeyboardAnimation = useKeyboardAnimation;
77
+ const useTranslateAnimation = () => {
78
+ const {
79
+ reanimated
80
+ } = (0, _context.useKeyboardContext)();
81
+
82
+ // calculate it only once on mount, to avoid `SharedValue` reads during a render
83
+ const [initialProgress] = (0, _react.useState)(() => reanimated.progress.value);
84
+ const padding = (0, _reactNativeReanimated.useSharedValue)(initialProgress);
85
+ const translate = (0, _reactNativeReanimated.useSharedValue)(0);
86
+ (0, _hooks.useKeyboardHandler)({
87
+ onStart: e => {
88
+ "worklet";
89
+
90
+ if (e.height === 0) {
91
+ // eslint-disable-next-line react-compiler/react-compiler
92
+ padding.value = 0;
93
+ }
94
+ if (OS === "ios") {
95
+ translate.value = e.progress;
96
+ }
97
+ },
98
+ onMove: e => {
99
+ "worklet";
100
+
101
+ if (OS === "android") {
102
+ translate.value = e.progress;
103
+ }
104
+ },
105
+ onInteractive: e => {
106
+ "worklet";
107
+
108
+ padding.value = 0;
109
+ translate.value = e.progress;
110
+ },
111
+ onEnd: e => {
112
+ "worklet";
113
+
114
+ padding.value = e.progress;
115
+ if (OS === "android") {
116
+ translate.value = e.progress;
117
+ }
118
+ }
119
+ }, []);
120
+ return {
121
+ translate,
122
+ padding
123
+ };
124
+ };
125
+ exports.useTranslateAnimation = useTranslateAnimation;
126
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNativeReanimated","require","_hooks","_context","_react","_reactNative","OS","Platform","useKeyboardAnimation","reanimated","useKeyboardContext","initialHeight","useState","height","value","initialProgress","progress","heightWhenOpened","useSharedValue","isClosed","useKeyboardHandler","onStart","e","onMove","onInteractive","onEnd","duration","exports","useTranslateAnimation","padding","translate"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\n\nimport {useKeyboardHandler} from \"../../hooks\";\nimport {useKeyboardContext} from \"../../context\";\nimport { useState } from \"react\";\nimport { Platform } from \"react-native\";\n\nconst OS = Platform.OS;\n\nexport const useKeyboardAnimation = () => {\n const { reanimated } = useKeyboardContext();\n // calculate it only once on mount, to avoid `SharedValue` reads during a render\n const [initialHeight] = useState(() => -reanimated.height.value);\n const [initialProgress] = useState(() => reanimated.progress.value);\n\n const heightWhenOpened = useSharedValue(initialHeight);\n const height = useSharedValue(initialHeight);\n const progress = useSharedValue(initialProgress);\n const isClosed = useSharedValue(initialProgress === 0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (e.height > 0) {\n // eslint-disable-next-line react-compiler/react-compiler\n isClosed.value = false;\n heightWhenOpened.value = e.height;\n }\n },\n onMove: (e) => {\n \"worklet\";\n \n progress.value = e.progress;\n height.value = e.height;\n },\n onInteractive: (e) => {\n \"worklet\";\n\n progress.value = e.progress;\n height.value = e.height;\n },\n onEnd: (e) => {\n \"worklet\";\n if(Platform.OS as string === 'harmony'){\n heightWhenOpened.value = e.height;\n }\n \n isClosed.value = e.height === 0;\n\n // `height` update happens in `onMove` handler\n // in `onEnd` we need to update only if `onMove`\n // wasn't called (i. e. duration === 0)\n //\n // we can not call this code without condition below\n // because in some corner cases (iOS with `secureTextEntry`)\n // `onEnd` can be emitted before `onMove` and in this case\n // it may lead to choppy/glitchy/jumpy UI\n // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327\n if (e.duration === 0) {\n progress.value = e.progress;\n height.value = e.height;\n }\n },\n },\n [],\n );\n\n return { height, progress, heightWhenOpened, isClosed };\n};\n\nexport const useTranslateAnimation = () => {\n const { reanimated } = useKeyboardContext();\n\n // calculate it only once on mount, to avoid `SharedValue` reads during a render\n const [initialProgress] = useState(() => reanimated.progress.value);\n\n const padding = useSharedValue(initialProgress);\n const translate = useSharedValue(0);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (e.height === 0) {\n // eslint-disable-next-line react-compiler/react-compiler\n padding.value = 0;\n }\n if (OS === \"ios\") {\n translate.value = e.progress;\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n if (OS === \"android\") {\n translate.value = e.progress;\n }\n },\n onInteractive: (e) => {\n \"worklet\";\n\n padding.value = 0;\n\n translate.value = e.progress;\n },\n onEnd: (e) => {\n \"worklet\";\n\n padding.value = e.progress;\n\n if (OS === \"android\") {\n translate.value = e.progress;\n }\n },\n },\n [],\n );\n\n return { translate, padding };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,MAAMK,EAAE,GAAGC,qBAAQ,CAAC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QAAQ;MAC9B;IACF,CAAC;IACDQ,aAAa,EAAGF,CAAC,IAAK;MACpB,SAAS;;MAETO,OAAO,CAACf,KAAK,GAAG,CAAC;MAEjBgB,SAAS,CAAChB,KAAK,GAAGQ,CAAC,CAACN,QAAQ;IAC9B,CAAC;IACDS,KAAK,EAAGH,CAAC,IAAK;MACZ,SAAS;;MAETO,OAAO,CAACf,KAAK,GAAGQ,CAAC,CAACN,QAAQ;MAE1B,IAAIV,EAAE,KAAK,SAAS,EAAE;QACpBwB,SAAS,CAAChB,KAAK,GAAGQ,CAAC,CAACN,QAAQ;MAC9B;IACF;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEc,SAAS;IAAED;EAAQ,CAAC;AAC/B,CAAC;AAACF,OAAA,CAAAC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -0,0 +1,120 @@
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 {
38
+ translate,
39
+ padding
40
+ } = (0, _hooks2.useTranslateAnimation)();
41
+ const keyboard = (0, _hooks2.useKeyboardAnimation)();
42
+ const {
43
+ height: screenHeight
44
+ } = (0, _hooks.useWindowDimensions)();
45
+ const relativeKeyboardHeight = (0, _react.useCallback)(() => {
46
+ "worklet";
47
+
48
+ const keyboardY = screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
49
+ return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
50
+ }, [screenHeight, keyboardVerticalOffset]);
51
+ const interpolateToRelativeKeyboardHeight = (0, _react.useCallback)(value => {
52
+ "worklet";
53
+
54
+ return (0, _reactNativeReanimated.interpolate)(value, [0, 1], [0, relativeKeyboardHeight()]);
55
+ }, [relativeKeyboardHeight]);
56
+ const onLayoutWorklet = (0, _react.useCallback)(layout => {
57
+ "worklet";
58
+
59
+ if (keyboard.isClosed.value || initialFrame.value === null) {
60
+ // eslint-disable-next-line react-compiler/react-compiler
61
+ initialFrame.value = layout;
62
+ }
63
+ }, []);
64
+ const onLayout = (0, _react.useCallback)(e => {
65
+ (0, _reactNativeReanimated.runOnUI)(onLayoutWorklet)(e.nativeEvent.layout);
66
+ onLayoutProps === null || onLayoutProps === void 0 || onLayoutProps(e);
67
+ }, [onLayoutProps]);
68
+ const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
69
+ const bottom = interpolateToRelativeKeyboardHeight(keyboard.progress.value);
70
+ const translateY = interpolateToRelativeKeyboardHeight(translate.value);
71
+ const paddingBottom = interpolateToRelativeKeyboardHeight(padding.value);
72
+ const bottomHeight = enabled ? bottom : 0;
73
+ switch (behavior) {
74
+ case "height":
75
+ if (!keyboard.isClosed.value) {
76
+ return {
77
+ height: frame.value.height - bottomHeight,
78
+ flex: 0
79
+ };
80
+ }
81
+ return {};
82
+ case "position":
83
+ return {
84
+ bottom: bottomHeight
85
+ };
86
+ case "padding":
87
+ return {
88
+ paddingBottom: bottomHeight
89
+ };
90
+ case "translate-with-padding":
91
+ return {
92
+ paddingBottom: paddingBottom,
93
+ transform: [{
94
+ translateY: -translateY
95
+ }]
96
+ };
97
+ default:
98
+ return {};
99
+ }
100
+ }, [behavior, enabled, interpolateToRelativeKeyboardHeight]);
101
+ const isPositionBehavior = behavior === "position";
102
+ const containerStyle = isPositionBehavior ? contentContainerStyle : style;
103
+ const combinedStyles = (0, _react.useMemo)(() => [containerStyle, animatedStyle], [containerStyle, animatedStyle]);
104
+ if (isPositionBehavior) {
105
+ return /*#__PURE__*/_react.default.createElement(_reactNative.View, _extends({
106
+ ref: ref,
107
+ style: style,
108
+ onLayout: onLayout
109
+ }, props), /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
110
+ style: combinedStyles
111
+ }, children));
112
+ }
113
+ return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, _extends({
114
+ ref: ref,
115
+ onLayout: onLayout,
116
+ style: combinedStyles
117
+ }, props), children);
118
+ });
119
+ var _default = exports.default = KeyboardAvoidingView;
120
+ //# 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","translate","padding","useTranslateAnimation","keyboard","useKeyboardAnimation","screenHeight","useWindowDimensions","relativeKeyboardHeight","useCallback","keyboardY","heightWhenOpened","Math","max","interpolateToRelativeKeyboardHeight","interpolate","onLayoutWorklet","layout","isClosed","runOnUI","nativeEvent","animatedStyle","useAnimatedStyle","bottom","progress","translateY","paddingBottom","bottomHeight","flex","transform","isPositionBehavior","containerStyle","combinedStyles","useMemo","createElement","View","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\nimport { View } from \"react-native\";\nimport Reanimated, {\n interpolate,\n runOnUI,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport { useWindowDimensions } from \"../../hooks\";\n\nimport { useKeyboardAnimation, useTranslateAnimation } from \"./hooks\";\n\nimport type { LayoutRectangle, ViewProps } from \"react-native\";\n\nexport type KeyboardAvoidingViewBaseProps = {\n /**\n * Controls whether this `KeyboardAvoidingView` instance should take effect.\n * This is useful when more than one is on the screen. Defaults to true.\n */\n enabled?: boolean;\n\n /**\n * Distance between the top of the user screen and the React Native view. This\n * may be non-zero in some cases. Defaults to 0.\n */\n keyboardVerticalOffset?: number;\n} & ViewProps;\n\nexport type KeyboardAvoidingViewProps = KeyboardAvoidingViewBaseProps &\n (\n | {\n /**\n * Specify how to react to the presence of the keyboard.\n */\n behavior?: \"position\";\n\n /**\n * Style of the content container when `behavior` is 'position'.\n */\n contentContainerStyle?: ViewProps[\"style\"];\n }\n | {\n /**\n * Specify how to react to the presence of the keyboard.\n */\n behavior?: \"height\" | \"padding\" | \"translate-with-padding\";\n\n /**\n * `contentContainerStyle` is not allowed for these behaviors.\n */\n contentContainerStyle?: never;\n }\n );\n\nconst defaultLayout: LayoutRectangle = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n};\n\n/**\n * View that moves out of the way when the keyboard appears by automatically\n * adjusting its height, position, or bottom padding.\n */\nconst KeyboardAvoidingView = forwardRef<\n View,\n React.PropsWithChildren<KeyboardAvoidingViewProps>\n>(\n (\n {\n behavior,\n children,\n contentContainerStyle,\n enabled = true,\n keyboardVerticalOffset = 0,\n style,\n onLayout: onLayoutProps,\n ...props\n },\n ref,\n ) => {\n const initialFrame = useSharedValue<LayoutRectangle | null>(null);\n const frame = useDerivedValue(() => initialFrame.value || defaultLayout);\n\n const { translate, padding } = useTranslateAnimation();\n const keyboard = useKeyboardAnimation();\n const { height: screenHeight } = useWindowDimensions();\n\n const relativeKeyboardHeight = useCallback(() => {\n \"worklet\";\n\n const keyboardY =\n screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;\n\n return Math.max(frame.value.y + frame.value.height - keyboardY, 0);\n }, [screenHeight, keyboardVerticalOffset]);\n const interpolateToRelativeKeyboardHeight = useCallback(\n (value: number) => {\n \"worklet\";\n\n return interpolate(value, [0, 1], [0, relativeKeyboardHeight()]);\n },\n [relativeKeyboardHeight],\n );\n\n const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {\n \"worklet\";\n\n if (keyboard.isClosed.value || initialFrame.value === null) {\n // eslint-disable-next-line react-compiler/react-compiler\n initialFrame.value = layout;\n }\n }, []);\n const onLayout = useCallback<NonNullable<ViewProps[\"onLayout\"]>>(\n (e) => {\n runOnUI(onLayoutWorklet)(e.nativeEvent.layout);\n onLayoutProps?.(e);\n },\n [onLayoutProps],\n );\n\n const animatedStyle = useAnimatedStyle(() => {\n const bottom = interpolateToRelativeKeyboardHeight(\n keyboard.progress.value,\n );\n const translateY = interpolateToRelativeKeyboardHeight(translate.value);\n const paddingBottom = interpolateToRelativeKeyboardHeight(padding.value);\n const bottomHeight = enabled ? bottom : 0;\n\n switch (behavior) {\n case \"height\":\n if (!keyboard.isClosed.value) {\n return {\n height: frame.value.height - bottomHeight,\n flex: 0,\n };\n }\n\n return {};\n\n case \"position\":\n return { bottom: bottomHeight };\n\n case \"padding\":\n return { paddingBottom: bottomHeight };\n\n case \"translate-with-padding\":\n return {\n paddingBottom: paddingBottom,\n transform: [{ translateY: -translateY}],\n };\n\n default:\n return {};\n }\n }, [behavior, enabled, interpolateToRelativeKeyboardHeight]);\n const isPositionBehavior = behavior === \"position\";\n const containerStyle = isPositionBehavior ? contentContainerStyle : style;\n const combinedStyles = useMemo(\n () => [containerStyle, animatedStyle],\n [containerStyle, animatedStyle],\n );\n\n if (isPositionBehavior) {\n return (\n <View ref={ref} style={style} onLayout={onLayout} {...props}>\n <Reanimated.View style={combinedStyles}>{children}</Reanimated.View>\n </View>\n );\n }\n\n return (\n <Reanimated.View\n ref={ref}\n onLayout={onLayout}\n style={combinedStyles}\n {...props}\n >\n {children}\n </Reanimated.View>\n );\n },\n);\n\nexport default KeyboardAvoidingView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAQA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AAAsE,SAAAD,wBAAAM,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAR,uBAAA,YAAAA,CAAAM,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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AAO,CAAC,CAAC;IACb;EACF,CAAC,EAAE,CAACvC,QAAQ,EAAEG,OAAO,EAAEyB,mCAAmC,CAAC,CAAC;EAC5D,MAAMgB,kBAAkB,GAAG5C,QAAQ,KAAK,UAAU;EAClD,MAAM6C,cAAc,GAAGD,kBAAkB,GAAG1C,qBAAqB,GAAGG,KAAK;EACzE,MAAMyC,cAAc,GAAG,IAAAC,cAAO,EAC5B,MAAM,CAACF,cAAc,EAAEV,aAAa,CAAC,EACrC,CAACU,cAAc,EAAEV,aAAa,CAChC,CAAC;EAED,IAAIS,kBAAkB,EAAE;IACtB,oBACEnF,MAAA,CAAAiB,OAAA,CAAAsE,aAAA,CAACpF,YAAA,CAAAqF,IAAI,EAAA9D,QAAA;MAACsB,GAAG,EAAEA,GAAI;MAACJ,KAAK,EAAEA,KAAM;MAACC,QAAQ,EAAEA;IAAS,GAAKE,KAAK,gBACzD/C,MAAA,CAAAiB,OAAA,CAAAsE,aAAA,CAACnF,sBAAA,CAAAa,OAAU,CAACuE,IAAI;MAAC5C,KAAK,EAAEyC;IAAe,GAAE7C,QAA0B,CAC/D,CAAC;EAEX;EAEA,oBACExC,MAAA,CAAAiB,OAAA,CAAAsE,aAAA,CAACnF,sBAAA,CAAAa,OAAU,CAACuE,IAAI,EAAA9D,QAAA;IACdsB,GAAG,EAAEA,GAAI;IACTH,QAAQ,EAAEA,QAAS;IACnBD,KAAK,EAAEyC;EAAe,GAClBtC,KAAK,GAERP,QACc,CAAC;AAEtB,CACF,CAAC;AAAC,IAAAiD,QAAA,GAAAC,OAAA,CAAAzE,OAAA,GAEaoB,oBAAoB","ignoreList":[]}
@@ -0,0 +1,262 @@
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
+ ScrollViewComponent = _reactNativeReanimated.default.ScrollView,
61
+ ...rest
62
+ }, ref) => {
63
+ const scrollViewAnimatedRef = (0, _reactNativeReanimated.useAnimatedRef)();
64
+ const scrollViewTarget = (0, _reactNativeReanimated.useSharedValue)(null);
65
+ const scrollPosition = (0, _reactNativeReanimated.useSharedValue)(0);
66
+ const position = (0, _reactNativeReanimated.useScrollViewOffset)(scrollViewAnimatedRef);
67
+ const currentKeyboardFrameHeight = (0, _reactNativeReanimated.useSharedValue)(0);
68
+ const keyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
69
+ const keyboardWillAppear = (0, _reactNativeReanimated.useSharedValue)(false);
70
+ const tag = (0, _reactNativeReanimated.useSharedValue)(-1);
71
+ const initialKeyboardSize = (0, _reactNativeReanimated.useSharedValue)(0);
72
+ const scrollBeforeKeyboardMovement = (0, _reactNativeReanimated.useSharedValue)(0);
73
+ const {
74
+ input
75
+ } = (0, _hooks.useReanimatedFocusedInput)();
76
+ const layout = (0, _reactNativeReanimated.useSharedValue)(null);
77
+ const {
78
+ height
79
+ } = (0, _hooks.useWindowDimensions)();
80
+ const onRef = (0, _react.useCallback)(assignedRef => {
81
+ if (typeof ref === "function") {
82
+ ref(assignedRef);
83
+ } else if (ref) {
84
+ ref.current = assignedRef;
85
+ }
86
+ scrollViewAnimatedRef(assignedRef);
87
+ }, []);
88
+ const onScrollViewLayout = (0, _react.useCallback)(e => {
89
+ scrollViewTarget.value = (0, _reactNative.findNodeHandle)(scrollViewAnimatedRef.current);
90
+ onLayout === null || onLayout === void 0 || onLayout(e);
91
+ }, [onLayout]);
92
+
93
+ /**
94
+ * Function that will scroll a ScrollView as keyboard gets moving
95
+ */
96
+ const maybeScroll = (0, _react.useCallback)((e, animated = false) => {
97
+ "worklet";
98
+
99
+ var _layout$value, _layout$value2, _layout$value3;
100
+ if (!enabled) {
101
+ return 0;
102
+ }
103
+
104
+ // input belongs to ScrollView
105
+ if (((_layout$value = layout.value) === null || _layout$value === void 0 ? void 0 : _layout$value.parentScrollViewTarget) !== scrollViewTarget.value) {
106
+ return 0;
107
+ }
108
+ const visibleRect = height - keyboardHeight.value;
109
+ const absoluteY = ((_layout$value2 = layout.value) === null || _layout$value2 === void 0 ? void 0 : _layout$value2.layout.absoluteY) || 0;
110
+ const inputHeight = ((_layout$value3 = layout.value) === null || _layout$value3 === void 0 ? void 0 : _layout$value3.layout.height) || 0;
111
+ const point = absoluteY + inputHeight;
112
+ if (visibleRect - point <= bottomOffset) {
113
+ const relativeScrollTo = keyboardHeight.value - (height - point) + bottomOffset;
114
+ const interpolatedScrollTo = (0, _reactNativeReanimated.interpolate)(e, [initialKeyboardSize.value, keyboardHeight.value], [0, (0, _utils.scrollDistanceWithRespectToSnapPoints)(relativeScrollTo + scrollPosition.value, rest.snapToOffsets) - scrollPosition.value]);
115
+ const targetScrollY = Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
116
+ (0, _reactNativeReanimated.scrollTo)(scrollViewAnimatedRef, 0, targetScrollY, animated);
117
+ return interpolatedScrollTo;
118
+ }
119
+ if (absoluteY < 0) {
120
+ const positionOnScreen = visibleRect - inputHeight - bottomOffset;
121
+ const topOfScreen = scrollPosition.value + absoluteY;
122
+ (0, _reactNativeReanimated.scrollTo)(scrollViewAnimatedRef, 0, topOfScreen - positionOnScreen, animated);
123
+ }
124
+ return 0;
125
+ }, [bottomOffset, enabled, height, rest.snapToOffsets]);
126
+ const syncKeyboardFrame = (0, _react.useCallback)(e => {
127
+ "worklet";
128
+
129
+ const keyboardFrame = (0, _reactNativeReanimated.interpolate)(e.height, [0, keyboardHeight.value], [0, keyboardHeight.value + extraKeyboardSpace]);
130
+ currentKeyboardFrameHeight.value = keyboardFrame;
131
+ }, [extraKeyboardSpace]);
132
+ const scrollFromCurrentPosition = (0, _react.useCallback)(customHeight => {
133
+ "worklet";
134
+
135
+ var _input$value;
136
+ const prevScrollPosition = scrollPosition.value;
137
+ const prevLayout = layout.value;
138
+ if (!((_input$value = input.value) !== null && _input$value !== void 0 && _input$value.layout)) {
139
+ return;
140
+ }
141
+
142
+ // eslint-disable-next-line react-compiler/react-compiler
143
+ layout.value = {
144
+ ...input.value,
145
+ layout: {
146
+ ...input.value.layout,
147
+ height: customHeight ?? input.value.layout.height
148
+ }
149
+ };
150
+ scrollPosition.value = position.value;
151
+ maybeScroll(keyboardHeight.value, true);
152
+ scrollPosition.value = prevScrollPosition;
153
+ layout.value = prevLayout;
154
+ }, [maybeScroll]);
155
+ const onChangeText = (0, _react.useCallback)(() => {
156
+ "worklet";
157
+
158
+ // if typing a text caused layout shift, then we need to ignore this handler
159
+ // because this event will be handled in `useAnimatedReaction` below
160
+ var _layout$value4, _input$value2;
161
+ 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)) {
162
+ return;
163
+ }
164
+ scrollFromCurrentPosition();
165
+ }, [scrollFromCurrentPosition]);
166
+ const onSelectionChange = (0, _react.useCallback)(e => {
167
+ "worklet";
168
+
169
+ if (e.selection.start.position !== e.selection.end.position) {
170
+ scrollFromCurrentPosition(e.selection.end.y);
171
+ }
172
+ }, [scrollFromCurrentPosition]);
173
+ const onChangeTextHandler = (0, _react.useMemo)(() => (0, _utils.debounce)(onChangeText, 200), [onChangeText]);
174
+ (0, _hooks.useFocusedInputHandler)({
175
+ onChangeText: onChangeTextHandler,
176
+ onSelectionChange: onSelectionChange
177
+ }, [onChangeTextHandler, onSelectionChange]);
178
+ (0, _useSmoothKeyboardHandler.useSmoothKeyboardHandler)({
179
+ onStart: e => {
180
+ "worklet";
181
+
182
+ const keyboardWillChangeSize = keyboardHeight.value !== e.height && e.height > 0;
183
+ keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;
184
+ const keyboardWillHide = e.height === 0;
185
+ const focusWasChanged = tag.value !== e.target && e.target !== -1 || keyboardWillChangeSize;
186
+ if (keyboardWillChangeSize) {
187
+ initialKeyboardSize.value = keyboardHeight.value;
188
+ }
189
+ if (keyboardWillHide) {
190
+ // on back transition need to interpolate as [0, keyboardHeight]
191
+ initialKeyboardSize.value = 0;
192
+ scrollPosition.value = scrollBeforeKeyboardMovement.value;
193
+ }
194
+ if (keyboardWillAppear.value || keyboardWillChangeSize || focusWasChanged) {
195
+ // persist scroll value
196
+ scrollPosition.value = position.value;
197
+ // just persist height - later will be used in interpolation
198
+ keyboardHeight.value = e.height;
199
+ }
200
+
201
+ // focus was changed
202
+ if (focusWasChanged) {
203
+ tag.value = e.target;
204
+
205
+ // save position of focused text input when keyboard starts to move
206
+ layout.value = input.value;
207
+ // save current scroll position - when keyboard will hide we'll reuse
208
+ // this value to achieve smooth hide effect
209
+ scrollBeforeKeyboardMovement.value = position.value;
210
+ }
211
+ if (focusWasChanged && !keyboardWillAppear.value) {
212
+ // update position on scroll value, so `onEnd` handler
213
+ // will pick up correct values
214
+ position.value += maybeScroll(e.height, true);
215
+ }
216
+ },
217
+ onMove: e => {
218
+ "worklet";
219
+
220
+ syncKeyboardFrame(e);
221
+
222
+ // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens
223
+ if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {
224
+ maybeScroll(e.height);
225
+ }
226
+ },
227
+ onEnd: e => {
228
+ "worklet";
229
+
230
+ keyboardHeight.value = e.height;
231
+ scrollPosition.value = position.value;
232
+ syncKeyboardFrame(e);
233
+ }
234
+ }, [maybeScroll, disableScrollOnKeyboardHide, syncKeyboardFrame]);
235
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => input.value, (current, previous) => {
236
+ 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)) {
237
+ const prevLayout = layout.value;
238
+ layout.value = input.value;
239
+ scrollPosition.value += maybeScroll(keyboardHeight.value, true);
240
+ layout.value = prevLayout;
241
+ }
242
+ }, []);
243
+ const view = (0, _reactNativeReanimated.useAnimatedStyle)(() => enabled ? {
244
+ // animations become choppy when scrolling to the end of the `ScrollView` (when the last input is focused)
245
+ // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
246
+ // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
247
+ // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
248
+ // re-calculation on every animation frame and it helps to achieve smooth animation.
249
+ // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
250
+ paddingBottom: currentKeyboardFrameHeight.value + 1
251
+ } : {}, [enabled]);
252
+ return /*#__PURE__*/_react.default.createElement(ScrollViewComponent, _extends({
253
+ ref: onRef
254
+ }, rest, {
255
+ onLayout: onScrollViewLayout,
256
+ scrollEventThrottle: 16
257
+ }), children, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
258
+ style: view
259
+ }));
260
+ });
261
+ var _default = exports.default = KeyboardAwareScrollView;
262
+ //# sourceMappingURL=index.js.map