Skip to content

Commit

Permalink
fix: initial scroll position if starting with undefined header height
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed May 9, 2022
1 parent 62f52b5 commit 9378af6
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ export const Container = React.memo(
)
}, [afterRender, tabNamesArray])

const resyncTabScroll = () => {
'worklet'
for (const name of tabNamesArray) {
scrollToImpl(
refMap[name],
0,
scrollYCurrent.value - contentInset.value,
false
)
}
}

// the purpose of this is to scroll to the proper position if dynamic tabs are changing
useAnimatedReaction(
() => {
Expand All @@ -173,15 +185,7 @@ export const Container = React.memo(
(trigger) => {
if (trigger) {
afterRender.value = 0
tabNamesArray.forEach((name) => {
'worklet'
scrollToImpl(
refMap[name],
0,
scrollY.value[index.value] - contentInset.value,
false
)
})
resyncTabScroll()
}
},
[tabNamesArray, refMap, afterRender, contentInset]
Expand Down Expand Up @@ -233,6 +237,16 @@ export const Container = React.memo(
[]
)

useAnimatedReaction(
() => headerHeight.value,
(_current, prev) => {
if (prev === undefined) {
// sync scroll if we started with undefined header height
resyncTabScroll()
}
}
)

const headerTranslateY = useDerivedValue(() => {
return revealHeaderOnScroll
? -accDiffClamp.value
Expand Down

0 comments on commit 9378af6

Please sign in to comment.