Skip to content

Commit

Permalink
Fix initial pager gap after fast scroll (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Nov 10, 2023
1 parent 91f8a23 commit 86b4842
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/view/com/pager/PagerWithHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,20 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
})
}

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)
}
}
}
Expand All @@ -158,7 +161,14 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
runOnJS(setIsScrolledDown)(nextIsScrolledDown)
}
},
[currentPage, headerOnlyHeight, isScrolledDown, scrollRefs, scrollY],
[
currentPage,
headerOnlyHeight,
isScrolledDown,
scrollRefs,
scrollY,
lastForcedScrollY,
],
)

const onPageSelectedInner = React.useCallback(
Expand Down

0 comments on commit 86b4842

Please sign in to comment.