From 7569a52059269b594f6742f91aa276af47858d56 Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Mon, 8 Feb 2021 16:59:09 +0200 Subject: [PATCH] fix: sticky header edge case on android --- src/Container.tsx | 21 +-------------------- src/hooks.tsx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Container.tsx b/src/Container.tsx index c7b6bf08..b9e761b8 100644 --- a/src/Container.tsx +++ b/src/Container.tsx @@ -288,26 +288,6 @@ const Container = React.forwardRef( [] ) - // 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 @@ -537,6 +517,7 @@ const Container = React.forwardRef( { 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