react-native-keyboard-controller 1.10.0 → 1.10.2

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 (144) hide show
  1. package/android/src/main/java/com/reactnativekeyboardcontroller/extensions/EditText.kt +31 -1
  2. package/ios/.clang-format +30 -30
  3. package/ios/.swiftlint.yml +1 -1
  4. package/ios/observers/FocusedInputObserver.swift +1 -0
  5. package/ios/views/KeyboardControllerViewManager.swift +12 -2
  6. package/jest/index.js +14 -4
  7. package/lib/commonjs/animated.js +19 -19
  8. package/lib/commonjs/animated.js.map +1 -1
  9. package/lib/commonjs/bindings.js.map +1 -1
  10. package/lib/commonjs/bindings.native.js +6 -6
  11. package/lib/commonjs/bindings.native.js.map +1 -1
  12. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js +19 -5
  13. package/lib/commonjs/components/KeyboardAvoidingView/hooks.js.map +1 -1
  14. package/lib/commonjs/components/KeyboardAvoidingView/index.js +12 -7
  15. package/lib/commonjs/components/KeyboardAvoidingView/index.js.map +1 -1
  16. package/lib/commonjs/components/KeyboardAwareScrollView/index.js +10 -8
  17. package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
  18. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +5 -5
  19. package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  20. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js +2 -2
  21. package/lib/commonjs/components/KeyboardAwareScrollView/utils.js.map +1 -1
  22. package/lib/commonjs/components/KeyboardStickyView/index.js +9 -5
  23. package/lib/commonjs/components/KeyboardStickyView/index.js.map +1 -1
  24. package/lib/commonjs/components/hooks/useKeyboardInterpolation.js +88 -0
  25. package/lib/commonjs/components/hooks/useKeyboardInterpolation.js.map +1 -0
  26. package/lib/commonjs/components/index.js.map +1 -1
  27. package/lib/commonjs/constants.js.map +1 -1
  28. package/lib/commonjs/context.js.map +1 -1
  29. package/lib/commonjs/hooks.js.map +1 -1
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/internal.js +1 -1
  32. package/lib/commonjs/internal.js.map +1 -1
  33. package/lib/commonjs/monkey-patch.android.js +1 -1
  34. package/lib/commonjs/monkey-patch.android.js.map +1 -1
  35. package/lib/commonjs/monkey-patch.js.map +1 -1
  36. package/lib/commonjs/reanimated.js.map +1 -1
  37. package/lib/commonjs/reanimated.native.js +12 -12
  38. package/lib/commonjs/reanimated.native.js.map +1 -1
  39. package/lib/commonjs/replicas.js +5 -5
  40. package/lib/commonjs/replicas.js.map +1 -1
  41. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js +1 -1
  42. package/lib/commonjs/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
  43. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js +2 -2
  44. package/lib/commonjs/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
  45. package/lib/commonjs/specs/NativeKeyboardController.js +1 -1
  46. package/lib/commonjs/specs/NativeKeyboardController.js.map +1 -1
  47. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js +1 -1
  48. package/lib/commonjs/specs/NativeStatusBarManagerCompat.js.map +1 -1
  49. package/lib/commonjs/types.js.map +1 -1
  50. package/lib/commonjs/utils.js.map +1 -1
  51. package/lib/module/animated.js +27 -27
  52. package/lib/module/animated.js.map +1 -1
  53. package/lib/module/bindings.js +1 -1
  54. package/lib/module/bindings.js.map +1 -1
  55. package/lib/module/bindings.native.js +7 -7
  56. package/lib/module/bindings.native.js.map +1 -1
  57. package/lib/module/components/KeyboardAvoidingView/hooks.js +19 -5
  58. package/lib/module/components/KeyboardAvoidingView/hooks.js.map +1 -1
  59. package/lib/module/components/KeyboardAvoidingView/index.js +15 -11
  60. package/lib/module/components/KeyboardAvoidingView/index.js.map +1 -1
  61. package/lib/module/components/KeyboardAwareScrollView/index.js +16 -14
  62. package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
  63. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +8 -8
  64. package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
  65. package/lib/module/components/KeyboardAwareScrollView/utils.js +2 -2
  66. package/lib/module/components/KeyboardAwareScrollView/utils.js.map +1 -1
  67. package/lib/module/components/KeyboardStickyView/index.js +9 -6
  68. package/lib/module/components/KeyboardStickyView/index.js.map +1 -1
  69. package/lib/module/components/hooks/useKeyboardInterpolation.js +81 -0
  70. package/lib/module/components/hooks/useKeyboardInterpolation.js.map +1 -0
  71. package/lib/module/components/index.js +3 -3
  72. package/lib/module/components/index.js.map +1 -1
  73. package/lib/module/context.js +2 -2
  74. package/lib/module/context.js.map +1 -1
  75. package/lib/module/hooks.js +5 -5
  76. package/lib/module/hooks.js.map +1 -1
  77. package/lib/module/index.js +8 -8
  78. package/lib/module/index.js.map +1 -1
  79. package/lib/module/internal.js +4 -4
  80. package/lib/module/internal.js.map +1 -1
  81. package/lib/module/monkey-patch.android.js +2 -2
  82. package/lib/module/monkey-patch.android.js.map +1 -1
  83. package/lib/module/monkey-patch.js.map +1 -1
  84. package/lib/module/reanimated.js.map +1 -1
  85. package/lib/module/reanimated.native.js +13 -13
  86. package/lib/module/reanimated.native.js.map +1 -1
  87. package/lib/module/replicas.js +11 -11
  88. package/lib/module/replicas.js.map +1 -1
  89. package/lib/module/specs/KeyboardControllerViewNativeComponent.js +2 -2
  90. package/lib/module/specs/KeyboardControllerViewNativeComponent.js.map +1 -1
  91. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js +3 -3
  92. package/lib/module/specs/KeyboardGestureAreaNativeComponent.js.map +1 -1
  93. package/lib/module/specs/NativeKeyboardController.js +2 -2
  94. package/lib/module/specs/NativeKeyboardController.js.map +1 -1
  95. package/lib/module/specs/NativeStatusBarManagerCompat.js +2 -2
  96. package/lib/module/specs/NativeStatusBarManagerCompat.js.map +1 -1
  97. package/lib/module/types.js.map +1 -1
  98. package/lib/module/utils.js.map +1 -1
  99. package/lib/typescript/animated.d.ts +1 -1
  100. package/lib/typescript/bindings.d.ts +1 -1
  101. package/lib/typescript/bindings.native.d.ts +1 -1
  102. package/lib/typescript/components/KeyboardAvoidingView/index.d.ts +4 -4
  103. package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +2 -2
  104. package/lib/typescript/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.d.ts +1 -1
  105. package/lib/typescript/components/KeyboardStickyView/index.d.ts +2 -2
  106. package/lib/typescript/components/hooks/useKeyboardInterpolation.d.ts +20 -0
  107. package/lib/typescript/components/index.d.ts +3 -3
  108. package/lib/typescript/context.d.ts +4 -4
  109. package/lib/typescript/hooks.d.ts +3 -3
  110. package/lib/typescript/index.d.ts +8 -8
  111. package/lib/typescript/internal.d.ts +2 -2
  112. package/lib/typescript/reanimated.d.ts +1 -1
  113. package/lib/typescript/reanimated.native.d.ts +1 -1
  114. package/lib/typescript/replicas.d.ts +1 -1
  115. package/lib/typescript/specs/KeyboardControllerViewNativeComponent.d.ts +3 -3
  116. package/lib/typescript/specs/KeyboardGestureAreaNativeComponent.d.ts +4 -4
  117. package/lib/typescript/specs/NativeKeyboardController.d.ts +1 -1
  118. package/lib/typescript/specs/NativeStatusBarManagerCompat.d.ts +1 -1
  119. package/lib/typescript/types.d.ts +3 -3
  120. package/package.json +8 -10
  121. package/src/animated.tsx +39 -39
  122. package/src/bindings.native.ts +11 -11
  123. package/src/bindings.ts +3 -3
  124. package/src/components/KeyboardAvoidingView/hooks.ts +20 -6
  125. package/src/components/KeyboardAvoidingView/index.tsx +25 -24
  126. package/src/components/KeyboardAwareScrollView/index.tsx +29 -25
  127. package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +13 -13
  128. package/src/components/KeyboardAwareScrollView/utils.ts +3 -3
  129. package/src/components/KeyboardStickyView/index.tsx +12 -12
  130. package/src/components/hooks/useKeyboardInterpolation.ts +108 -0
  131. package/src/components/index.ts +3 -3
  132. package/src/context.ts +7 -7
  133. package/src/hooks.ts +12 -12
  134. package/src/index.ts +8 -8
  135. package/src/internal.ts +9 -9
  136. package/src/monkey-patch.android.ts +2 -2
  137. package/src/reanimated.native.ts +20 -20
  138. package/src/reanimated.ts +1 -1
  139. package/src/replicas.ts +16 -16
  140. package/src/specs/KeyboardControllerViewNativeComponent.ts +5 -5
  141. package/src/specs/KeyboardGestureAreaNativeComponent.ts +7 -7
  142. package/src/specs/NativeKeyboardController.ts +3 -3
  143. package/src/specs/NativeStatusBarManagerCompat.ts +3 -3
  144. package/src/types.ts +21 -21
@@ -1,9 +1,9 @@
1
- import { NativeEventEmitter, Platform } from 'react-native';
1
+ import { NativeEventEmitter, Platform } from "react-native";
2
2
  const LINKING_ERROR = `The package 'react-native-keyboard-controller' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
3
3
  ios: "- You have run 'pod install'\n",
4
- default: ''
5
- }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
6
- const RCTKeyboardController = require('./specs/NativeKeyboardController').default;
4
+ default: ""
5
+ }) + "- You rebuilt the app after installing the package\n" + "- You are not using Expo Go\n";
6
+ const RCTKeyboardController = require("./specs/NativeKeyboardController").default;
7
7
  export const KeyboardController = RCTKeyboardController ? RCTKeyboardController : new Proxy({}, {
8
8
  get() {
9
9
  throw new Error(LINKING_ERROR);
@@ -11,10 +11,10 @@ export const KeyboardController = RCTKeyboardController ? RCTKeyboardController
11
11
  });
12
12
  const eventEmitter = new NativeEventEmitter(KeyboardController);
13
13
  export const KeyboardEvents = {
14
- addListener: (name, cb) => eventEmitter.addListener('KeyboardController::' + name, cb)
14
+ addListener: (name, cb) => eventEmitter.addListener("KeyboardController::" + name, cb)
15
15
  };
16
- export const KeyboardControllerView = require('./specs/KeyboardControllerViewNativeComponent').default;
17
- export const KeyboardGestureArea = Platform.OS === 'android' && Platform.Version >= 30 ? require('./specs/KeyboardGestureAreaNativeComponent').default : _ref => {
16
+ export const KeyboardControllerView = require("./specs/KeyboardControllerViewNativeComponent").default;
17
+ export const KeyboardGestureArea = Platform.OS === "android" && Platform.Version >= 30 ? require("./specs/KeyboardGestureAreaNativeComponent").default : _ref => {
18
18
  let {
19
19
  children
20
20
  } = _ref;
@@ -1 +1 @@
1
- {"version":3,"names":["NativeEventEmitter","Platform","LINKING_ERROR","select","ios","default","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView","KeyboardGestureArea","OS","Version","children"],"sources":["bindings.native.ts"],"sourcesContent":["import { NativeEventEmitter, Platform } from 'react-native';\n\nimport type {\n KeyboardControllerModule,\n KeyboardControllerProps,\n KeyboardEventsModule,\n KeyboardGestureAreaProps,\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;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents: KeyboardEventsModule = {\n addListener: (name, cb) =>\n eventEmitter.addListener('KeyboardController::' + 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\n ? require('./specs/KeyboardGestureAreaNativeComponent').default\n : ({ children }: KeyboardGestureAreaProps) => children;\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAS3D,MAAMC,aAAa,GAChB,2FAA0F,GAC3FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAkC,CAAC,CAACF,OAAO;AACrD,OAAO,MAAMG,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBAAqB,GACrB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CAAC,CAEoB;AAE7B,MAAMU,YAAY,GAAG,IAAIZ,kBAAkB,CAACQ,kBAAkB,CAAC;AAE/D,OAAO,MAAMK,cAAoC,GAAG;EAClDC,WAAW,EAAE,CAACC,IAAI,EAAEC,EAAE,KACpBJ,YAAY,CAACE,WAAW,CAAC,sBAAsB,GAAGC,IAAI,EAAEC,EAAE;AAC9D,CAAC;AACD,OAAO,MAAMC,sBAAyD,GACpEV,OAAO,CAAC,+CAA+C,CAAC,CAACF,OAAO;AAClE,OAAO,MAAMa,mBAAuD,GAClEjB,QAAQ,CAACkB,EAAE,KAAK,SAAS,IAAIlB,QAAQ,CAACmB,OAAO,IAAI,EAAE,GAC/Cb,OAAO,CAAC,4CAA4C,CAAC,CAACF,OAAO,GAC7D;EAAA,IAAC;IAAEgB;EAAmC,CAAC;EAAA,OAAKA,QAAQ;AAAA"}
1
+ {"version":3,"names":["NativeEventEmitter","Platform","LINKING_ERROR","select","ios","default","RCTKeyboardController","require","KeyboardController","Proxy","get","Error","eventEmitter","KeyboardEvents","addListener","name","cb","KeyboardControllerView","KeyboardGestureArea","OS","Version","_ref","children"],"sources":["bindings.native.ts"],"sourcesContent":["import { NativeEventEmitter, Platform } from \"react-native\";\n\nimport type {\n KeyboardControllerModule,\n KeyboardControllerProps,\n KeyboardEventsModule,\n KeyboardGestureAreaProps,\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;\nexport const KeyboardController = (\n RCTKeyboardController\n ? RCTKeyboardController\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n },\n )\n) as KeyboardControllerModule;\n\nconst eventEmitter = new NativeEventEmitter(KeyboardController);\n\nexport const KeyboardEvents: KeyboardEventsModule = {\n addListener: (name, cb) =>\n eventEmitter.addListener(\"KeyboardController::\" + 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\n ? require(\"./specs/KeyboardGestureAreaNativeComponent\").default\n : ({ children }: KeyboardGestureAreaProps) => children;\n"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAS3D,MAAMC,aAAa,GAChB,2FAA0F,GAC3FD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,qBAAqB,GACzBC,OAAO,CAAC,kCAAkC,CAAC,CAACF,OAAO;AACrD,OAAO,MAAMG,kBAAkB,GAC7BF,qBAAqB,GACjBA,qBAAqB,GACrB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CACuB;AAE7B,MAAMU,YAAY,GAAG,IAAIZ,kBAAkB,CAACQ,kBAAkB,CAAC;AAE/D,OAAO,MAAMK,cAAoC,GAAG;EAClDC,WAAW,EAAEA,CAACC,IAAI,EAAEC,EAAE,KACpBJ,YAAY,CAACE,WAAW,CAAC,sBAAsB,GAAGC,IAAI,EAAEC,EAAE;AAC9D,CAAC;AACD,OAAO,MAAMC,sBAAyD,GACpEV,OAAO,CAAC,+CAA+C,CAAC,CAACF,OAAO;AAClE,OAAO,MAAMa,mBAAuD,GAClEjB,QAAQ,CAACkB,EAAE,KAAK,SAAS,IAAIlB,QAAQ,CAACmB,OAAO,IAAI,EAAE,GAC/Cb,OAAO,CAAC,4CAA4C,CAAC,CAACF,OAAO,GAC7DgB,IAAA;EAAA,IAAC;IAAEC;EAAmC,CAAC,GAAAD,IAAA;EAAA,OAAKC,QAAQ;AAAA"}
@@ -1,5 +1,5 @@
1
- import { useSharedValue } from 'react-native-reanimated';
2
- import { useKeyboardHandler } from '../../hooks';
1
+ import { useSharedValue } from "react-native-reanimated";
2
+ import { useKeyboardHandler } from "react-native-keyboard-controller";
3
3
  export const useKeyboardAnimation = () => {
4
4
  const heightWhenOpened = useSharedValue(0);
5
5
  const height = useSharedValue(0);
@@ -7,7 +7,7 @@ export const useKeyboardAnimation = () => {
7
7
  const isClosed = useSharedValue(true);
8
8
  useKeyboardHandler({
9
9
  onStart: e => {
10
- 'worklet';
10
+ "worklet";
11
11
 
12
12
  if (e.height > 0) {
13
13
  isClosed.value = false;
@@ -15,15 +15,29 @@ export const useKeyboardAnimation = () => {
15
15
  }
16
16
  },
17
17
  onMove: e => {
18
- 'worklet';
18
+ "worklet";
19
19
 
20
20
  progress.value = e.progress;
21
21
  height.value = e.height;
22
22
  },
23
23
  onEnd: e => {
24
- 'worklet';
24
+ "worklet";
25
25
 
26
26
  isClosed.value = e.height === 0;
27
+
28
+ // `height` update happens in `onMove` handler
29
+ // in `onEnd` we need to update only if `onMove`
30
+ // wasn't called (i. e. duration === 0)
31
+ //
32
+ // we can not call this code without condition below
33
+ // because in some corner cases (iOS with `secureTextEntry`)
34
+ // `onEnd` can be emitted before `onMove` and in this case
35
+ // it may lead to choppy/glitchy/jumpy UI
36
+ // see https://github.com/kirillzyusko/react-native-keyboard-controller/issues/327
37
+ if (e.duration === 0) {
38
+ progress.value = e.progress;
39
+ height.value = e.height;
40
+ }
27
41
  }
28
42
  }, []);
29
43
  return {
@@ -1 +1 @@
1
- {"version":3,"names":["useSharedValue","useKeyboardHandler","useKeyboardAnimation","heightWhenOpened","height","progress","isClosed","onStart","e","value","onMove","onEnd"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from 'react-native-reanimated';\n\nimport { useKeyboardHandler } from '../../hooks';\n\nexport const useKeyboardAnimation = () => {\n const heightWhenOpened = useSharedValue(0);\n const height = useSharedValue(0);\n const progress = useSharedValue(0);\n const isClosed = useSharedValue(true);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n 'worklet';\n\n if (e.height > 0) {\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 onEnd: (e) => {\n 'worklet';\n\n isClosed.value = e.height === 0;\n },\n },\n []\n );\n\n return { height, progress, heightWhenOpened, isClosed };\n};\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,yBAAyB;AAExD,SAASC,kBAAkB,QAAQ,aAAa;AAEhD,OAAO,MAAMC,oBAAoB,GAAG,MAAM;EACxC,MAAMC,gBAAgB,GAAGH,cAAc,CAAC,CAAC,CAAC;EAC1C,MAAMI,MAAM,GAAGJ,cAAc,CAAC,CAAC,CAAC;EAChC,MAAMK,QAAQ,GAAGL,cAAc,CAAC,CAAC,CAAC;EAClC,MAAMM,QAAQ,GAAGN,cAAc,CAAC,IAAI,CAAC;EAErCC,kBAAkB,CAChB;IACEM,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACJ,MAAM,GAAG,CAAC,EAAE;QAChBE,QAAQ,CAACG,KAAK,GAAG,KAAK;QACtBN,gBAAgB,CAACM,KAAK,GAAGD,CAAC,CAACJ,MAAM;MACnC;IACF,CAAC;IACDM,MAAM,EAAGF,CAAC,IAAK;MACb,SAAS;;MAETH,QAAQ,CAACI,KAAK,GAAGD,CAAC,CAACH,QAAQ;MAC3BD,MAAM,CAACK,KAAK,GAAGD,CAAC,CAACJ,MAAM;IACzB,CAAC;IACDO,KAAK,EAAGH,CAAC,IAAK;MACZ,SAAS;;MAETF,QAAQ,CAACG,KAAK,GAAGD,CAAC,CAACJ,MAAM,KAAK,CAAC;IACjC;EACF,CAAC,EACD,EAAE,CACH;EAED,OAAO;IAAEA,MAAM;IAAEC,QAAQ;IAAEF,gBAAgB;IAAEG;EAAS,CAAC;AACzD,CAAC"}
1
+ {"version":3,"names":["useSharedValue","useKeyboardHandler","useKeyboardAnimation","heightWhenOpened","height","progress","isClosed","onStart","e","value","onMove","onEnd","duration"],"sources":["hooks.ts"],"sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\n\nimport { useKeyboardHandler } from \"react-native-keyboard-controller\";\n\nexport const useKeyboardAnimation = () => {\n const heightWhenOpened = useSharedValue(0);\n const height = useSharedValue(0);\n const progress = useSharedValue(0);\n const isClosed = useSharedValue(true);\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n if (e.height > 0) {\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 onEnd: (e) => {\n \"worklet\";\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"],"mappings":"AAAA,SAASA,cAAc,QAAQ,yBAAyB;AAExD,SAASC,kBAAkB,QAAQ,kCAAkC;AAErE,OAAO,MAAMC,oBAAoB,GAAGA,CAAA,KAAM;EACxC,MAAMC,gBAAgB,GAAGH,cAAc,CAAC,CAAC,CAAC;EAC1C,MAAMI,MAAM,GAAGJ,cAAc,CAAC,CAAC,CAAC;EAChC,MAAMK,QAAQ,GAAGL,cAAc,CAAC,CAAC,CAAC;EAClC,MAAMM,QAAQ,GAAGN,cAAc,CAAC,IAAI,CAAC;EAErCC,kBAAkB,CAChB;IACEM,OAAO,EAAGC,CAAC,IAAK;MACd,SAAS;;MAET,IAAIA,CAAC,CAACJ,MAAM,GAAG,CAAC,EAAE;QAChBE,QAAQ,CAACG,KAAK,GAAG,KAAK;QACtBN,gBAAgB,CAACM,KAAK,GAAGD,CAAC,CAACJ,MAAM;MACnC;IACF,CAAC;IACDM,MAAM,EAAGF,CAAC,IAAK;MACb,SAAS;;MAETH,QAAQ,CAACI,KAAK,GAAGD,CAAC,CAACH,QAAQ;MAC3BD,MAAM,CAACK,KAAK,GAAGD,CAAC,CAACJ,MAAM;IACzB,CAAC;IACDO,KAAK,EAAGH,CAAC,IAAK;MACZ,SAAS;;MAETF,QAAQ,CAACG,KAAK,GAAGD,CAAC,CAACJ,MAAM,KAAK,CAAC;;MAE/B;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA,IAAII,CAAC,CAACI,QAAQ,KAAK,CAAC,EAAE;QACpBP,QAAQ,CAACI,KAAK,GAAGD,CAAC,CAACH,QAAQ;QAC3BD,MAAM,CAACK,KAAK,GAAGD,CAAC,CAACJ,MAAM;MACzB;IACF;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEA,MAAM;IAAEC,QAAQ;IAAEF,gBAAgB;IAAEG;EAAS,CAAC;AACzD,CAAC"}
@@ -1,8 +1,9 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { forwardRef, useCallback, useMemo } from 'react';
3
- import { View, useWindowDimensions } from 'react-native';
4
- import Reanimated, { interpolate, runOnUI, useAnimatedStyle, useDerivedValue, useSharedValue } from 'react-native-reanimated';
5
- import { useKeyboardAnimation } from './hooks';
2
+ import React, { forwardRef, useCallback, useMemo } from "react";
3
+ import { View, useWindowDimensions } from "react-native";
4
+ import Reanimated, { runOnUI, useAnimatedStyle, useDerivedValue, useSharedValue } from "react-native-reanimated";
5
+ import useKeyboardInterpolation from "../hooks/useKeyboardInterpolation";
6
+ import { useKeyboardAnimation } from "./hooks";
6
7
  const defaultLayout = {
7
8
  x: 0,
8
9
  y: 0,
@@ -32,13 +33,16 @@ const KeyboardAvoidingView = /*#__PURE__*/forwardRef((_ref, ref) => {
32
33
  height: screenHeight
33
34
  } = useWindowDimensions();
34
35
  const relativeKeyboardHeight = useCallback(() => {
35
- 'worklet';
36
+ "worklet";
36
37
 
37
38
  const keyboardY = screenHeight - keyboard.heightWhenOpened.value - keyboardVerticalOffset;
38
39
  return Math.max(frame.value.y + frame.value.height - keyboardY, 0);
39
40
  }, [screenHeight, keyboardVerticalOffset]);
41
+ const {
42
+ interpolate
43
+ } = useKeyboardInterpolation();
40
44
  const onLayoutWorklet = useCallback(layout => {
41
- 'worklet';
45
+ "worklet";
42
46
 
43
47
  if (keyboard.isClosed.value) {
44
48
  initialFrame.value = layout;
@@ -49,10 +53,10 @@ const KeyboardAvoidingView = /*#__PURE__*/forwardRef((_ref, ref) => {
49
53
  onLayoutProps === null || onLayoutProps === void 0 ? void 0 : onLayoutProps(e);
50
54
  }, [onLayoutProps]);
51
55
  const animatedStyle = useAnimatedStyle(() => {
52
- const bottom = interpolate(keyboard.progress.value, [0, 1], [0, relativeKeyboardHeight()]);
56
+ const bottom = interpolate(keyboard.height.value, [0, relativeKeyboardHeight()]);
53
57
  const bottomHeight = enabled ? bottom : 0;
54
58
  switch (behavior) {
55
- case 'height':
59
+ case "height":
56
60
  if (!keyboard.isClosed.value) {
57
61
  return {
58
62
  height: frame.value.height - bottomHeight,
@@ -60,11 +64,11 @@ const KeyboardAvoidingView = /*#__PURE__*/forwardRef((_ref, ref) => {
60
64
  };
61
65
  }
62
66
  return {};
63
- case 'position':
67
+ case "position":
64
68
  return {
65
69
  bottom: bottomHeight
66
70
  };
67
- case 'padding':
71
+ case "padding":
68
72
  return {
69
73
  paddingBottom: bottomHeight
70
74
  };
@@ -72,7 +76,7 @@ const KeyboardAvoidingView = /*#__PURE__*/forwardRef((_ref, ref) => {
72
76
  return {};
73
77
  }
74
78
  }, [behavior, enabled, relativeKeyboardHeight]);
75
- const isPositionBehavior = behavior === 'position';
79
+ const isPositionBehavior = behavior === "position";
76
80
  const containerStyle = isPositionBehavior ? contentContainerStyle : style;
77
81
  const combinedStyles = useMemo(() => [containerStyle, animatedStyle], [containerStyle, animatedStyle]);
78
82
  if (isPositionBehavior) {
@@ -1 +1 @@
1
- {"version":3,"names":["React","forwardRef","useCallback","useMemo","View","useWindowDimensions","Reanimated","interpolate","runOnUI","useAnimatedStyle","useDerivedValue","useSharedValue","useKeyboardAnimation","defaultLayout","x","y","width","height","KeyboardAvoidingView","ref","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","initialFrame","frame","value","keyboard","screenHeight","relativeKeyboardHeight","keyboardY","heightWhenOpened","Math","max","onLayoutWorklet","layout","isClosed","e","nativeEvent","animatedStyle","bottom","progress","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from 'react';\nimport { View, useWindowDimensions } from 'react-native';\nimport Reanimated, {\n interpolate,\n runOnUI,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n} from 'react-native-reanimated';\n\nimport { useKeyboardAnimation } from './hooks';\n\nimport type { LayoutRectangle, ViewProps } from 'react-native';\n\ntype Props = {\n /**\n * Specify how to react to the presence of the keyboard.\n */\n behavior?: 'height' | 'position' | 'padding';\n\n /**\n * Style of the content container when `behavior` is 'position'.\n */\n contentContainerStyle?: ViewProps['style'];\n\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\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<View, React.PropsWithChildren<Props>>(\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 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\n const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {\n 'worklet';\n\n if (keyboard.isClosed.value) {\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 = interpolate(\n keyboard.progress.value,\n [0, 1],\n [0, relativeKeyboardHeight()]\n );\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 default:\n return {};\n }\n }, [behavior, enabled, relativeKeyboardHeight]);\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,OAAOA,KAAK,IAAIC,UAAU,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAC/D,SAASC,IAAI,EAAEC,mBAAmB,QAAQ,cAAc;AACxD,OAAOC,UAAU,IACfC,WAAW,EACXC,OAAO,EACPC,gBAAgB,EAChBC,eAAe,EACfC,cAAc,QACT,yBAAyB;AAEhC,SAASC,oBAAoB,QAAQ,SAAS;AA4B9C,MAAMC,aAA8B,GAAG;EACrCC,CAAC,EAAE,CAAC;EACJC,CAAC,EAAE,CAAC;EACJC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE;AACV,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,gBAAGjB,UAAU,CACrC,OAWEkB,GAAG,KACA;EAAA,IAXH;IACEC,QAAQ;IACRC,QAAQ;IACRC,qBAAqB;IACrBC,OAAO,GAAG,IAAI;IACdC,sBAAsB,GAAG,CAAC;IAC1BC,KAAK;IACLC,QAAQ,EAAEC,aAAa;I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+ {"version":3,"names":["React","forwardRef","useCallback","useMemo","View","useWindowDimensions","Reanimated","runOnUI","useAnimatedStyle","useDerivedValue","useSharedValue","useKeyboardInterpolation","useKeyboardAnimation","defaultLayout","x","y","width","height","KeyboardAvoidingView","_ref","ref","behavior","children","contentContainerStyle","enabled","keyboardVerticalOffset","style","onLayout","onLayoutProps","props","initialFrame","frame","value","keyboard","screenHeight","relativeKeyboardHeight","keyboardY","heightWhenOpened","Math","max","interpolate","onLayoutWorklet","layout","isClosed","e","nativeEvent","animatedStyle","bottom","bottomHeight","flex","paddingBottom","isPositionBehavior","containerStyle","combinedStyles","createElement","_extends"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useCallback, useMemo } from \"react\";\nimport { View, useWindowDimensions } from \"react-native\";\nimport Reanimated, {\n runOnUI,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport useKeyboardInterpolation from \"../hooks/useKeyboardInterpolation\";\n\nimport { useKeyboardAnimation } from \"./hooks\";\n\nimport type { LayoutRectangle, ViewProps } from \"react-native\";\n\ntype Props = {\n /**\n * Specify how to react to the presence of the keyboard.\n */\n behavior?: \"height\" | \"position\" | \"padding\";\n\n /**\n * Style of the content container when `behavior` is 'position'.\n */\n contentContainerStyle?: ViewProps[\"style\"];\n\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\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<View, React.PropsWithChildren<Props>>(\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 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 { interpolate } = useKeyboardInterpolation();\n\n const onLayoutWorklet = useCallback((layout: LayoutRectangle) => {\n \"worklet\";\n\n if (keyboard.isClosed.value) {\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 = interpolate(keyboard.height.value, [\n 0,\n relativeKeyboardHeight(),\n ]);\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 default:\n return {};\n }\n }, [behavior, enabled, relativeKeyboardHeight]);\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 </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,CAAC;IACb;EACF,CAAC,EAAE,CAAC3B,QAAQ,EAAEG,OAAO,EAAEW,sBAAsB,CAAC,CAAC;EAC/C,MAAMgB,kBAAkB,GAAG9B,QAAQ,KAAK,UAAU;EAClD,MAAM+B,cAAc,GAAGD,kBAAkB,GAAG5B,qBAAqB,GAAGG,KAAK;EACzE,MAAM2B,cAAc,GAAGlD,OAAO,CAC5B,MAAM,CAACiD,cAAc,EAAEN,aAAa,CAAC,EACrC,CAACM,cAAc,EAAEN,aAAa,CAChC,CAAC;EAED,IAAIK,kBAAkB,EAAE;IACtB,oBACEnD,KAAA,CAAAsD,aAAA,CAAClD,IAAI,EAAAmD,QAAA;MAACnC,GAAG,EAAEA,GAAI;MAACM,KAAK,EAAEA,KAAM;MAACC,QAAQ,EAAEA;IAAS,GAAKE,KAAK,gBACzD7B,KAAA,CAAAsD,aAAA,CAAChD,UAAU,CAACF,IAAI;MAACsB,KAAK,EAAE2B;IAAe,GAAE/B,QAA0B,CAC/D,CAAC;EAEX;EAEA,oBACEtB,KAAA,CAAAsD,aAAA,CAAChD,UAAU,CAACF,IAAI,EAAAmD,QAAA;IACdnC,GAAG,EAAEA,GAAI;IACTO,QAAQ,EAAEA,QAAS;IACnBD,KAAK,EAAE2B;EAAe,GAClBxB,KAAK,GAERP,QACc,CAAC;AAEtB,CACF,CAAC;AAED,eAAeJ,oBAAoB"}
@@ -1,10 +1,10 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { useCallback, useMemo } from 'react';
3
- import { useWindowDimensions } from 'react-native';
4
- import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
5
- import { useFocusedInputHandler, useReanimatedFocusedInput } from 'react-native-keyboard-controller';
6
- import { useSmoothKeyboardHandler } from './useSmoothKeyboardHandler';
7
- import { debounce } from './utils';
2
+ import React, { useCallback, useMemo } from "react";
3
+ import { useWindowDimensions } from "react-native";
4
+ import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from "react-native-reanimated";
5
+ import { useFocusedInputHandler, useReanimatedFocusedInput } from "react-native-keyboard-controller";
6
+ import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
7
+ import { debounce } from "./utils";
8
8
  /**
9
9
  * Everything begins from `onStart` handler. This handler is called every time,
10
10
  * when keyboard changes its size or when focused `TextInput` was changed. In
@@ -52,6 +52,7 @@ const KeyboardAwareScrollView = _ref => {
52
52
  const scrollViewAnimatedRef = useAnimatedRef();
53
53
  const scrollPosition = useSharedValue(0);
54
54
  const position = useSharedValue(0);
55
+ const currentKeyboardFrameHeight = useSharedValue(0);
55
56
  const keyboardHeight = useSharedValue(0);
56
57
  const tag = useSharedValue(-1);
57
58
  const initialKeyboardSize = useSharedValue(0);
@@ -73,7 +74,7 @@ const KeyboardAwareScrollView = _ref => {
73
74
  * Function that will scroll a ScrollView as keyboard gets moving
74
75
  */
75
76
  const maybeScroll = useCallback(function (e) {
76
- 'worklet';
77
+ "worklet";
77
78
 
78
79
  var _layout$value, _layout$value2;
79
80
  let animated = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -95,7 +96,7 @@ const KeyboardAwareScrollView = _ref => {
95
96
  return 0;
96
97
  }, [bottomOffset]);
97
98
  const onChangeText = useCallback(() => {
98
- 'worklet';
99
+ "worklet";
99
100
 
100
101
  // if typing a text caused layout shift, then we need to ignore this handler
101
102
  // because this event will be handled in `useAnimatedReaction` below
@@ -117,7 +118,7 @@ const KeyboardAwareScrollView = _ref => {
117
118
  }, [onChangeTextHandler]);
118
119
  useSmoothKeyboardHandler({
119
120
  onStart: e => {
120
- 'worklet';
121
+ "worklet";
121
122
 
122
123
  const keyboardWillChangeSize = keyboardHeight.value !== e.height && e.height > 0;
123
124
  const keyboardWillAppear = e.height > 0 && keyboardHeight.value === 0;
@@ -155,12 +156,13 @@ const KeyboardAwareScrollView = _ref => {
155
156
  }
156
157
  },
157
158
  onMove: e => {
158
- 'worklet';
159
+ "worklet";
159
160
 
161
+ currentKeyboardFrameHeight.value = e.height;
160
162
  maybeScroll(e.height);
161
163
  },
162
164
  onEnd: e => {
163
- 'worklet';
165
+ "worklet";
164
166
 
165
167
  keyboardHeight.value = e.height;
166
168
  scrollPosition.value = position.value;
@@ -175,16 +177,16 @@ const KeyboardAwareScrollView = _ref => {
175
177
  }
176
178
  }, []);
177
179
  const view = useAnimatedStyle(() => ({
178
- paddingBottom: keyboardHeight.value
180
+ paddingBottom: currentKeyboardFrameHeight.value
179
181
  }), []);
180
182
  return /*#__PURE__*/React.createElement(Reanimated.ScrollView, _extends({
181
183
  ref: scrollViewAnimatedRef
182
184
  }, rest, {
183
185
  onScroll: onScroll,
184
186
  scrollEventThrottle: 16
185
- }), /*#__PURE__*/React.createElement(Reanimated.View, {
187
+ }), children, /*#__PURE__*/React.createElement(Reanimated.View, {
186
188
  style: view
187
- }, children));
189
+ }));
188
190
  };
189
191
  export default KeyboardAwareScrollView;
190
192
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useCallback","useMemo","useWindowDimensions","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedScrollHandler","useAnimatedStyle","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useSmoothKeyboardHandler","debounce","KeyboardAwareScrollView","children","bottomOffset","rest","scrollViewAnimatedRef","scrollPosition","position","keyboardHeight","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","onScroll","e","value","contentOffset","y","maybeScroll","animated","visibleRect","absoluteY","inputHeight","point","interpolatedScrollTo","targetScrollY","Math","max","positionOnScreen","topOfScreen","onChangeText","prevScrollPosition","prevLayout","onChangeTextHandler","onStart","keyboardWillChangeSize","keyboardWillAppear","keyboardWillHide","focusWasChanged","target","onMove","onEnd","current","previous","view","paddingBottom"],"sources":["index.tsx"],"sourcesContent":["import React, { useCallback, useMemo } from 'react';\nimport { useWindowDimensions } from 'react-native';\nimport Reanimated, {\n interpolate,\n scrollTo,\n useAnimatedReaction,\n useAnimatedRef,\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useSharedValue,\n} from 'react-native-reanimated';\n\nimport {\n useFocusedInputHandler,\n useReanimatedFocusedInput,\n} from 'react-native-keyboard-controller';\n\nimport { useSmoothKeyboardHandler } from './useSmoothKeyboardHandler';\nimport { debounce } from './utils';\n\nimport type { FC } from 'react';\nimport type { ScrollViewProps } from 'react-native';\nimport type { FocusedInputLayoutChangedEvent } from 'react-native-keyboard-controller';\n\ntype KeyboardAwareScrollViewProps = {\n bottomOffset?: number;\n} & ScrollViewProps;\n\n/**\n * Everything begins from `onStart` handler. This handler is called every time,\n * when keyboard changes its size or when focused `TextInput` was changed. In\n * this handler we are calculating/memoizing values which later will be used\n * during layout movement. For that we calculate:\n * - layout of focused field (`layout`) - to understand whether there will be overlap\n * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation\n * - future keyboard height (`keyboardHeight`) - used in scroll interpolation\n * - current scroll position (`scrollPosition`) - used to scroll from this point\n *\n * Once we've calculated all necessary variables - we can actually start to use them.\n * It happens in `onMove` handler - this function simply calls `maybeScroll` with\n * current keyboard frame height. This functions makes the smooth transition.\n *\n * When the transition has finished we go to `onEnd` handler. In this handler\n * we verify, that the current field is not overlapped within a keyboard frame.\n * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,\n * however there could be some cases, when `onMove` is not called:\n * - on iOS when TextInput was changed - keyboard transition is instant\n * - on Android when TextInput was changed and keyboard size wasn't changed\n * So `onEnd` handler handle the case, when `onMove` wasn't triggered.\n *\n * ====================================================================================================================+\n * -----------------------------------------------------Flow chart-----------------------------------------------------+\n * ====================================================================================================================+\n *\n * +============================+ +============================+ +==================================+\n * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>\n * + + + (run `onStart`) + + `onMove` is getting called +\n * +============================+ +============================+ +==================================+\n *\n *\n * +============================+ +============================+ +=====================================+\n * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +\n * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +\n * +============================+ +============================+ +=====================================+\n *\n */\nconst KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({\n children,\n bottomOffset = 0,\n ...rest\n}) => {\n const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();\n const scrollPosition = useSharedValue(0);\n const position = useSharedValue(0);\n const keyboardHeight = useSharedValue(0);\n const tag = useSharedValue(-1);\n const initialKeyboardSize = useSharedValue(0);\n const scrollBeforeKeyboardMovement = useSharedValue(0);\n const { input } = useReanimatedFocusedInput();\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n\n const { height } = useWindowDimensions();\n\n const onScroll = useAnimatedScrollHandler(\n {\n onScroll: (e) => {\n position.value = e.contentOffset.y;\n },\n },\n []\n );\n\n /**\n * Function that will scroll a ScrollView as keyboard gets moving\n */\n const maybeScroll = useCallback(\n (e: number, animated: boolean = false) => {\n 'worklet';\n\n const visibleRect = height - keyboardHeight.value;\n const absoluteY = layout.value?.layout.absoluteY || 0;\n const inputHeight = layout.value?.layout.height || 0;\n const point = absoluteY + inputHeight;\n\n if (visibleRect - point <= bottomOffset) {\n const interpolatedScrollTo = interpolate(\n e,\n [initialKeyboardSize.value, keyboardHeight.value],\n [0, keyboardHeight.value - (height - point) + bottomOffset]\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\n scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);\n\n return interpolatedScrollTo;\n }\n\n if (absoluteY < 0) {\n const positionOnScreen = visibleRect - inputHeight - bottomOffset;\n const topOfScreen = scrollPosition.value + absoluteY;\n\n scrollTo(\n scrollViewAnimatedRef,\n 0,\n topOfScreen - positionOnScreen,\n animated\n );\n }\n\n return 0;\n },\n [bottomOffset]\n );\n\n const onChangeText = useCallback(() => {\n 'worklet';\n\n // if typing a text caused layout shift, then we need to ignore this handler\n // because this event will be handled in `useAnimatedReaction` below\n if (layout.value?.layout.height !== input.value?.layout.height) {\n return;\n }\n\n const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n scrollPosition.value = position.value;\n layout.value = input.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n }, [maybeScroll]);\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText]\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n },\n [onChangeTextHandler]\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n 'worklet';\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n const keyboardWillAppear = e.height > 0 && keyboardHeight.value === 0;\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) || keyboardWillChangeSize;\n\n if (keyboardWillChangeSize) {\n initialKeyboardSize.value = keyboardHeight.value;\n }\n\n if (keyboardWillHide) {\n // on back transition need to interpolate as [0, keyboardHeight]\n initialKeyboardSize.value = 0;\n scrollPosition.value = scrollBeforeKeyboardMovement.value;\n }\n\n if (keyboardWillAppear || keyboardWillChangeSize || focusWasChanged) {\n // persist scroll value\n scrollPosition.value = position.value;\n // just persist height - later will be used in interpolation\n keyboardHeight.value = e.height;\n }\n\n // focus was changed\n if (focusWasChanged) {\n tag.value = e.target;\n\n // save position of focused text input when keyboard starts to move\n layout.value = input.value;\n // save current scroll position - when keyboard will hide we'll reuse\n // this value to achieve smooth hide effect\n scrollBeforeKeyboardMovement.value = position.value;\n }\n\n if (focusWasChanged && !keyboardWillAppear) {\n // update position on scroll value, so `onEnd` handler\n // will pick up correct values\n position.value += maybeScroll(e.height, true);\n }\n },\n onMove: (e) => {\n 'worklet';\n\n maybeScroll(e.height);\n },\n onEnd: (e) => {\n 'worklet';\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [height, maybeScroll]\n );\n\n useAnimatedReaction(\n () => input.value,\n (current, previous) => {\n if (\n current?.target === previous?.target &&\n current?.layout.height !== previous?.layout.height\n ) {\n const prevLayout = layout.value;\n\n layout.value = input.value;\n scrollPosition.value += maybeScroll(keyboardHeight.value, true);\n layout.value = prevLayout;\n }\n },\n []\n );\n\n const view = useAnimatedStyle(\n () => ({\n paddingBottom: keyboardHeight.value,\n }),\n []\n );\n\n return (\n <Reanimated.ScrollView\n ref={scrollViewAnimatedRef}\n {...rest}\n onScroll={onScroll}\n scrollEventThrottle={16}\n >\n <Reanimated.View style={view}>{children}</Reanimated.View>\n </Reanimated.ScrollView>\n );\n};\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AACnD,SAASC,mBAAmB,QAAQ,cAAc;AAClD,OAAOC,UAAU,IACfC,WAAW,EACXC,QAAQ,EACRC,mBAAmB,EACnBC,cAAc,EACdC,wBAAwB,EACxBC,gBAAgB,EAChBC,cAAc,QACT,yBAAyB;AAEhC,SACEC,sBAAsB,EACtBC,yBAAyB,QACpB,kCAAkC;AAEzC,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,QAAQ,QAAQ,SAAS;AAUlC;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,uBAAyD,GAAG,QAI5D;EAAA,IAJ6D;IACjEC,QAAQ;IACRC,YAAY,GAAG,CAAC;IA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EACD,EAAE,CACH;EAED,MAAMY,IAAI,GAAGnD,gBAAgB,CAC3B,OAAO;IACLoD,aAAa,EAAEvC,cAAc,CAACS;EAChC,CAAC,CAAC,EACF,EAAE,CACH;EAED,oBACE,oBAAC,UAAU,CAAC,UAAU;IACpB,GAAG,EAAEZ;EAAsB,GACvBD,IAAI;IACR,QAAQ,EAAEW,QAAS;IACnB,mBAAmB,EAAE;EAAG,iBAExB,oBAAC,UAAU,CAAC,IAAI;IAAC,KAAK,EAAE+B;EAAK,GAAE5C,QAAQ,CAAmB,CACpC;AAE5B,CAAC;AAED,eAAeD,uBAAuB"}
1
+ {"version":3,"names":["React","useCallback","useMemo","useWindowDimensions","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedScrollHandler","useAnimatedStyle","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useSmoothKeyboardHandler","debounce","KeyboardAwareScrollView","_ref","children","bottomOffset","rest","scrollViewAnimatedRef","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","onScroll","e","value","contentOffset","y","maybeScroll","_layout$value","_layout$value2","animated","arguments","length","undefined","visibleRect","absoluteY","inputHeight","point","interpolatedScrollTo","targetScrollY","Math","max","positionOnScreen","topOfScreen","onChangeText","_layout$value3","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","onStart","keyboardWillChangeSize","keyboardWillAppear","keyboardWillHide","focusWasChanged","target","onMove","onEnd","current","previous","view","paddingBottom","createElement","ScrollView","_extends","ref","scrollEventThrottle","View","style"],"sources":["index.tsx"],"sourcesContent":["import React, { useCallback, useMemo } from \"react\";\nimport { useWindowDimensions } from \"react-native\";\nimport Reanimated, {\n interpolate,\n scrollTo,\n useAnimatedReaction,\n useAnimatedRef,\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useSharedValue,\n} from \"react-native-reanimated\";\n\nimport {\n useFocusedInputHandler,\n useReanimatedFocusedInput,\n} from \"react-native-keyboard-controller\";\n\nimport { useSmoothKeyboardHandler } from \"./useSmoothKeyboardHandler\";\nimport { debounce } from \"./utils\";\n\nimport type { FC } from \"react\";\nimport type { ScrollViewProps } from \"react-native\";\nimport type { FocusedInputLayoutChangedEvent } from \"react-native-keyboard-controller\";\n\ntype KeyboardAwareScrollViewProps = {\n bottomOffset?: number;\n} & ScrollViewProps;\n\n/**\n * Everything begins from `onStart` handler. This handler is called every time,\n * when keyboard changes its size or when focused `TextInput` was changed. In\n * this handler we are calculating/memoizing values which later will be used\n * during layout movement. For that we calculate:\n * - layout of focused field (`layout`) - to understand whether there will be overlap\n * - initial keyboard size (`initialKeyboardSize`) - used in scroll interpolation\n * - future keyboard height (`keyboardHeight`) - used in scroll interpolation\n * - current scroll position (`scrollPosition`) - used to scroll from this point\n *\n * Once we've calculated all necessary variables - we can actually start to use them.\n * It happens in `onMove` handler - this function simply calls `maybeScroll` with\n * current keyboard frame height. This functions makes the smooth transition.\n *\n * When the transition has finished we go to `onEnd` handler. In this handler\n * we verify, that the current field is not overlapped within a keyboard frame.\n * For full `onStart`/`onMove`/`onEnd` flow it may look like a redundant thing,\n * however there could be some cases, when `onMove` is not called:\n * - on iOS when TextInput was changed - keyboard transition is instant\n * - on Android when TextInput was changed and keyboard size wasn't changed\n * So `onEnd` handler handle the case, when `onMove` wasn't triggered.\n *\n * ====================================================================================================================+\n * -----------------------------------------------------Flow chart-----------------------------------------------------+\n * ====================================================================================================================+\n *\n * +============================+ +============================+ +==================================+\n * + User Press on TextInput + => + Keyboard starts showing + => + As keyboard moves frame by frame + =>\n * + + + (run `onStart`) + + `onMove` is getting called +\n * +============================+ +============================+ +==================================+\n *\n *\n * +============================+ +============================+ +=====================================+\n * + Keyboard is shown and we + => + User moved focus to + => + Only `onStart`/`onEnd` maybe called +\n * + call `onEnd` handler + + another `TextInput` + + (without involving `onMove`) +\n * +============================+ +============================+ +=====================================+\n *\n */\nconst KeyboardAwareScrollView: FC<KeyboardAwareScrollViewProps> = ({\n children,\n bottomOffset = 0,\n ...rest\n}) => {\n const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();\n const scrollPosition = useSharedValue(0);\n const position = useSharedValue(0);\n const currentKeyboardFrameHeight = useSharedValue(0);\n const keyboardHeight = useSharedValue(0);\n const tag = useSharedValue(-1);\n const initialKeyboardSize = useSharedValue(0);\n const scrollBeforeKeyboardMovement = useSharedValue(0);\n const { input } = useReanimatedFocusedInput();\n const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);\n\n const { height } = useWindowDimensions();\n\n const onScroll = useAnimatedScrollHandler(\n {\n onScroll: (e) => {\n position.value = e.contentOffset.y;\n },\n },\n [],\n );\n\n /**\n * Function that will scroll a ScrollView as keyboard gets moving\n */\n const maybeScroll = useCallback(\n (e: number, animated: boolean = false) => {\n \"worklet\";\n\n const visibleRect = height - keyboardHeight.value;\n const absoluteY = layout.value?.layout.absoluteY || 0;\n const inputHeight = layout.value?.layout.height || 0;\n const point = absoluteY + inputHeight;\n\n if (visibleRect - point <= bottomOffset) {\n const interpolatedScrollTo = interpolate(\n e,\n [initialKeyboardSize.value, keyboardHeight.value],\n [0, keyboardHeight.value - (height - point) + bottomOffset],\n );\n const targetScrollY =\n Math.max(interpolatedScrollTo, 0) + scrollPosition.value;\n scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);\n\n return interpolatedScrollTo;\n }\n\n if (absoluteY < 0) {\n const positionOnScreen = visibleRect - inputHeight - bottomOffset;\n const topOfScreen = scrollPosition.value + absoluteY;\n\n scrollTo(\n scrollViewAnimatedRef,\n 0,\n topOfScreen - positionOnScreen,\n animated,\n );\n }\n\n return 0;\n },\n [bottomOffset],\n );\n\n const onChangeText = useCallback(() => {\n \"worklet\";\n\n // if typing a text caused layout shift, then we need to ignore this handler\n // because this event will be handled in `useAnimatedReaction` below\n if (layout.value?.layout.height !== input.value?.layout.height) {\n return;\n }\n\n const prevScrollPosition = scrollPosition.value;\n const prevLayout = layout.value;\n\n scrollPosition.value = position.value;\n layout.value = input.value;\n maybeScroll(keyboardHeight.value, true);\n scrollPosition.value = prevScrollPosition;\n layout.value = prevLayout;\n }, [maybeScroll]);\n const onChangeTextHandler = useMemo(\n () => debounce(onChangeText, 200),\n [onChangeText],\n );\n\n useFocusedInputHandler(\n {\n onChangeText: onChangeTextHandler,\n },\n [onChangeTextHandler],\n );\n\n useSmoothKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n const keyboardWillChangeSize =\n keyboardHeight.value !== e.height && e.height > 0;\n const keyboardWillAppear = e.height > 0 && keyboardHeight.value === 0;\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) || keyboardWillChangeSize;\n\n if (keyboardWillChangeSize) {\n initialKeyboardSize.value = keyboardHeight.value;\n }\n\n if (keyboardWillHide) {\n // on back transition need to interpolate as [0, keyboardHeight]\n initialKeyboardSize.value = 0;\n scrollPosition.value = scrollBeforeKeyboardMovement.value;\n }\n\n if (keyboardWillAppear || keyboardWillChangeSize || focusWasChanged) {\n // persist scroll value\n scrollPosition.value = position.value;\n // just persist height - later will be used in interpolation\n keyboardHeight.value = e.height;\n }\n\n // focus was changed\n if (focusWasChanged) {\n tag.value = e.target;\n\n // save position of focused text input when keyboard starts to move\n layout.value = input.value;\n // save current scroll position - when keyboard will hide we'll reuse\n // this value to achieve smooth hide effect\n scrollBeforeKeyboardMovement.value = position.value;\n }\n\n if (focusWasChanged && !keyboardWillAppear) {\n // update position on scroll value, so `onEnd` handler\n // will pick up correct values\n position.value += maybeScroll(e.height, true);\n }\n },\n onMove: (e) => {\n \"worklet\";\n\n currentKeyboardFrameHeight.value = e.height;\n\n maybeScroll(e.height);\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [height, maybeScroll],\n );\n\n useAnimatedReaction(\n () => input.value,\n (current, previous) => {\n if (\n current?.target === previous?.target &&\n current?.layout.height !== previous?.layout.height\n ) {\n const prevLayout = layout.value;\n\n layout.value = input.value;\n scrollPosition.value += maybeScroll(keyboardHeight.value, true);\n layout.value = prevLayout;\n }\n },\n [],\n );\n\n const view = useAnimatedStyle(\n () => ({\n paddingBottom: currentKeyboardFrameHeight.value,\n }),\n [],\n );\n\n return (\n <Reanimated.ScrollView\n ref={scrollViewAnimatedRef}\n {...rest}\n onScroll={onScroll}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n};\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AACnD,SAASC,mBAAmB,QAAQ,cAAc;AAClD,OAAOC,UAAU,IACfC,WAAW,EACXC,QAAQ,EACRC,mBAAmB,EACnBC,cAAc,EACdC,wBAAwB,EACxBC,gBAAgB,EAChBC,cAAc,QACT,yBAAyB;AAEhC,SACEC,sBAAsB,EACtBC,yBAAyB,QACpB,kCAAkC;AAEzC,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,QAAQ,QAAQ,SAAS;AAUlC;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,uBAAyD,GAAGC,IAAA,IAI5D;EAAA,IAJ6D;IACjEC,QAAQ;IACRC,YAAY,GAAG,CAAC;IAChB,GAAGC;EACL,CAAC,GAAAH,IAAA;EACC,MAAMI,qBAAqB,GAAGb,cAAc,CAAwB,CAAC;EACrE,MAAMc,cAAc,GAAGX,cAAc,CAAC,CAAC,CAAC;EACxC,MAAMY,QAAQ,GAAGZ,cAAc,CAAC,CAAC,CAAC;EAClC,MAAMa,0BAA0B,GAAGb,cAAc,CAAC,CAAC,CAAC;EACpD,MAAMc,c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AC1BZ,cAAc,CAACY,KAAK,IAAIG,WAAW,CAACZ,cAAc,CAACS,KAAK,EAAE,IAAI,CAAC;MAC/DJ,MAAM,CAACI,KAAK,GAAGwB,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMY,IAAI,GAAG5D,gBAAgB,CAC3B,OAAO;IACL6D,aAAa,EAAE/C,0BAA0B,CAACU;EAC5C,CAAC,CAAC,EACF,EACF,CAAC;EAED,oBACElC,KAAA,CAAAwE,aAAA,CAACpE,UAAU,CAACqE,UAAU,EAAAC,QAAA;IACpBC,GAAG,EAAEtD;EAAsB,GACvBD,IAAI;IACRY,QAAQ,EAAEA,QAAS;IACnB4C,mBAAmB,EAAE;EAAG,IAEvB1D,QAAQ,eACTlB,KAAA,CAAAwE,aAAA,CAACpE,UAAU,CAACyE,IAAI;IAACC,KAAK,EAAER;EAAK,CAAE,CACV,CAAC;AAE5B,CAAC;AAED,eAAetD,uBAAuB"}
@@ -1,9 +1,9 @@
1
- import { Platform } from 'react-native';
2
- import { Easing, useAnimatedReaction, useSharedValue, withTiming } from 'react-native-reanimated';
3
- import { useKeyboardHandler } from 'react-native-keyboard-controller';
4
- const IS_ANDROID_ELEVEN_OR_HIGHER = Platform.OS === 'android' && Platform.Version >= 30;
1
+ import { Platform } from "react-native";
2
+ import { Easing, useAnimatedReaction, useSharedValue, withTiming } from "react-native-reanimated";
3
+ import { useKeyboardHandler } from "react-native-keyboard-controller";
4
+ const IS_ANDROID_ELEVEN_OR_HIGHER = Platform.OS === "android" && Platform.Version >= 30;
5
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';
6
+ const IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS = IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === "ios";
7
7
  // on Android Telegram is not using androidx.core values and uses custom interpolation
8
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
9
  // and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40
@@ -48,7 +48,7 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
48
48
  }, [handler]);
49
49
  useKeyboardHandler({
50
50
  onStart: e => {
51
- 'worklet';
51
+ "worklet";
52
52
 
53
53
  // immediately dispatch onStart/onEnd events if onStart dispatched with the same height
54
54
  // and don't wait for animation 250ms
@@ -72,7 +72,7 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
72
72
  (_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 ? void 0 : _handler$onStart2.call(handler, e);
73
73
  },
74
74
  onMove: e => {
75
- 'worklet';
75
+ "worklet";
76
76
 
77
77
  if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
78
78
  var _handler$onMove2;
@@ -80,7 +80,7 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
80
80
  }
81
81
  },
82
82
  onEnd: e => {
83
- 'worklet';
83
+ "worklet";
84
84
 
85
85
  if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
86
86
  var _handler$onEnd3;
@@ -1 +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","persistedHeight","animatedKeyboardHeight","event","value","height","progress","evt","onMove","onEnd","onStart","e"],"sources":["useSmoothKeyboardHandler.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport {\n Easing,\n useAnimatedReaction,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\n\nimport { useKeyboardHandler } from 'react-native-keyboard-controller';\n\nconst IS_ANDROID_ELEVEN_OR_HIGHER =\n Platform.OS === 'android' && Platform.Version >= 30;\n// on these platforms keyboard transitions will be smooth\nconst IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS =\n IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === 'ios';\n// on Android Telegram is not using androidx.core values and uses custom interpolation\n// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39\n// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40\nconst TELEGRAM_ANDROID_TIMING_CONFIG = {\n duration: 250,\n easing: Easing.bezier(\n 0.19919472913616398,\n 0.010644531250000006,\n 0.27920937042459737,\n 0.91025390625\n ),\n};\n\n/**\n * Hook that uses default transitions for iOS and Android > 11, and uses\n * custom interpolation on Android < 11 to achieve more smooth animation\n */\nexport const useSmoothKeyboardHandler: typeof useKeyboardHandler = (\n handler,\n deps\n) => {\n const target = useSharedValue(-1);\n const persistedHeight = useSharedValue(0);\n const animatedKeyboardHeight = useSharedValue(0);\n\n useAnimatedReaction(\n () => {\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n return;\n }\n const event = {\n // it'll be always 250, since we're running animation via `withTiming` where\n // duration in config (TELEGRAM_ANDROID_TIMING_CONFIG.duration) = 250ms\n duration: 250,\n target: target.value,\n height: animatedKeyboardHeight.value,\n progress: animatedKeyboardHeight.value / persistedHeight.value,\n };\n return event;\n },\n (evt) => {\n if (!evt) {\n return;\n }\n handler.onMove?.(evt);\n\n // dispatch `onEnd`\n if (evt.height === persistedHeight.value) {\n handler.onEnd?.(evt);\n }\n },\n [handler]\n );\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n 'worklet';\n\n // immediately dispatch onStart/onEnd events if onStart dispatched with the same height\n // and don't wait for animation 250ms\n if (\n !IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS &&\n e.height === persistedHeight.value\n ) {\n handler.onStart?.(e);\n handler.onEnd?.(e);\n\n return;\n }\n\n target.value = e.target;\n\n if (e.height > 0) {\n persistedHeight.value = e.height;\n }\n // if we are running on Android < 9, then we are using custom interpolation\n // to achieve smoother animation and use `animatedKeyboardHeight` as animation\n // driver\n if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n animatedKeyboardHeight.value = withTiming(\n e.height,\n TELEGRAM_ANDROID_TIMING_CONFIG\n );\n }\n\n handler.onStart?.(e);\n },\n onMove: (e) => {\n 'worklet';\n\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n handler.onMove?.(e);\n }\n },\n onEnd: (e) => {\n 'worklet';\n\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n handler.onEnd?.(e);\n }\n\n persistedHeight.value = e.height;\n },\n },\n deps\n );\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SACEC,MAAM,EACNC,mBAAmB,EACnBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAEhC,SAASC,kBAAkB,QAAQ,kCAAkC;AAErE,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;AACtD;AACA;AACA;AACA,MAAMG,8BAA8B,GAAG;EACrCC,QAAQ,EAAE,GAAG;EACbC,MAAM,EAAEX,MAAM,CAACY,MAAM,CACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa;AAEjB,CAAC;;AAED;AACA;AACA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C,CAACX,MAAM;MAEvB,IAAIW,CAAC,CAACN,MAAM,GAAG,CAAC,EAAE;QAChBJ,eAAe,CAACG,KAAK,GAAGO,CAAC,CAACN,MAAM;MAClC;MACA;MACA;MACA;MACA,IAAI,CAACb,kCAAkC,EAAE;QACvCU,sBAAsB,CAACE,KAAK,GAAGjB,UAAU,CACvCwB,CAAC,CAACN,MAAM,EACRZ,8BAA8B,CAC/B;MACH;MAEA,qBAAAK,OAAO,CAACY,OAAO,sDAAf,uBAAAZ,OAAO,EAAWa,CAAC,CAAC;IACtB,CAAC;IACDH,MAAM,EAAGG,CAAC,IAAK;MACb,SAAS;;MAET,IAAInB,kCAAkC,EAAE;QAAA;QACtC,oBAAAM,OAAO,CAACU,MAAM,qDAAd,sBAAAV,OAAO,EAAUa,CAAC,CAAC;MACrB;IACF,CAAC;IACDF,KAAK,EAAGE,CAAC,IAAK;MACZ,SAAS;;MAET,IAAInB,kCAAkC,EAAE;QAAA;QACtC,mBAAAM,OAAO,CAACW,KAAK,oDAAb,qBAAAX,OAAO,EAASa,CAAC,CAAC;MACpB;MAEAV,eAAe,CAACG,KAAK,GAAGO,CAAC,CAACN,MAAM;IAClC;EACF,CAAC,EACDN,IAAI,CACL;AACH,CAAC"}
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","persistedHeight","animatedKeyboardHeight","event","value","height","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\";\nimport {\n Easing,\n useAnimatedReaction,\n useSharedValue,\n withTiming,\n} from \"react-native-reanimated\";\n\nimport { useKeyboardHandler } from \"react-native-keyboard-controller\";\n\nconst IS_ANDROID_ELEVEN_OR_HIGHER =\n Platform.OS === \"android\" && Platform.Version >= 30;\n// on these platforms keyboard transitions will be smooth\nconst IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS =\n IS_ANDROID_ELEVEN_OR_HIGHER || Platform.OS === \"ios\";\n// on Android Telegram is not using androidx.core values and uses custom interpolation\n// duration is taken from here: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/AdjustPanLayoutHelper.java#L39\n// and bezier is taken from: https://github.com/DrKLO/Telegram/blob/e9a35cea54c06277c69d41b8e25d94b5d7ede065/TMessagesProj/src/main/java/androidx/recyclerview/widget/ChatListItemAnimator.java#L40\nconst TELEGRAM_ANDROID_TIMING_CONFIG = {\n duration: 250,\n easing: Easing.bezier(\n 0.19919472913616398,\n 0.010644531250000006,\n 0.27920937042459737,\n 0.91025390625,\n ),\n};\n\n/**\n * Hook that uses default transitions for iOS and Android > 11, and uses\n * custom interpolation on Android < 11 to achieve more smooth animation\n */\nexport const useSmoothKeyboardHandler: typeof useKeyboardHandler = (\n handler,\n deps,\n) => {\n const target = useSharedValue(-1);\n const persistedHeight = useSharedValue(0);\n const animatedKeyboardHeight = useSharedValue(0);\n\n useAnimatedReaction(\n () => {\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n return;\n }\n const event = {\n // it'll be always 250, since we're running animation via `withTiming` where\n // duration in config (TELEGRAM_ANDROID_TIMING_CONFIG.duration) = 250ms\n duration: 250,\n target: target.value,\n height: animatedKeyboardHeight.value,\n progress: animatedKeyboardHeight.value / persistedHeight.value,\n };\n return event;\n },\n (evt) => {\n if (!evt) {\n return;\n }\n handler.onMove?.(evt);\n\n // dispatch `onEnd`\n if (evt.height === persistedHeight.value) {\n handler.onEnd?.(evt);\n }\n },\n [handler],\n );\n\n useKeyboardHandler(\n {\n onStart: (e) => {\n \"worklet\";\n\n // immediately dispatch onStart/onEnd events if onStart dispatched with the same height\n // and don't wait for animation 250ms\n if (\n !IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS &&\n e.height === persistedHeight.value\n ) {\n handler.onStart?.(e);\n handler.onEnd?.(e);\n\n return;\n }\n\n target.value = e.target;\n\n if (e.height > 0) {\n persistedHeight.value = e.height;\n }\n // if we are running on Android < 9, then we are using custom interpolation\n // to achieve smoother animation and use `animatedKeyboardHeight` as animation\n // driver\n if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n animatedKeyboardHeight.value = withTiming(\n e.height,\n TELEGRAM_ANDROID_TIMING_CONFIG,\n );\n }\n\n handler.onStart?.(e);\n },\n onMove: (e) => {\n \"worklet\";\n\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n handler.onMove?.(e);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {\n handler.onEnd?.(e);\n }\n\n persistedHeight.value = e.height;\n },\n },\n deps,\n );\n};\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SACEC,MAAM,EACNC,mBAAmB,EACnBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAEhC,SAASC,kBAAkB,QAAQ,kCAAkC;AAErE,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;AACtD;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,w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';
2
+ "worklet";
3
3
 
4
4
  let wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
5
5
  const value = {
6
6
  time: 0
7
7
  };
8
8
  return function () {
9
- 'worklet';
9
+ "worklet";
10
10
 
11
11
  const t = Date.now();
12
12
  const now = t - value.time;
@@ -1 +1 @@
1
- {"version":3,"names":["debounce","worklet","wait","value","time","t","Date","now"],"sources":["utils.ts"],"sourcesContent":["export const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(\n worklet: F,\n wait = 0\n) => {\n 'worklet';\n\n const value = {\n time: 0,\n };\n\n return (...args: Parameters<F>): ReturnType<F> | void => {\n 'worklet';\n\n const t = Date.now();\n const now = t - value.time;\n\n if (now < wait) {\n value.time = t;\n return;\n }\n\n value.time = t;\n\n return worklet(...args);\n };\n};\n"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,GAAG,UACtBC,OAAU,EAEP;EACH,SAAS;;EAAC,IAFVC,IAAI,uEAAG,CAAC;EAIR,MAAMC,KAAK,GAAG;IACZC,IAAI,EAAE;EACR,CAAC;EAED,OAAO,YAAkD;IACvD,SAAS;;IAET,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,EAAE;IACpB,MAAMA,GAAG,GAAGF,CAAC,GAAGF,KAAK,CAACC,IAAI;IAE1B,IAAIG,GAAG,GAAGL,IAAI,EAAE;MACdC,KAAK,CAACC,IAAI,GAAGC,CAAC;MACd;IACF;IAEAF,KAAK,CAACC,IAAI,GAAGC,CAAC;IAEd,OAAOJ,OAAO,CAAC,YAAO,CAAC;EACzB,CAAC;AACH,CAAC"}
1
+ {"version":3,"names":["debounce","worklet","wait","arguments","length","undefined","value","time","t","Date","now"],"sources":["utils.ts"],"sourcesContent":["export const debounce = <F extends (...args: Parameters<F>) => ReturnType<F>>(\n worklet: F,\n wait = 0,\n) => {\n \"worklet\";\n\n const value = {\n time: 0,\n };\n\n return (...args: Parameters<F>): ReturnType<F> | void => {\n \"worklet\";\n\n const t = Date.now();\n const now = t - value.time;\n\n if (now < wait) {\n value.time = t;\n return;\n }\n\n value.time = t;\n\n return worklet(...args);\n };\n};\n"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,GAAG,SAAAA,CACtBC,OAAU,EAEP;EACH,SAAS;;EAAC,IAFVC,IAAI,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAIR,MAAMG,KAAK,GAAG;IACZC,IAAI,EAAE;EACR,CAAC;EAED,OAAO,YAAkD;IACvD,SAAS;;IAET,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;IACpB,MAAMA,GAAG,GAAGF,CAAC,GAAGF,KAAK,CAACC,IAAI;IAE1B,IAAIG,GAAG,GAAGR,IAAI,EAAE;MACdI,KAAK,CAACC,IAAI,GAAGC,CAAC;MACd;IACF;IAEAF,KAAK,CAACC,IAAI,GAAGC,CAAC;IAEd,OAAOP,OAAO,CAAC,GAAAE,SAAO,CAAC;EACzB,CAAC;AACH,CAAC"}
@@ -1,7 +1,8 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { forwardRef, useMemo } from 'react';
3
- import Reanimated, { interpolate, useAnimatedStyle } from 'react-native-reanimated';
4
- import { useReanimatedKeyboardAnimation } from '../../hooks';
2
+ import React, { forwardRef, useMemo } from "react";
3
+ import Reanimated, { useAnimatedStyle } from "react-native-reanimated";
4
+ import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller";
5
+ import useKeyboardInterpolation from "../hooks/useKeyboardInterpolation";
5
6
  const KeyboardStickyView = /*#__PURE__*/forwardRef((_ref, ref) => {
6
7
  let {
7
8
  children,
@@ -13,11 +14,13 @@ const KeyboardStickyView = /*#__PURE__*/forwardRef((_ref, ref) => {
13
14
  ...props
14
15
  } = _ref;
15
16
  const {
16
- height,
17
- progress
17
+ height
18
18
  } = useReanimatedKeyboardAnimation();
19
+ const {
20
+ interpolate
21
+ } = useKeyboardInterpolation();
19
22
  const stickyViewStyle = useAnimatedStyle(() => {
20
- const offset = interpolate(progress.value, [0, 1], [closed, opened]);
23
+ const offset = interpolate(-height.value, [closed, opened]);
21
24
  return {
22
25
  transform: [{
23
26
  translateY: height.value + offset
@@ -1 +1 @@
1
- {"version":3,"names":["React","forwardRef","useMemo","Reanimated","interpolate","useAnimatedStyle","useReanimatedKeyboardAnimation","KeyboardStickyView","ref","children","offset","closed","opened","style","props","height","progress","stickyViewStyle","value","transform","translateY","styles"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useMemo } from 'react';\nimport Reanimated, {\n interpolate,\n useAnimatedStyle,\n} from 'react-native-reanimated';\n\nimport { useReanimatedKeyboardAnimation } from '../../hooks';\n\nimport type { View, ViewProps } from 'react-native';\n\ntype KeyboardStickyViewProps = {\n /**\n * Specify additional offset to the view for given keyboard state.\n */\n offset?: {\n /**\n * Adds additional `translateY` when keyboard is close. By default `0`.\n */\n closed?: number;\n /**\n * Adds additional `translateY` when keyboard is open. By default `0`.\n */\n opened?: number;\n };\n} & ViewProps;\n\nconst KeyboardStickyView = forwardRef<\n View,\n React.PropsWithChildren<KeyboardStickyViewProps>\n>(\n (\n { children, offset: { closed = 0, opened = 0 } = {}, style, ...props },\n ref\n ) => {\n const { height, progress } = useReanimatedKeyboardAnimation();\n\n const stickyViewStyle = useAnimatedStyle(() => {\n const offset = interpolate(progress.value, [0, 1], [closed, opened]);\n\n return {\n transform: [{ translateY: height.value + offset }],\n };\n }, [closed, opened]);\n\n const styles = useMemo(\n () => [style, stickyViewStyle],\n [style, stickyViewStyle]\n );\n\n return (\n <Reanimated.View ref={ref} style={styles} {...props}>\n {children}\n </Reanimated.View>\n );\n }\n);\n\nexport default KeyboardStickyView;\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,OAEEO,GAAG,KACA;EAAA,IAFH;IAAEC,QAAQ;IAAEC,MAAM,EAAE;MAAEC,MAAM,GAAG,CAAC;MAAEC,MAAM,GAAG;IAAE,CAAC,GAAG,CAAC,CAAC;IAAEC,KAAK;IAAE,GAAGC;EAAM,CAAC;EAGtE,MAAM;IAAEC,MAAM;IAAEC;EAAS,CAAC,GAAGV,8BAA8B,EAAE;EAE7D,MAAMW,eAAe,GAAGZ,gBAAgB,CAAC,MAAM;IAC7C,MAAMK,MAAM,GAAGN,WAAW,CAACY,QAAQ,CAACE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAACP,MAAM,EAAEC,MAAM,CAAC,CAAC;IAEpE,OAAO;MACLO,SAAS,EAAE,CAAC;QAAEC,UAAU,EAAEL,MAAM,CAACG,KAAK,GAAGR;MAAO,CAAC;IACnD,CAAC;EACH,CAAC,EAAE,CAACC,MAAM,EAAEC,MAAM,CAAC,CAAC;EAEpB,MAAMS,MAAM,GAAGnB,OAAO,CACpB,MAAM,CAACW,KAAK,EAAEI,eAAe,CAAC,EAC9B,CAACJ,KAAK,EAAEI,eAAe,CAAC,CACzB;EAED,oBACE,oBAAC,UAAU,CAAC,IAAI;IAAC,GAAG,EAAET,GAAI;IAAC,KAAK,EAAEa;EAAO,GAAKP,KAAK,GAChDL,QAAQ,CACO;AAEtB,CAAC,CACF;AAED,eAAeF,kBAAkB"}
1
+ {"version":3,"names":["React","forwardRef","useMemo","Reanimated","useAnimatedStyle","useReanimatedKeyboardAnimation","useKeyboardInterpolation","KeyboardStickyView","_ref","ref","children","offset","closed","opened","style","props","height","interpolate","stickyViewStyle","value","transform","translateY","styles","createElement","View","_extends"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, useMemo } from \"react\";\nimport Reanimated, { useAnimatedStyle } from \"react-native-reanimated\";\n\nimport { useReanimatedKeyboardAnimation } from \"react-native-keyboard-controller\";\n\nimport useKeyboardInterpolation from \"../hooks/useKeyboardInterpolation\";\n\nimport type { View, ViewProps } from \"react-native\";\n\ntype KeyboardStickyViewProps = {\n /**\n * Specify additional offset to the view for given keyboard state.\n */\n offset?: {\n /**\n * Adds additional `translateY` when keyboard is close. By default `0`.\n */\n closed?: number;\n /**\n * Adds additional `translateY` when keyboard is open. By default `0`.\n */\n opened?: number;\n };\n} & ViewProps;\n\nconst KeyboardStickyView = forwardRef<\n View,\n React.PropsWithChildren<KeyboardStickyViewProps>\n>(\n (\n { children, offset: { closed = 0, opened = 0 } = {}, style, ...props },\n ref,\n ) => {\n const { height } = useReanimatedKeyboardAnimation();\n const { interpolate } = useKeyboardInterpolation();\n\n const stickyViewStyle = useAnimatedStyle(() => {\n const offset = interpolate(-height.value, [closed, opened]);\n\n return {\n transform: [{ translateY: height.value + offset }],\n };\n }, [closed, opened]);\n\n const styles = useMemo(\n () => [style, stickyViewStyle],\n [style, stickyViewStyle],\n );\n\n return (\n <Reanimated.View ref={ref} style={styles} {...props}>\n {children}\n </Reanimated.View>\n );\n },\n);\n\nexport default KeyboardStickyView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAClD,OAAOC,UAAU,IAAIC,gBAAgB,QAAQ,yBAAyB;AAEtE,SAASC,8BAA8B,QAAQ,kCAAkC;AAEjF,OAAOC,wBAAwB,MAAM,mCAAmC;AAoBxE,MAAMC,kBAAkB,gBAAGN,UAAU,CAInC,CAAAO,IAAA,EAEEC,GAAG,KACA;EAAA,IAFH;IAAEC,QAAQ;IAAEC,MAAM,EAAE;MAAEC,MAAM,GAAG,CAAC;MAAEC,MAAM,GAAG;IAAE,CAAC,GAAG,CAAC,CAAC;IAAEC,KAAK;IAAE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