Skip to content

Commit

Permalink
fix: prevent scrolling to top
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBern committed Feb 8, 2021
1 parent 5e18678 commit 1db8e4e
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,37 +205,42 @@ export const useScrollHandlerY = (name: TabName) => {
const onMomentumEnd = () => {
'worklet'
if (typeof snapThreshold === 'number') {
if (diffClampEnabled && accDiffClamp.value > 0) {
if (scrollYCurrent.value > headerScrollDistance.value * snapThreshold) {
if (diffClampEnabled) {
if (accDiffClamp.value > 0) {
if (
accDiffClamp.value <=
scrollYCurrent.value >
headerScrollDistance.value * snapThreshold
) {
// snap down
if (
accDiffClamp.value <=
headerScrollDistance.value * snapThreshold
) {
// snap down
isSnapping.value = true
accDiffClamp.value = withTiming(0, undefined, () => {
isSnapping.value = false
})
} else if (accDiffClamp.value < headerScrollDistance.value) {
// snap up
isSnapping.value = true
accDiffClamp.value = withTiming(
headerScrollDistance.value,
undefined,
() => {
isSnapping.value = false
}
)

if (scrollYCurrent.value < headerScrollDistance.value) {
scrollToImpl(refMap[name], 0, headerScrollDistance.value, true)
}
}
} else {
isSnapping.value = true
accDiffClamp.value = withTiming(0, undefined, () => {
isSnapping.value = false
})
} else if (accDiffClamp.value < headerScrollDistance.value) {
// snap up
isSnapping.value = true
accDiffClamp.value = withTiming(
headerScrollDistance.value,
undefined,
() => {
isSnapping.value = false
}
)

if (scrollYCurrent.value < headerScrollDistance.value) {
scrollToImpl(refMap[name], 0, headerScrollDistance.value, true)
}
}
} else {
isSnapping.value = true
accDiffClamp.value = withTiming(0, undefined, () => {
isSnapping.value = false
})
}
} else {
if (
Expand Down

0 comments on commit 1db8e4e

Please sign in to comment.