From 86b4842d67c563caf68388e2453f716d1c553862 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 10 Nov 2023 21:23:17 +0000 Subject: [PATCH] Fix initial pager gap after fast scroll (#1868) --- src/view/com/pager/PagerWithHeader.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index e93d91fedb..95798d26b8 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -138,17 +138,20 @@ export const PagerWithHeader = React.forwardRef( }) } + const lastForcedScrollY = useSharedValue(0) const onScrollWorklet = React.useCallback( (e: NativeScrollEvent) => { 'worklet' const nextScrollY = e.contentOffset.y scrollY.value = nextScrollY - if (nextScrollY < headerOnlyHeight) { + const forcedScrollY = Math.min(nextScrollY, headerOnlyHeight) + if (lastForcedScrollY.value !== forcedScrollY) { + lastForcedScrollY.value = forcedScrollY const refs = scrollRefs.value for (let i = 0; i < refs.length; i++) { if (i !== currentPage) { - scrollTo(refs[i], 0, nextScrollY, false) + scrollTo(refs[i], 0, forcedScrollY, false) } } } @@ -158,7 +161,14 @@ export const PagerWithHeader = React.forwardRef( runOnJS(setIsScrolledDown)(nextIsScrolledDown) } }, - [currentPage, headerOnlyHeight, isScrolledDown, scrollRefs, scrollY], + [ + currentPage, + headerOnlyHeight, + isScrolledDown, + scrollRefs, + scrollY, + lastForcedScrollY, + ], ) const onPageSelectedInner = React.useCallback(