Skip to content

Commit 5d60c05

Browse files
committed
refactor: migrate measureInWindow to viewPositionInWindow
1 parent 55c62d5 commit 5d60c05

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

  • src/components/KeyboardAwareScrollView

src/components/KeyboardAwareScrollView/index.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Reanimated, {
1616
useSharedValue,
1717
} from "react-native-reanimated";
1818

19+
import { KeyboardControllerNative } from "../../bindings";
1920
import {
2021
useFocusedInputHandler,
2122
useReanimatedFocusedInput,
@@ -155,15 +156,20 @@ const KeyboardAwareScrollView = forwardRef<
155156
const { height } = useWindowDimensions();
156157

157158
const onScrollViewLayout = useCallback(
158-
(e: LayoutChangeEvent) => {
159-
scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);
159+
async (e: LayoutChangeEvent) => {
160+
const handle = findNodeHandle(scrollViewAnimatedRef.current);
160161

161-
// @ts-expect-error something is wrong with the type of `measureInWindow`
162-
scrollViewRef.current?.measureInWindow((_x, y) => {
163-
scrollViewPageY.value = y;
164-
});
162+
scrollViewTarget.value = handle;
165163

166164
onLayout?.(e);
165+
166+
if (handle !== null) {
167+
const { y } = await KeyboardControllerNative.viewPositionInWindow(
168+
handle,
169+
);
170+
171+
scrollViewPageY.value = y;
172+
}
167173
},
168174
[onLayout],
169175
);

0 commit comments

Comments
 (0)