From a00b017fb37eb0ded1a38824abde9ed807a6086e Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 29 Oct 2024 17:03:55 +0100 Subject: [PATCH 1/2] fix: google password manager breaks `KeyboardAwareScrollView` --- src/components/KeyboardAwareScrollView/index.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index bcdc5207fe..7309e57492 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -326,6 +326,14 @@ const KeyboardAwareScrollView = forwardRef< keyboardHeight.value = e.height; scrollPosition.value = position.value; + + const keyboardFrame = interpolate( + e.height, + [0, keyboardHeight.value], + [0, keyboardHeight.value + extraKeyboardSpace], + ); + + currentKeyboardFrameHeight.value = keyboardFrame; }, }, [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace], From e63f45dd742a7fd2ac0038cf5dae34a566f75b9b Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 29 Oct 2024 18:33:50 +0100 Subject: [PATCH 2/2] refactor: reduce code duplication --- .../KeyboardAwareScrollView/index.tsx | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index 7309e57492..10e316b88c 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -27,6 +27,7 @@ import type { import type { FocusedInputLayoutChangedEvent, FocusedInputSelectionChangedEvent, + NativeEvent, } from "react-native-keyboard-controller"; export type KeyboardAwareScrollViewProps = { @@ -190,6 +191,20 @@ const KeyboardAwareScrollView = forwardRef< }, [bottomOffset, enabled, height, snapToOffsets], ); + const syncKeyboardFrame = useCallback( + (e: NativeEvent) => { + "worklet"; + + const keyboardFrame = interpolate( + e.height, + [0, keyboardHeight.value], + [0, keyboardHeight.value + extraKeyboardSpace], + ); + + currentKeyboardFrameHeight.value = keyboardFrame; + }, + [extraKeyboardSpace], + ); const scrollFromCurrentPosition = useCallback( (customHeight?: number) => { @@ -308,13 +323,7 @@ const KeyboardAwareScrollView = forwardRef< onMove: (e) => { "worklet"; - const keyboardFrame = interpolate( - e.height, - [0, keyboardHeight.value], - [0, keyboardHeight.value + extraKeyboardSpace], - ); - - currentKeyboardFrameHeight.value = keyboardFrame; + syncKeyboardFrame(e); // if the user has set disableScrollOnKeyboardHide, only auto-scroll when the keyboard opens if (!disableScrollOnKeyboardHide || keyboardWillAppear.value) { @@ -327,16 +336,10 @@ const KeyboardAwareScrollView = forwardRef< keyboardHeight.value = e.height; scrollPosition.value = position.value; - const keyboardFrame = interpolate( - e.height, - [0, keyboardHeight.value], - [0, keyboardHeight.value + extraKeyboardSpace], - ); - - currentKeyboardFrameHeight.value = keyboardFrame; + syncKeyboardFrame(e); }, }, - [maybeScroll, disableScrollOnKeyboardHide, extraKeyboardSpace], + [maybeScroll, disableScrollOnKeyboardHide, syncKeyboardFrame], ); useAnimatedReaction(