From 55c62d57df496d7eaab7010fa28d45c2b2a3e133 Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Tue, 10 Mar 2026 19:42:47 +0100 Subject: [PATCH 1/2] fix: automatically detect top border of `KeyboardAwareScrollView` --- src/components/KeyboardAwareScrollView/index.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index 1d484a35c2..51b05b77d2 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -150,6 +150,7 @@ const KeyboardAwareScrollView = forwardRef< useSharedValue(null); const ghostViewSpace = useSharedValue(-1); const pendingSelectionForFocus = useSharedValue(false); + const scrollViewPageY = useSharedValue(0); const { height } = useWindowDimensions(); @@ -157,6 +158,11 @@ const KeyboardAwareScrollView = forwardRef< (e: LayoutChangeEvent) => { scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current); + // @ts-expect-error something is wrong with the type of `measureInWindow` + scrollViewRef.current?.measureInWindow((_x, y) => { + scrollViewPageY.value = y; + }); + onLayout?.(e); }, [onLayout], @@ -205,7 +211,7 @@ const KeyboardAwareScrollView = forwardRef< return interpolatedScrollTo; } - if (point < 0) { + if (point < scrollViewPageY.value) { const positionOnScreen = visibleRect - bottomOffset; const topOfScreen = scrollPosition.value + point; From 5d60c05887cc064f165dcb279cd29f41c50094dd Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Thu, 12 Mar 2026 17:05:39 +0100 Subject: [PATCH 2/2] refactor: migrate `measureInWindow` to `viewPositionInWindow` --- .../KeyboardAwareScrollView/index.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/KeyboardAwareScrollView/index.tsx b/src/components/KeyboardAwareScrollView/index.tsx index 51b05b77d2..fc5ec35ec8 100644 --- a/src/components/KeyboardAwareScrollView/index.tsx +++ b/src/components/KeyboardAwareScrollView/index.tsx @@ -16,6 +16,7 @@ import Reanimated, { useSharedValue, } from "react-native-reanimated"; +import { KeyboardControllerNative } from "../../bindings"; import { useFocusedInputHandler, useReanimatedFocusedInput, @@ -155,15 +156,20 @@ const KeyboardAwareScrollView = forwardRef< const { height } = useWindowDimensions(); const onScrollViewLayout = useCallback( - (e: LayoutChangeEvent) => { - scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current); + async (e: LayoutChangeEvent) => { + const handle = findNodeHandle(scrollViewAnimatedRef.current); - // @ts-expect-error something is wrong with the type of `measureInWindow` - scrollViewRef.current?.measureInWindow((_x, y) => { - scrollViewPageY.value = y; - }); + scrollViewTarget.value = handle; onLayout?.(e); + + if (handle !== null) { + const { y } = await KeyboardControllerNative.viewPositionInWindow( + handle, + ); + + scrollViewPageY.value = y; + } }, [onLayout], );