react-native-keyboard-controller 1.10.3 → 1.10.4
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.
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +18 -4
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +13 -6
- package/lib/commonjs/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/index.js +19 -5
- package/lib/module/components/KeyboardAwareScrollView/index.js.map +1 -1
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js +13 -6
- package/lib/module/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.js.map +1 -1
- package/lib/typescript/components/KeyboardAwareScrollView/index.d.ts +8 -7
- package/package.json +1 -1
- package/src/components/KeyboardAwareScrollView/index.tsx +216 -192
- package/src/components/KeyboardAwareScrollView/useSmoothKeyboardHandler.ts +15 -7
|
@@ -51,7 +51,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
51
51
|
* +============================+ +============================+ +=====================================+
|
|
52
52
|
*
|
|
53
53
|
*/
|
|
54
|
-
const KeyboardAwareScrollView = _ref => {
|
|
54
|
+
const KeyboardAwareScrollView = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
55
55
|
let {
|
|
56
56
|
children,
|
|
57
57
|
bottomOffset = 0,
|
|
@@ -79,6 +79,14 @@ const KeyboardAwareScrollView = _ref => {
|
|
|
79
79
|
position.value = e.contentOffset.y;
|
|
80
80
|
}
|
|
81
81
|
}, []);
|
|
82
|
+
const onRef = (0, _react.useCallback)(assignedRef => {
|
|
83
|
+
if (typeof ref === "function") {
|
|
84
|
+
ref(assignedRef);
|
|
85
|
+
} else if (ref) {
|
|
86
|
+
ref.current = assignedRef;
|
|
87
|
+
}
|
|
88
|
+
scrollViewAnimatedRef(assignedRef);
|
|
89
|
+
}, []);
|
|
82
90
|
|
|
83
91
|
/**
|
|
84
92
|
* Function that will scroll a ScrollView as keyboard gets moving
|
|
@@ -191,10 +199,16 @@ const KeyboardAwareScrollView = _ref => {
|
|
|
191
199
|
}
|
|
192
200
|
}, []);
|
|
193
201
|
const view = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
|
|
194
|
-
|
|
202
|
+
// animations become laggy when scrolling to the end of the `ScrollView` (when the last input is focused)
|
|
203
|
+
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
|
|
204
|
+
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
|
|
205
|
+
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
|
|
206
|
+
// re-calculation on every animation frame and it helps to achieve smooth animation.
|
|
207
|
+
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
|
|
208
|
+
paddingBottom: currentKeyboardFrameHeight.value + 1
|
|
195
209
|
}), []);
|
|
196
210
|
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.ScrollView, _extends({
|
|
197
|
-
ref:
|
|
211
|
+
ref: onRef
|
|
198
212
|
}, rest, {
|
|
199
213
|
// @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events
|
|
200
214
|
onScrollReanimated: onScroll,
|
|
@@ -202,7 +216,7 @@ const KeyboardAwareScrollView = _ref => {
|
|
|
202
216
|
}), children, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
203
217
|
style: view
|
|
204
218
|
}));
|
|
205
|
-
};
|
|
219
|
+
});
|
|
206
220
|
var _default = KeyboardAwareScrollView;
|
|
207
221
|
exports.default = _default;
|
|
208
222
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_reactNativeKeyboardController","_useSmoothKeyboardHandler","_utils","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","bind","target","i","arguments","length","source","apply","KeyboardAwareScrollView","_ref","children","bottomOffset","disableScrollOnKeyboardHide","rest","scrollViewAnimatedRef","useAnimatedRef","scrollPosition","useSharedValue","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","useReanimatedFocusedInput","layout","height","useWindowDimensions","onScroll","useAnimatedScrollHandler","e","value","contentOffset","y","maybeScroll","useCallback","_layout$value","_layout$value2","animated","undefined","visibleRect","absoluteY","inputHeight","point","interpolatedScrollTo","interpolate","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","onChangeText","_layout$value3","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","onMove","onEnd","useAnimatedReaction","current","previous","view","useAnimatedStyle","paddingBottom","createElement","ScrollView","ref","onScrollReanimated","scrollEventThrottle","View","style","_default","exports"],"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 /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\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 disableScrollOnKeyboardHide = false,\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 keyboardWillAppear = useSharedValue(false);\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 keyboardWillAppear.value = 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 (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\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.value) {\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 // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [height, maybeScroll, disableScrollOnKeyboardHide],\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 // @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events\n onScrollReanimated={onScroll}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n};\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AAUA,IAAAG,8BAAA,GAAAH,OAAA;AAKA,IAAAI,yBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAAmC,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAR,wBAAAY,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,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Ae,OAAA,CAAA4F,aAAA,CAACvG,sBAAA,CAAAW,OAAU,CAACiG,IAAI;IAACC,KAAK,EAAET;EAAK,CAAE,CACV,CAAC;AAE5B,CAAC;AAAC,IAAAU,QAAA,GAEa3E,uBAAuB;AAAA4E,OAAA,CAAApG,OAAA,GAAAmG,QAAA"}
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_reactNativeKeyboardController","_useSmoothKeyboardHandler","_utils","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","bind","target","i","arguments","length","source","apply","KeyboardAwareScrollView","forwardRef","_ref","ref","children","bottomOffset","disableScrollOnKeyboardHide","rest","scrollViewAnimatedRef","useAnimatedRef","scrollPosition","useSharedValue","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","useReanimatedFocusedInput","layout","height","useWindowDimensions","onScroll","useAnimatedScrollHandler","e","value","contentOffset","y","onRef","useCallback","assignedRef","current","maybeScroll","_layout$value","_layout$value2","animated","undefined","visibleRect","absoluteY","inputHeight","point","interpolatedScrollTo","interpolate","targetScrollY","Math","max","scrollTo","positionOnScreen","topOfScreen","onChangeText","_layout$value3","_input$value","prevScrollPosition","prevLayout","onChangeTextHandler","useMemo","debounce","useFocusedInputHandler","useSmoothKeyboardHandler","onStart","keyboardWillChangeSize","keyboardWillHide","focusWasChanged","onMove","onEnd","useAnimatedReaction","previous","view","useAnimatedStyle","paddingBottom","createElement","ScrollView","onScrollReanimated","scrollEventThrottle","View","style","_default","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, 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 { ScrollView, ScrollViewProps } from \"react-native\";\nimport type { FocusedInputLayoutChangedEvent } from \"react-native-keyboard-controller\";\n\ntype KeyboardAwareScrollViewProps = {\n /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\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 = forwardRef<\n ScrollView,\n React.PropsWithChildren<KeyboardAwareScrollViewProps>\n>(\n (\n {\n children,\n bottomOffset = 0,\n disableScrollOnKeyboardHide = false,\n ...rest\n },\n ref,\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 keyboardWillAppear = useSharedValue(false);\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 const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {\n if (typeof ref === \"function\") {\n ref(assignedRef);\n } else if (ref) {\n ref.current = assignedRef;\n }\n\n scrollViewAnimatedRef(assignedRef);\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 keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) ||\n 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 (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\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.value) {\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 // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [height, maybeScroll, disableScrollOnKeyboardHide],\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 // animations become laggy when scrolling to the end of the `ScrollView` (when the last input is focused)\n // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding\n // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation\n // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout\n // re-calculation on every animation frame and it helps to achieve smooth animation.\n // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342\n paddingBottom: currentKeyboardFrameHeight.value + 1,\n }),\n [],\n );\n\n return (\n <Reanimated.ScrollView\n ref={onRef}\n {...rest}\n // @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events\n onScrollReanimated={onScroll}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView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C;AAE5B,CACF,CAAC;AAAC,IAAAS,QAAA,GAEa9E,uBAAuB;AAAA+E,OAAA,CAAAvG,OAAA,GAAAsG,QAAA"}
|
|
@@ -24,16 +24,19 @@ const TELEGRAM_ANDROID_TIMING_CONFIG = {
|
|
|
24
24
|
*/
|
|
25
25
|
const useSmoothKeyboardHandler = (handler, deps) => {
|
|
26
26
|
const target = (0, _reactNativeReanimated.useSharedValue)(-1);
|
|
27
|
+
const height = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
27
28
|
const persistedHeight = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
28
29
|
const animatedKeyboardHeight = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
29
30
|
(0, _reactNativeReanimated.useAnimatedReaction)(() => {
|
|
30
31
|
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
34
|
+
if (persistedHeight.value === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
33
37
|
const event = {
|
|
34
|
-
// it'll be always
|
|
35
|
-
|
|
36
|
-
duration: 250,
|
|
38
|
+
// it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`
|
|
39
|
+
duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
|
|
37
40
|
target: target.value,
|
|
38
41
|
height: animatedKeyboardHeight.value,
|
|
39
42
|
progress: animatedKeyboardHeight.value / persistedHeight.value
|
|
@@ -47,9 +50,10 @@ const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
47
50
|
(_handler$onMove = handler.onMove) === null || _handler$onMove === void 0 ? void 0 : _handler$onMove.call(handler, evt);
|
|
48
51
|
|
|
49
52
|
// dispatch `onEnd`
|
|
50
|
-
if (evt.height ===
|
|
53
|
+
if (evt.height === height.value) {
|
|
51
54
|
var _handler$onEnd;
|
|
52
55
|
(_handler$onEnd = handler.onEnd) === null || _handler$onEnd === void 0 ? void 0 : _handler$onEnd.call(handler, evt);
|
|
56
|
+
persistedHeight.value = height.value;
|
|
53
57
|
}
|
|
54
58
|
}, [handler]);
|
|
55
59
|
(0, _reactNativeKeyboardController.useKeyboardHandler)({
|
|
@@ -66,6 +70,7 @@ const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
66
70
|
return;
|
|
67
71
|
}
|
|
68
72
|
target.value = e.target;
|
|
73
|
+
height.value = e.height;
|
|
69
74
|
if (e.height > 0) {
|
|
70
75
|
persistedHeight.value = e.height;
|
|
71
76
|
}
|
|
@@ -75,7 +80,10 @@ const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
75
80
|
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
76
81
|
animatedKeyboardHeight.value = (0, _reactNativeReanimated.withTiming)(e.height, TELEGRAM_ANDROID_TIMING_CONFIG);
|
|
77
82
|
}
|
|
78
|
-
(_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 ? void 0 : _handler$onStart2.call(handler,
|
|
83
|
+
(_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 ? void 0 : _handler$onStart2.call(handler, {
|
|
84
|
+
...e,
|
|
85
|
+
duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS ? e.duration : TELEGRAM_ANDROID_TIMING_CONFIG.duration
|
|
86
|
+
});
|
|
79
87
|
},
|
|
80
88
|
onMove: e => {
|
|
81
89
|
"worklet";
|
|
@@ -92,7 +100,6 @@ const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
92
100
|
var _handler$onEnd3;
|
|
93
101
|
(_handler$onEnd3 = handler.onEnd) === null || _handler$onEnd3 === void 0 ? void 0 : _handler$onEnd3.call(handler, e);
|
|
94
102
|
}
|
|
95
|
-
persistedHeight.value = e.height;
|
|
96
103
|
}
|
|
97
104
|
}, deps);
|
|
98
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_reactNativeReanimated","_reactNativeKeyboardController","IS_ANDROID_ELEVEN_OR_HIGHER","Platform","OS","Version","IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS","TELEGRAM_ANDROID_TIMING_CONFIG","duration","easing","Easing","bezier","useSmoothKeyboardHandler","handler","deps","target","useSharedValue","persistedHeight","animatedKeyboardHeight","useAnimatedReaction","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_reactNativeReanimated","_reactNativeKeyboardController","IS_ANDROID_ELEVEN_OR_HIGHER","Platform","OS","Version","IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS","TELEGRAM_ANDROID_TIMING_CONFIG","duration","easing","Easing","bezier","useSmoothKeyboardHandler","handler","deps","target","useSharedValue","height","persistedHeight","animatedKeyboardHeight","useAnimatedReaction","value","event","progress","evt","_handler$onMove","onMove","call","_handler$onEnd","onEnd","useKeyboardHandler","onStart","e","_handler$onStart2","_handler$onStart","_handler$onEnd2","withTiming","_handler$onMove2","_handler$onEnd3","exports"],"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 height = useSharedValue(0);\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 if (persistedHeight.value === 0) {\n return;\n }\n const event = {\n // it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`\n duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,\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 === height.value) {\n handler.onEnd?.(evt);\n persistedHeight.value = height.value;\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 height.value = e.height;\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?.({\n ...e,\n duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS\n ? e.duration\n : TELEGRAM_ANDROID_TIMING_CONFIG.duration,\n });\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 },\n deps,\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AAOA,IAAAE,8BAAA,GAAAF,OAAA;AAEA,MAAMG,2BAA2B,GAC/BC,qBAAQ,CAACC,EAAE,KAAK,SAAS,IAAID,qBAAQ,CAACE,OAAO,IAAI,EAAE;AACrD;AACA,MAAMC,kCAAkC,GACtCJ,2BAA2B,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK;AACtD;AACA;AACA;AACA,MAAMG,8BAA8B,GAAG;EACrCC,QAAQ,EAAE,GAAG;EACbC,MAAM,EAAEC,6BAAM,CAACC,MAAM,CACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,aACF;AACF,CAAC;;AAED;AACA;AACA;AACA;AACO,MAAMC,wBAAmD,GAAGA,CACjEC,OAAO,EACPC,IAAI,KACD;EACH,MAAMC,MAAM,GAAG,IAAAC,qCAAc,EAAC,CAAC,CAAC,CAAC;EACjC,MAAMC,MAAM,GAAG,IAAAD,qCAAc,EAAC,CAAC,CAAC;EAChC,MAAME,eAAe,GAAG,IAAAF,qCAAc,EAAC,CAAC,CAAC;EACzC,MAAMG,sBAAsB,GAAG,IAAAH,qCAAc,EAAC,CAAC,CAAC;EAEhD,IAAAI,0CAAmB,EACjB,MAAM;IACJ,IAAId,kCAAkC,EAAE;MACtC;IACF;IACA,IAAIY,eAAe,CAACG,KAAK,KAAK,CAAC,EAAE;MAC/B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MAEAjB,MAAM,CAACM,KAAK,GAAGW,CAAC,CAACjB,MAAM;MACvBE,MAAM,CAACI,KAAK,GAAGW,CAAC,CAACf,MAAM;MAEvB,IAAIe,CAAC,CAACf,MAAM,GAAG,CAAC,EAAE;QAChBC,eAAe,CAACG,KAAK,GAAGW,CAAC,CAACf,MAAM;MAClC;MACA;MACA;MACA;MACA,IAAI,CAACX,kCAAkC,EAAE;QACvCa,sBAAsB,CAACE,KAAK,GAAG,IAAAe,iCAAU,EACvCJ,CAAC,CAACf,MAAM,EACRV,8BACF,CAAC;MACH;MAEA,CAAA0B,iBAAA,GAAApB,OAAO,CAACkB,OAAO,cAAAE,iBAAA,uBAAfA,iBAAA,CAAAN,IAAA,CAAAd,OAAO,EAAW;QAChB,GAAGmB,CAAC;QACJxB,QAAQ,EAAEF,kCAAkC,GACxC0B,CAAC,CAACxB,QAAQ,GACVD,8BAA8B,CAACC;MACrC,CAAC,CAAC;IACJ,CAAC;IACDkB,MAAM,EAAGM,CAAC,IAAK;MACb,SAAS;;MAET,IAAI1B,kCAAkC,EAAE;QAAA,IAAA+B,gBAAA;QACtC,CAAAA,gBAAA,GAAAxB,OAAO,CAACa,MAAM,cAAAW,gBAAA,uBAAdA,gBAAA,CAAAV,IAAA,CAAAd,OAAO,EAAUmB,CAAC,CAAC;MACrB;IACF,CAAC;IACDH,KAAK,EAAGG,CAAC,IAAK;MACZ,SAAS;;MAET,IAAI1B,kCAAkC,EAAE;QAAA,IAAAgC,eAAA;QACtC,CAAAA,eAAA,GAAAzB,OAAO,CAACgB,KAAK,cAAAS,eAAA,uBAAbA,eAAA,CAAAX,IAAA,CAAAd,OAAO,EAASmB,CAAC,CAAC;MACpB;IACF;EACF,CAAC,EACDlB,IACF,CAAC;AACH,CAAC;AAACyB,OAAA,CAAA3B,wBAAA,GAAAA,wBAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
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";
|
|
2
|
+
import React, { forwardRef, useCallback, useMemo } from "react";
|
|
3
3
|
import { useWindowDimensions } from "react-native";
|
|
4
4
|
import Reanimated, { interpolate, scrollTo, useAnimatedReaction, useAnimatedRef, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue } from "react-native-reanimated";
|
|
5
5
|
import { useFocusedInputHandler, useReanimatedFocusedInput } from "react-native-keyboard-controller";
|
|
@@ -43,7 +43,7 @@ import { debounce } from "./utils";
|
|
|
43
43
|
* +============================+ +============================+ +=====================================+
|
|
44
44
|
*
|
|
45
45
|
*/
|
|
46
|
-
const KeyboardAwareScrollView = _ref => {
|
|
46
|
+
const KeyboardAwareScrollView = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
47
47
|
let {
|
|
48
48
|
children,
|
|
49
49
|
bottomOffset = 0,
|
|
@@ -71,6 +71,14 @@ const KeyboardAwareScrollView = _ref => {
|
|
|
71
71
|
position.value = e.contentOffset.y;
|
|
72
72
|
}
|
|
73
73
|
}, []);
|
|
74
|
+
const onRef = useCallback(assignedRef => {
|
|
75
|
+
if (typeof ref === "function") {
|
|
76
|
+
ref(assignedRef);
|
|
77
|
+
} else if (ref) {
|
|
78
|
+
ref.current = assignedRef;
|
|
79
|
+
}
|
|
80
|
+
scrollViewAnimatedRef(assignedRef);
|
|
81
|
+
}, []);
|
|
74
82
|
|
|
75
83
|
/**
|
|
76
84
|
* Function that will scroll a ScrollView as keyboard gets moving
|
|
@@ -183,10 +191,16 @@ const KeyboardAwareScrollView = _ref => {
|
|
|
183
191
|
}
|
|
184
192
|
}, []);
|
|
185
193
|
const view = useAnimatedStyle(() => ({
|
|
186
|
-
|
|
194
|
+
// animations become laggy when scrolling to the end of the `ScrollView` (when the last input is focused)
|
|
195
|
+
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
|
|
196
|
+
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
|
|
197
|
+
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
|
|
198
|
+
// re-calculation on every animation frame and it helps to achieve smooth animation.
|
|
199
|
+
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
|
|
200
|
+
paddingBottom: currentKeyboardFrameHeight.value + 1
|
|
187
201
|
}), []);
|
|
188
202
|
return /*#__PURE__*/React.createElement(Reanimated.ScrollView, _extends({
|
|
189
|
-
ref:
|
|
203
|
+
ref: onRef
|
|
190
204
|
}, rest, {
|
|
191
205
|
// @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events
|
|
192
206
|
onScrollReanimated: onScroll,
|
|
@@ -194,6 +208,6 @@ const KeyboardAwareScrollView = _ref => {
|
|
|
194
208
|
}), children, /*#__PURE__*/React.createElement(Reanimated.View, {
|
|
195
209
|
style: view
|
|
196
210
|
}));
|
|
197
|
-
};
|
|
211
|
+
});
|
|
198
212
|
export default KeyboardAwareScrollView;
|
|
199
213
|
//# 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","_ref","children","bottomOffset","disableScrollOnKeyboardHide","rest","scrollViewAnimatedRef","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","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","keyboardWillHide","focusWasChanged","target","onMove","onEnd","current","previous","view","paddingBottom","createElement","ScrollView","_extends","ref","onScrollReanimated","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 /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\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 disableScrollOnKeyboardHide = false,\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 keyboardWillAppear = useSharedValue(false);\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 keyboardWillAppear.value = 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 (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\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.value) {\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 // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [height, maybeScroll, disableScrollOnKeyboardHide],\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 // @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events\n onScrollReanimated={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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5C,CAAC,CAAC,EACF,EACF,CAAC;EAED,oBACEpC,KAAA,CAAAyE,aAAA,CAACrE,UAAU,CAACsE,UAAU,EAAAC,QAAA;IACpBC,GAAG,EAAEtD;EAAsB,GACvBD,IAAI;IACR;IACAwD,kBAAkB,EAAE3C,QAAS;IAC7B4C,mBAAmB,EAAE;EAAG,IAEvB5D,QAAQ,eACTlB,KAAA,CAAAyE,aAAA,CAACrE,UAAU,CAAC2E,IAAI;IAACC,KAAK,EAAET;EAAK,CAAE,CACV,CAAC;AAE5B,CAAC;AAED,eAAevD,uBAAuB"}
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useCallback","useMemo","useWindowDimensions","Reanimated","interpolate","scrollTo","useAnimatedReaction","useAnimatedRef","useAnimatedScrollHandler","useAnimatedStyle","useSharedValue","useFocusedInputHandler","useReanimatedFocusedInput","useSmoothKeyboardHandler","debounce","KeyboardAwareScrollView","_ref","ref","children","bottomOffset","disableScrollOnKeyboardHide","rest","scrollViewAnimatedRef","scrollPosition","position","currentKeyboardFrameHeight","keyboardHeight","keyboardWillAppear","tag","initialKeyboardSize","scrollBeforeKeyboardMovement","input","layout","height","onScroll","e","value","contentOffset","y","onRef","assignedRef","current","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","keyboardWillHide","focusWasChanged","target","onMove","onEnd","previous","view","paddingBottom","createElement","ScrollView","_extends","onScrollReanimated","scrollEventThrottle","View","style"],"sources":["index.tsx"],"sourcesContent":["import React, { forwardRef, 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 { ScrollView, ScrollViewProps } from \"react-native\";\nimport type { FocusedInputLayoutChangedEvent } from \"react-native-keyboard-controller\";\n\ntype KeyboardAwareScrollViewProps = {\n /** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */\n bottomOffset?: number;\n /** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */\n disableScrollOnKeyboardHide?: boolean;\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 = forwardRef<\n ScrollView,\n React.PropsWithChildren<KeyboardAwareScrollViewProps>\n>(\n (\n {\n children,\n bottomOffset = 0,\n disableScrollOnKeyboardHide = false,\n ...rest\n },\n ref,\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 keyboardWillAppear = useSharedValue(false);\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 const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {\n if (typeof ref === \"function\") {\n ref(assignedRef);\n } else if (ref) {\n ref.current = assignedRef;\n }\n\n scrollViewAnimatedRef(assignedRef);\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 keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;\n const keyboardWillHide = e.height === 0;\n const focusWasChanged =\n (tag.value !== e.target && e.target !== -1) ||\n 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 (\n keyboardWillAppear.value ||\n keyboardWillChangeSize ||\n focusWasChanged\n ) {\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.value) {\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 // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens\n if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {\n maybeScroll(e.height);\n }\n },\n onEnd: (e) => {\n \"worklet\";\n\n keyboardHeight.value = e.height;\n scrollPosition.value = position.value;\n },\n },\n [height, maybeScroll, disableScrollOnKeyboardHide],\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 // animations become laggy when scrolling to the end of the `ScrollView` (when the last input is focused)\n // this happens because the layout recalculates on every frame. To avoid this we slightly increase padding\n // by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation\n // from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout\n // re-calculation on every animation frame and it helps to achieve smooth animation.\n // see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342\n paddingBottom: currentKeyboardFrameHeight.value + 1,\n }),\n [],\n );\n\n return (\n <Reanimated.ScrollView\n ref={onRef}\n {...rest}\n // @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events\n onScrollReanimated={onScroll}\n scrollEventThrottle={16}\n >\n {children}\n <Reanimated.View style={view} />\n </Reanimated.ScrollView>\n );\n },\n);\n\nexport default KeyboardAwareScrollView;\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,UAA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,aAARA,QAAQ,uBAARA,QAAQ,CAAExC,MAAM,CAACC,MAAM,GAClD;MACA,MAAM8B,UAAU,GAAG/B,MAAM,CAACI,KAAK;MAE/BJ,MAAM,CAACI,KAAK,GAAGL,KAAK,CAACK,KAAK;MAC1Bb,cAAc,CAACa,KAAK,IAAIM,WAAW,CAAChB,cAAc,CAACU,KAAK,EAAE,IAAI,CAAC;MAC/DJ,MAAM,CAACI,KAAK,GAAG2B,UAAU;IAC3B;EACF,CAAC,EACD,EACF,CAAC;EAED,MAAMU,IAAI,GAAGhE,gBAAgB,CAC3B,OAAO;IACL;IACA;IACA;IACA;IACA;IACA;IACAiE,aAAa,EAAEjD,0BAA0B,CAACW,KAAK,GAAG;EACpD,CAAC,CAAC,EACF,EACF,CAAC;EAED,oBACEtC,KAAA,CAAA6E,aAAA,CAACxE,UAAU,CAACyE,UAAU,EAAAC,QAAA;IACpB5D,GAAG,EAAEsB;EAAM,GACPlB,IAAI;IACR;IACAyD,kBAAkB,EAAE5C,QAAS;IAC7B6C,mBAAmB,EAAE;EAAG,IAEvB7D,QAAQ,eACTpB,KAAA,CAAA6E,aAAA,CAACxE,UAAU,CAAC6E,IAAI;IAACC,KAAK,EAAER;EAAK,CAAE,CACV,CAAC;AAE5B,CACF,CAAC;AAED,eAAe1D,uBAAuB"}
|
|
@@ -18,16 +18,19 @@ const TELEGRAM_ANDROID_TIMING_CONFIG = {
|
|
|
18
18
|
*/
|
|
19
19
|
export const useSmoothKeyboardHandler = (handler, deps) => {
|
|
20
20
|
const target = useSharedValue(-1);
|
|
21
|
+
const height = useSharedValue(0);
|
|
21
22
|
const persistedHeight = useSharedValue(0);
|
|
22
23
|
const animatedKeyboardHeight = useSharedValue(0);
|
|
23
24
|
useAnimatedReaction(() => {
|
|
24
25
|
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
28
|
+
if (persistedHeight.value === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
27
31
|
const event = {
|
|
28
|
-
// it'll be always
|
|
29
|
-
|
|
30
|
-
duration: 250,
|
|
32
|
+
// it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`
|
|
33
|
+
duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
|
|
31
34
|
target: target.value,
|
|
32
35
|
height: animatedKeyboardHeight.value,
|
|
33
36
|
progress: animatedKeyboardHeight.value / persistedHeight.value
|
|
@@ -41,9 +44,10 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
41
44
|
(_handler$onMove = handler.onMove) === null || _handler$onMove === void 0 ? void 0 : _handler$onMove.call(handler, evt);
|
|
42
45
|
|
|
43
46
|
// dispatch `onEnd`
|
|
44
|
-
if (evt.height ===
|
|
47
|
+
if (evt.height === height.value) {
|
|
45
48
|
var _handler$onEnd;
|
|
46
49
|
(_handler$onEnd = handler.onEnd) === null || _handler$onEnd === void 0 ? void 0 : _handler$onEnd.call(handler, evt);
|
|
50
|
+
persistedHeight.value = height.value;
|
|
47
51
|
}
|
|
48
52
|
}, [handler]);
|
|
49
53
|
useKeyboardHandler({
|
|
@@ -60,6 +64,7 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
62
66
|
target.value = e.target;
|
|
67
|
+
height.value = e.height;
|
|
63
68
|
if (e.height > 0) {
|
|
64
69
|
persistedHeight.value = e.height;
|
|
65
70
|
}
|
|
@@ -69,7 +74,10 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
69
74
|
if (!IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
70
75
|
animatedKeyboardHeight.value = withTiming(e.height, TELEGRAM_ANDROID_TIMING_CONFIG);
|
|
71
76
|
}
|
|
72
|
-
(_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 ? void 0 : _handler$onStart2.call(handler,
|
|
77
|
+
(_handler$onStart2 = handler.onStart) === null || _handler$onStart2 === void 0 ? void 0 : _handler$onStart2.call(handler, {
|
|
78
|
+
...e,
|
|
79
|
+
duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS ? e.duration : TELEGRAM_ANDROID_TIMING_CONFIG.duration
|
|
80
|
+
});
|
|
73
81
|
},
|
|
74
82
|
onMove: e => {
|
|
75
83
|
"worklet";
|
|
@@ -86,7 +94,6 @@ export const useSmoothKeyboardHandler = (handler, deps) => {
|
|
|
86
94
|
var _handler$onEnd3;
|
|
87
95
|
(_handler$onEnd3 = handler.onEnd) === null || _handler$onEnd3 === void 0 ? void 0 : _handler$onEnd3.call(handler, e);
|
|
88
96
|
}
|
|
89
|
-
persistedHeight.value = e.height;
|
|
90
97
|
}
|
|
91
98
|
}, deps);
|
|
92
99
|
};
|
|
@@ -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","
|
|
1
|
+
{"version":3,"names":["Platform","Easing","useAnimatedReaction","useSharedValue","withTiming","useKeyboardHandler","IS_ANDROID_ELEVEN_OR_HIGHER","OS","Version","IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS","TELEGRAM_ANDROID_TIMING_CONFIG","duration","easing","bezier","useSmoothKeyboardHandler","handler","deps","target","height","persistedHeight","animatedKeyboardHeight","value","event","progress","evt","_handler$onMove","onMove","call","_handler$onEnd","onEnd","onStart","e","_handler$onStart2","_handler$onStart","_handler$onEnd2","_handler$onMove2","_handler$onEnd3"],"sources":["useSmoothKeyboardHandler.ts"],"sourcesContent":["import { Platform } from \"react-native\";\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 height = useSharedValue(0);\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 if (persistedHeight.value === 0) {\n return;\n }\n const event = {\n // it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`\n duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,\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 === height.value) {\n handler.onEnd?.(evt);\n persistedHeight.value = height.value;\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 height.value = e.height;\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?.({\n ...e,\n duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS\n ? e.duration\n : TELEGRAM_ANDROID_TIMING_CONFIG.duration,\n });\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 },\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,M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AAAS,gBAAA,uBAAdA,gBAAA,CAAAR,IAAA,CAAAZ,OAAO,EAAUgB,CAAC,CAAC;MACrB;IACF,CAAC;IACDF,KAAK,EAAGE,CAAC,IAAK;MACZ,SAAS;;MAET,IAAItB,kCAAkC,EAAE;QAAA,IAAA2B,eAAA;QACtC,CAAAA,eAAA,GAAArB,OAAO,CAACc,KAAK,cAAAO,eAAA,uBAAbA,eAAA,CAAAT,IAAA,CAAAZ,OAAO,EAASgB,CAAC,CAAC;MACpB;IACF;EACF,CAAC,EACDf,IACF,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ScrollViewProps } from "react-native";
|
|
3
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ScrollView, ScrollViewProps } from "react-native";
|
|
3
|
+
declare const KeyboardAwareScrollView: React.ForwardRefExoticComponent<{
|
|
4
4
|
/** The distance between keyboard and focused `TextInput` when keyboard is shown. Default is `0`. */
|
|
5
|
-
bottomOffset?: number;
|
|
5
|
+
bottomOffset?: number | undefined;
|
|
6
6
|
/** Prevents automatic scrolling of the `ScrollView` when the keyboard gets hidden, maintaining the current screen position. Default is `false`. */
|
|
7
|
-
disableScrollOnKeyboardHide?: boolean;
|
|
8
|
-
} & ScrollViewProps
|
|
9
|
-
|
|
7
|
+
disableScrollOnKeyboardHide?: boolean | undefined;
|
|
8
|
+
} & ScrollViewProps & {
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
} & React.RefAttributes<ScrollView>>;
|
|
10
11
|
export default KeyboardAwareScrollView;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useMemo } from "react";
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo } from "react";
|
|
2
2
|
import { useWindowDimensions } from "react-native";
|
|
3
3
|
import Reanimated, {
|
|
4
4
|
interpolate,
|
|
@@ -18,8 +18,7 @@ import {
|
|
|
18
18
|
import { useSmoothKeyboardHandler } from "./useSmoothKeyboardHandler";
|
|
19
19
|
import { debounce } from "./utils";
|
|
20
20
|
|
|
21
|
-
import type {
|
|
22
|
-
import type { ScrollViewProps } from "react-native";
|
|
21
|
+
import type { ScrollView, ScrollViewProps } from "react-native";
|
|
23
22
|
import type { FocusedInputLayoutChangedEvent } from "react-native-keyboard-controller";
|
|
24
23
|
|
|
25
24
|
type KeyboardAwareScrollViewProps = {
|
|
@@ -67,213 +66,238 @@ type KeyboardAwareScrollViewProps = {
|
|
|
67
66
|
* +============================+ +============================+ +=====================================+
|
|
68
67
|
*
|
|
69
68
|
*/
|
|
70
|
-
const KeyboardAwareScrollView
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}) => {
|
|
76
|
-
const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();
|
|
77
|
-
const scrollPosition = useSharedValue(0);
|
|
78
|
-
const position = useSharedValue(0);
|
|
79
|
-
const currentKeyboardFrameHeight = useSharedValue(0);
|
|
80
|
-
const keyboardHeight = useSharedValue(0);
|
|
81
|
-
const keyboardWillAppear = useSharedValue(false);
|
|
82
|
-
const tag = useSharedValue(-1);
|
|
83
|
-
const initialKeyboardSize = useSharedValue(0);
|
|
84
|
-
const scrollBeforeKeyboardMovement = useSharedValue(0);
|
|
85
|
-
const { input } = useReanimatedFocusedInput();
|
|
86
|
-
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
|
|
87
|
-
|
|
88
|
-
const { height } = useWindowDimensions();
|
|
89
|
-
|
|
90
|
-
const onScroll = useAnimatedScrollHandler(
|
|
69
|
+
const KeyboardAwareScrollView = forwardRef<
|
|
70
|
+
ScrollView,
|
|
71
|
+
React.PropsWithChildren<KeyboardAwareScrollViewProps>
|
|
72
|
+
>(
|
|
73
|
+
(
|
|
91
74
|
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
75
|
+
children,
|
|
76
|
+
bottomOffset = 0,
|
|
77
|
+
disableScrollOnKeyboardHide = false,
|
|
78
|
+
...rest
|
|
95
79
|
},
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
const topOfScreen = scrollPosition.value + absoluteY;
|
|
127
|
-
|
|
128
|
-
scrollTo(
|
|
129
|
-
scrollViewAnimatedRef,
|
|
130
|
-
0,
|
|
131
|
-
topOfScreen - positionOnScreen,
|
|
132
|
-
animated,
|
|
133
|
-
);
|
|
80
|
+
ref,
|
|
81
|
+
) => {
|
|
82
|
+
const scrollViewAnimatedRef = useAnimatedRef<Reanimated.ScrollView>();
|
|
83
|
+
const scrollPosition = useSharedValue(0);
|
|
84
|
+
const position = useSharedValue(0);
|
|
85
|
+
const currentKeyboardFrameHeight = useSharedValue(0);
|
|
86
|
+
const keyboardHeight = useSharedValue(0);
|
|
87
|
+
const keyboardWillAppear = useSharedValue(false);
|
|
88
|
+
const tag = useSharedValue(-1);
|
|
89
|
+
const initialKeyboardSize = useSharedValue(0);
|
|
90
|
+
const scrollBeforeKeyboardMovement = useSharedValue(0);
|
|
91
|
+
const { input } = useReanimatedFocusedInput();
|
|
92
|
+
const layout = useSharedValue<FocusedInputLayoutChangedEvent | null>(null);
|
|
93
|
+
|
|
94
|
+
const { height } = useWindowDimensions();
|
|
95
|
+
|
|
96
|
+
const onScroll = useAnimatedScrollHandler(
|
|
97
|
+
{
|
|
98
|
+
onScroll: (e) => {
|
|
99
|
+
position.value = e.contentOffset.y;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
[],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const onRef = useCallback((assignedRef: Reanimated.ScrollView) => {
|
|
106
|
+
if (typeof ref === "function") {
|
|
107
|
+
ref(assignedRef);
|
|
108
|
+
} else if (ref) {
|
|
109
|
+
ref.current = assignedRef;
|
|
134
110
|
}
|
|
135
111
|
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
[bottomOffset],
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const onChangeText = useCallback(() => {
|
|
142
|
-
"worklet";
|
|
143
|
-
|
|
144
|
-
// if typing a text caused layout shift, then we need to ignore this handler
|
|
145
|
-
// because this event will be handled in `useAnimatedReaction` below
|
|
146
|
-
if (layout.value?.layout.height !== input.value?.layout.height) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const prevScrollPosition = scrollPosition.value;
|
|
151
|
-
const prevLayout = layout.value;
|
|
152
|
-
|
|
153
|
-
scrollPosition.value = position.value;
|
|
154
|
-
layout.value = input.value;
|
|
155
|
-
maybeScroll(keyboardHeight.value, true);
|
|
156
|
-
scrollPosition.value = prevScrollPosition;
|
|
157
|
-
layout.value = prevLayout;
|
|
158
|
-
}, [maybeScroll]);
|
|
159
|
-
const onChangeTextHandler = useMemo(
|
|
160
|
-
() => debounce(onChangeText, 200),
|
|
161
|
-
[onChangeText],
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
useFocusedInputHandler(
|
|
165
|
-
{
|
|
166
|
-
onChangeText: onChangeTextHandler,
|
|
167
|
-
},
|
|
168
|
-
[onChangeTextHandler],
|
|
169
|
-
);
|
|
112
|
+
scrollViewAnimatedRef(assignedRef);
|
|
113
|
+
}, []);
|
|
170
114
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Function that will scroll a ScrollView as keyboard gets moving
|
|
117
|
+
*/
|
|
118
|
+
const maybeScroll = useCallback(
|
|
119
|
+
(e: number, animated: boolean = false) => {
|
|
174
120
|
"worklet";
|
|
175
121
|
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
122
|
+
const visibleRect = height - keyboardHeight.value;
|
|
123
|
+
const absoluteY = layout.value?.layout.absoluteY || 0;
|
|
124
|
+
const inputHeight = layout.value?.layout.height || 0;
|
|
125
|
+
const point = absoluteY + inputHeight;
|
|
126
|
+
|
|
127
|
+
if (visibleRect - point <= bottomOffset) {
|
|
128
|
+
const interpolatedScrollTo = interpolate(
|
|
129
|
+
e,
|
|
130
|
+
[initialKeyboardSize.value, keyboardHeight.value],
|
|
131
|
+
[0, keyboardHeight.value - (height - point) + bottomOffset],
|
|
132
|
+
);
|
|
133
|
+
const targetScrollY =
|
|
134
|
+
Math.max(interpolatedScrollTo, 0) + scrollPosition.value;
|
|
135
|
+
scrollTo(scrollViewAnimatedRef, 0, targetScrollY, animated);
|
|
136
|
+
|
|
137
|
+
return interpolatedScrollTo;
|
|
185
138
|
}
|
|
186
139
|
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
scrollPosition.value = scrollBeforeKeyboardMovement.value;
|
|
191
|
-
}
|
|
140
|
+
if (absoluteY < 0) {
|
|
141
|
+
const positionOnScreen = visibleRect - inputHeight - bottomOffset;
|
|
142
|
+
const topOfScreen = scrollPosition.value + absoluteY;
|
|
192
143
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
scrollPosition.value = position.value;
|
|
200
|
-
// just persist height - later will be used in interpolation
|
|
201
|
-
keyboardHeight.value = e.height;
|
|
144
|
+
scrollTo(
|
|
145
|
+
scrollViewAnimatedRef,
|
|
146
|
+
0,
|
|
147
|
+
topOfScreen - positionOnScreen,
|
|
148
|
+
animated,
|
|
149
|
+
);
|
|
202
150
|
}
|
|
203
151
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
152
|
+
return 0;
|
|
153
|
+
},
|
|
154
|
+
[bottomOffset],
|
|
155
|
+
);
|
|
207
156
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
// save current scroll position - when keyboard will hide we'll reuse
|
|
211
|
-
// this value to achieve smooth hide effect
|
|
212
|
-
scrollBeforeKeyboardMovement.value = position.value;
|
|
213
|
-
}
|
|
157
|
+
const onChangeText = useCallback(() => {
|
|
158
|
+
"worklet";
|
|
214
159
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
},
|
|
221
|
-
onMove: (e) => {
|
|
222
|
-
"worklet";
|
|
160
|
+
// if typing a text caused layout shift, then we need to ignore this handler
|
|
161
|
+
// because this event will be handled in `useAnimatedReaction` below
|
|
162
|
+
if (layout.value?.layout.height !== input.value?.layout.height) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
223
165
|
|
|
224
|
-
|
|
166
|
+
const prevScrollPosition = scrollPosition.value;
|
|
167
|
+
const prevLayout = layout.value;
|
|
168
|
+
|
|
169
|
+
scrollPosition.value = position.value;
|
|
170
|
+
layout.value = input.value;
|
|
171
|
+
maybeScroll(keyboardHeight.value, true);
|
|
172
|
+
scrollPosition.value = prevScrollPosition;
|
|
173
|
+
layout.value = prevLayout;
|
|
174
|
+
}, [maybeScroll]);
|
|
175
|
+
const onChangeTextHandler = useMemo(
|
|
176
|
+
() => debounce(onChangeText, 200),
|
|
177
|
+
[onChangeText],
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
useFocusedInputHandler(
|
|
181
|
+
{
|
|
182
|
+
onChangeText: onChangeTextHandler,
|
|
183
|
+
},
|
|
184
|
+
[onChangeTextHandler],
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
useSmoothKeyboardHandler(
|
|
188
|
+
{
|
|
189
|
+
onStart: (e) => {
|
|
190
|
+
"worklet";
|
|
191
|
+
|
|
192
|
+
const keyboardWillChangeSize =
|
|
193
|
+
keyboardHeight.value !== e.height && e.height > 0;
|
|
194
|
+
keyboardWillAppear.value = e.height > 0 && keyboardHeight.value === 0;
|
|
195
|
+
const keyboardWillHide = e.height === 0;
|
|
196
|
+
const focusWasChanged =
|
|
197
|
+
(tag.value !== e.target && e.target !== -1) ||
|
|
198
|
+
keyboardWillChangeSize;
|
|
199
|
+
|
|
200
|
+
if (keyboardWillChangeSize) {
|
|
201
|
+
initialKeyboardSize.value = keyboardHeight.value;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (keyboardWillHide) {
|
|
205
|
+
// on back transition need to interpolate as [0, keyboardHeight]
|
|
206
|
+
initialKeyboardSize.value = 0;
|
|
207
|
+
scrollPosition.value = scrollBeforeKeyboardMovement.value;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (
|
|
211
|
+
keyboardWillAppear.value ||
|
|
212
|
+
keyboardWillChangeSize ||
|
|
213
|
+
focusWasChanged
|
|
214
|
+
) {
|
|
215
|
+
// persist scroll value
|
|
216
|
+
scrollPosition.value = position.value;
|
|
217
|
+
// just persist height - later will be used in interpolation
|
|
218
|
+
keyboardHeight.value = e.height;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// focus was changed
|
|
222
|
+
if (focusWasChanged) {
|
|
223
|
+
tag.value = e.target;
|
|
224
|
+
|
|
225
|
+
// save position of focused text input when keyboard starts to move
|
|
226
|
+
layout.value = input.value;
|
|
227
|
+
// save current scroll position - when keyboard will hide we'll reuse
|
|
228
|
+
// this value to achieve smooth hide effect
|
|
229
|
+
scrollBeforeKeyboardMovement.value = position.value;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (focusWasChanged && !keyboardWillAppear.value) {
|
|
233
|
+
// update position on scroll value, so `onEnd` handler
|
|
234
|
+
// will pick up correct values
|
|
235
|
+
position.value += maybeScroll(e.height, true);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
onMove: (e) => {
|
|
239
|
+
"worklet";
|
|
240
|
+
|
|
241
|
+
currentKeyboardFrameHeight.value = e.height;
|
|
242
|
+
|
|
243
|
+
// if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens
|
|
244
|
+
if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) {
|
|
245
|
+
maybeScroll(e.height);
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
onEnd: (e) => {
|
|
249
|
+
"worklet";
|
|
225
250
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
251
|
+
keyboardHeight.value = e.height;
|
|
252
|
+
scrollPosition.value = position.value;
|
|
253
|
+
},
|
|
230
254
|
},
|
|
231
|
-
|
|
232
|
-
|
|
255
|
+
[height, maybeScroll, disableScrollOnKeyboardHide],
|
|
256
|
+
);
|
|
233
257
|
|
|
234
|
-
|
|
235
|
-
|
|
258
|
+
useAnimatedReaction(
|
|
259
|
+
() => input.value,
|
|
260
|
+
(current, previous) => {
|
|
261
|
+
if (
|
|
262
|
+
current?.target === previous?.target &&
|
|
263
|
+
current?.layout.height !== previous?.layout.height
|
|
264
|
+
) {
|
|
265
|
+
const prevLayout = layout.value;
|
|
266
|
+
|
|
267
|
+
layout.value = input.value;
|
|
268
|
+
scrollPosition.value += maybeScroll(keyboardHeight.value, true);
|
|
269
|
+
layout.value = prevLayout;
|
|
270
|
+
}
|
|
236
271
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
ref={scrollViewAnimatedRef}
|
|
268
|
-
{...rest}
|
|
269
|
-
// @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events
|
|
270
|
-
onScrollReanimated={onScroll}
|
|
271
|
-
scrollEventThrottle={16}
|
|
272
|
-
>
|
|
273
|
-
{children}
|
|
274
|
-
<Reanimated.View style={view} />
|
|
275
|
-
</Reanimated.ScrollView>
|
|
276
|
-
);
|
|
277
|
-
};
|
|
272
|
+
[],
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const view = useAnimatedStyle(
|
|
276
|
+
() => ({
|
|
277
|
+
// animations become laggy when scrolling to the end of the `ScrollView` (when the last input is focused)
|
|
278
|
+
// this happens because the layout recalculates on every frame. To avoid this we slightly increase padding
|
|
279
|
+
// by `+1`. In this way we assure, that `scrollTo` will never scroll to the end, because it uses interpolation
|
|
280
|
+
// from 0 to `keyboardHeight`, and here our padding is `keyboardHeight + 1`. It allows us not to re-run layout
|
|
281
|
+
// re-calculation on every animation frame and it helps to achieve smooth animation.
|
|
282
|
+
// see: https://github.com/kirillzyusko/react-native-keyboard-controller/pull/342
|
|
283
|
+
paddingBottom: currentKeyboardFrameHeight.value + 1,
|
|
284
|
+
}),
|
|
285
|
+
[],
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
return (
|
|
289
|
+
<Reanimated.ScrollView
|
|
290
|
+
ref={onRef}
|
|
291
|
+
{...rest}
|
|
292
|
+
// @ts-expect-error `onScrollReanimated` is a fake prop needed for reanimated to intercept scroll events
|
|
293
|
+
onScrollReanimated={onScroll}
|
|
294
|
+
scrollEventThrottle={16}
|
|
295
|
+
>
|
|
296
|
+
{children}
|
|
297
|
+
<Reanimated.View style={view} />
|
|
298
|
+
</Reanimated.ScrollView>
|
|
299
|
+
);
|
|
300
|
+
},
|
|
301
|
+
);
|
|
278
302
|
|
|
279
303
|
export default KeyboardAwareScrollView;
|
|
@@ -35,6 +35,7 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
35
35
|
deps,
|
|
36
36
|
) => {
|
|
37
37
|
const target = useSharedValue(-1);
|
|
38
|
+
const height = useSharedValue(0);
|
|
38
39
|
const persistedHeight = useSharedValue(0);
|
|
39
40
|
const animatedKeyboardHeight = useSharedValue(0);
|
|
40
41
|
|
|
@@ -43,10 +44,12 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
43
44
|
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
47
|
+
if (persistedHeight.value === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
46
50
|
const event = {
|
|
47
|
-
// it'll be always
|
|
48
|
-
|
|
49
|
-
duration: 250,
|
|
51
|
+
// it'll be always `TELEGRAM_ANDROID_TIMING_CONFIG.duration`, since we're running animation via `withTiming`
|
|
52
|
+
duration: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
|
|
50
53
|
target: target.value,
|
|
51
54
|
height: animatedKeyboardHeight.value,
|
|
52
55
|
progress: animatedKeyboardHeight.value / persistedHeight.value,
|
|
@@ -60,8 +63,9 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
60
63
|
handler.onMove?.(evt);
|
|
61
64
|
|
|
62
65
|
// dispatch `onEnd`
|
|
63
|
-
if (evt.height ===
|
|
66
|
+
if (evt.height === height.value) {
|
|
64
67
|
handler.onEnd?.(evt);
|
|
68
|
+
persistedHeight.value = height.value;
|
|
65
69
|
}
|
|
66
70
|
},
|
|
67
71
|
[handler],
|
|
@@ -85,6 +89,7 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
target.value = e.target;
|
|
92
|
+
height.value = e.height;
|
|
88
93
|
|
|
89
94
|
if (e.height > 0) {
|
|
90
95
|
persistedHeight.value = e.height;
|
|
@@ -99,7 +104,12 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
99
104
|
);
|
|
100
105
|
}
|
|
101
106
|
|
|
102
|
-
handler.onStart?.(
|
|
107
|
+
handler.onStart?.({
|
|
108
|
+
...e,
|
|
109
|
+
duration: IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS
|
|
110
|
+
? e.duration
|
|
111
|
+
: TELEGRAM_ANDROID_TIMING_CONFIG.duration,
|
|
112
|
+
});
|
|
103
113
|
},
|
|
104
114
|
onMove: (e) => {
|
|
105
115
|
"worklet";
|
|
@@ -114,8 +124,6 @@ export const useSmoothKeyboardHandler: typeof useKeyboardHandler = (
|
|
|
114
124
|
if (IS_ANDROID_ELEVEN_OR_HIGHER_OR_IOS) {
|
|
115
125
|
handler.onEnd?.(e);
|
|
116
126
|
}
|
|
117
|
-
|
|
118
|
-
persistedHeight.value = e.height;
|
|
119
127
|
},
|
|
120
128
|
},
|
|
121
129
|
deps,
|