Skip to content

Commit

Permalink
fix: sticky header edge case on android
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Feb 8, 2021
1 parent fa2f2d9 commit 7569a52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
21 changes: 1 addition & 20 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,6 @@ const Container = React.forwardRef<CollapsibleRef, CollapsibleProps>(
[]
)

// derived from accScrollY, to calculate the accDiffClamp value
useAnimatedReaction(
() => {
return diffClampEnabled ? accScrollY.value - oldAccScrollY.value : 0
},
(delta) => {
if (delta) {
const nextValue = accDiffClamp.value + delta
if (delta > 0) {
// scrolling down
accDiffClamp.value = Math.min(headerScrollDistance.value, nextValue)
} else if (delta < 0) {
// scrolling up
accDiffClamp.value = Math.max(0, nextValue)
}
}
},
[]
)

const renderItem = React.useCallback(
({ index: i }) => {
if (!tabNames.value[i]) return null
Expand Down Expand Up @@ -537,6 +517,7 @@ const Container = React.forwardRef<CollapsibleRef, CollapsibleProps>(
<AnimatedFlatList
// @ts-expect-error problem with reanimated types, they're missing `ref`
ref={containerRef}
scrollToOverflowEnabled
initialScrollIndex={index.value}
data={data}
keyExtractor={keyExtractor}
Expand Down
15 changes: 15 additions & 0 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ export const useScrollHandlerY = (name: TabName) => {
oldAccScrollY.value = accScrollY.value
accScrollY.value = scrollY.value[index.value] + offset.value

if (!isSnapping.value && diffClampEnabled) {
const delta = accScrollY.value - oldAccScrollY.value
const nextValue = accDiffClamp.value + delta
if (delta > 0) {
// scrolling down
accDiffClamp.value = Math.min(
headerScrollDistance.value,
nextValue
)
} else if (delta < 0) {
// scrolling up
accDiffClamp.value = Math.max(0, nextValue)
}
}

isScrolling.value = 1

// cancel the animation that is setting this back to 0 if we're still scrolling
Expand Down

0 comments on commit 7569a52

Please sign in to comment.