Fix initial pager gap after fast scroll (#1868)

zio/stable
dan 2023-11-10 21:23:17 +00:00 committed by GitHub
parent 91f8a23fbc
commit 86b4842d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -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)
}
}
}
@ -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(