Skip to content

Commit 55c62d5

Browse files
committed
fix: automatically detect top border of KeyboardAwareScrollView
1 parent eb2dfbb commit 55c62d5

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • src/components/KeyboardAwareScrollView

src/components/KeyboardAwareScrollView/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,19 @@ const KeyboardAwareScrollView = forwardRef<
150150
useSharedValue<FocusedInputSelectionChangedEvent | null>(null);
151151
const ghostViewSpace = useSharedValue(-1);
152152
const pendingSelectionForFocus = useSharedValue(false);
153+
const scrollViewPageY = useSharedValue(0);
153154

154155
const { height } = useWindowDimensions();
155156

156157
const onScrollViewLayout = useCallback(
157158
(e: LayoutChangeEvent) => {
158159
scrollViewTarget.value = findNodeHandle(scrollViewAnimatedRef.current);
159160

161+
// @ts-expect-error something is wrong with the type of `measureInWindow`
162+
scrollViewRef.current?.measureInWindow((_x, y) => {
163+
scrollViewPageY.value = y;
164+
});
165+
160166
onLayout?.(e);
161167
},
162168
[onLayout],
@@ -205,7 +211,7 @@ const KeyboardAwareScrollView = forwardRef<
205211
return interpolatedScrollTo;
206212
}
207213

208-
if (point < 0) {
214+
if (point < scrollViewPageY.value) {
209215
const positionOnScreen = visibleRect - bottomOffset;
210216
const topOfScreen = scrollPosition.value + point;
211217

0 commit comments

Comments
 (0)