[WIP] A simpler solution
This commit is contained in:
@@ -129,6 +129,16 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const scrollRefs = useSharedValue([])
|
||||||
|
const registerRef = (ref, index) => {
|
||||||
|
lolWut()
|
||||||
|
scrollRefs.modify(refs => {
|
||||||
|
'worklet'
|
||||||
|
refs[index] = ref
|
||||||
|
return refs
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// props to pass into children render functions
|
// props to pass into children render functions
|
||||||
const onScroll = useAnimatedScrollHandler({
|
const onScroll = useAnimatedScrollHandler({
|
||||||
onScroll(e) {
|
onScroll(e) {
|
||||||
@@ -138,6 +148,13 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
|
|||||||
e.contentOffset.y,
|
e.contentOffset.y,
|
||||||
headerOnlyHeightShared.value,
|
headerOnlyHeightShared.value,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (e.contentOffset.y < headerOnlyHeightShared.value) {
|
||||||
|
const refs = scrollRefs.value
|
||||||
|
for (let i = 0; i < refs.length; i++) {
|
||||||
|
scrollTo(refs[i], 0, e.contentOffset.y, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
useAnimatedReaction(
|
useAnimatedReaction(
|
||||||
@@ -179,7 +196,10 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
|
|||||||
headerHeight={headerHeight}
|
headerHeight={headerHeight}
|
||||||
isScrolledDown={isScrolledDown}
|
isScrolledDown={isScrolledDown}
|
||||||
onScroll={i === currentPage ? onScroll : noop}
|
onScroll={i === currentPage ? onScroll : noop}
|
||||||
forcedScrollY={i === currentPage ? null : clampedScrollY}
|
registerRef={ref => {
|
||||||
|
lolWut()
|
||||||
|
registerRef(ref, i)
|
||||||
|
}}
|
||||||
renderTab={
|
renderTab={
|
||||||
isHeaderReady && headerOnlyHeight > 0 && tabBarHeight > 0
|
isHeaderReady && headerOnlyHeight > 0 && tabBarHeight > 0
|
||||||
? child
|
? child
|
||||||
@@ -194,12 +214,16 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function lolWut() {
|
||||||
|
console.log('hi')
|
||||||
|
}
|
||||||
|
|
||||||
function PagerItem({
|
function PagerItem({
|
||||||
headerHeight,
|
headerHeight,
|
||||||
isScrolledDown,
|
isScrolledDown,
|
||||||
onScroll,
|
onScroll,
|
||||||
renderTab,
|
renderTab,
|
||||||
forcedScrollY,
|
registerRef,
|
||||||
}: {
|
}: {
|
||||||
headerHeight: number
|
headerHeight: number
|
||||||
isScrolledDown: boolean
|
isScrolledDown: boolean
|
||||||
@@ -207,33 +231,9 @@ function PagerItem({
|
|||||||
onScroll: OnScrollCb
|
onScroll: OnScrollCb
|
||||||
renderTab: ((props: PagerWithHeaderChildParams) => JSX.Element) | null
|
renderTab: ((props: PagerWithHeaderChildParams) => JSX.Element) | null
|
||||||
}) {
|
}) {
|
||||||
|
lolWut()
|
||||||
const scrollElRef = useAnimatedRef()
|
const scrollElRef = useAnimatedRef()
|
||||||
useAnimatedReaction(
|
registerRef(scrollElRef)
|
||||||
() => {
|
|
||||||
if (forcedScrollY) {
|
|
||||||
return forcedScrollY.value
|
|
||||||
} else {
|
|
||||||
// Active tab doesn't get synced.
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(nextForcedY, prevForcedY) => {
|
|
||||||
if (nextForcedY === prevForcedY) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (nextForcedY == null) {
|
|
||||||
// This tab just became active. It was already being synced before.
|
|
||||||
// So we don't need to do anything.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (prevForcedY == null) {
|
|
||||||
// This tab just became inactive, so it used to be the source of truth.
|
|
||||||
// There is no need to sync it until we get more scroll events.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
scrollTo(scrollElRef, 0, nextForcedY, false)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if (renderTab == null) {
|
if (renderTab == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user