From 585b90089ade640c862c21a74a132c6f95c97e32 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 26 Sep 2024 16:30:28 +0100 Subject: [PATCH 1/4] ignore bogus onScroll values --- src/view/com/pager/PagerWithHeader.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index 528f7fdf2e..844edb34aa 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -161,10 +161,15 @@ export const PagerWithHeader = React.forwardRef( (e: NativeScrollEvent) => { 'worklet' const nextScrollY = e.contentOffset.y - scrollY.value = nextScrollY - runOnJS(queueThrottledOnScroll)() + // HACK: onScroll is reporting some strange values on load. + // Highly improbable that you'd be overscrolled by over 400px - + // in fact, I actually can't do it, so let's just ignore those -sfn + if (nextScrollY !== -headerHeight) { + scrollY.value = nextScrollY + runOnJS(queueThrottledOnScroll)() + } }, - [scrollY, queueThrottledOnScroll], + [scrollY, queueThrottledOnScroll, headerHeight], ) const onPageSelectedInner = React.useCallback( From d2d10500ee5e149edafc6a2a5df1624241353f64 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 26 Sep 2024 16:36:00 +0100 Subject: [PATCH 2/4] only apply if < -300 --- src/view/com/pager/PagerWithHeader.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index 844edb34aa..4587a3de25 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -161,10 +161,12 @@ export const PagerWithHeader = React.forwardRef( (e: NativeScrollEvent) => { 'worklet' const nextScrollY = e.contentOffset.y - // HACK: onScroll is reporting some strange values on load. + // HACK: onScroll is reporting some strange values on load (negative header height). // Highly improbable that you'd be overscrolled by over 400px - - // in fact, I actually can't do it, so let's just ignore those -sfn - if (nextScrollY !== -headerHeight) { + // in fact, I actually can't do it, so let's just ignore those. + // Let's only apply this hack if we've overscrolled by more than 300px + // so that it's not a false positive from overscrolling -sfn + if (nextScrollY > -300 || nextScrollY !== -headerHeight) { scrollY.value = nextScrollY runOnJS(queueThrottledOnScroll)() } From 55901390ef0691ef00e573c5a766bda7d0184e87 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 26 Sep 2024 16:52:22 +0100 Subject: [PATCH 3/4] drop arbitrary threshold, just check there's a header --- src/view/com/pager/PagerWithHeader.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index 4587a3de25..bdfb5b5d1f 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -166,7 +166,9 @@ export const PagerWithHeader = React.forwardRef( // in fact, I actually can't do it, so let's just ignore those. // Let's only apply this hack if we've overscrolled by more than 300px // so that it's not a false positive from overscrolling -sfn - if (nextScrollY > -300 || nextScrollY !== -headerHeight) { + const isPossiblyInvalid = + headerHeight > 0 && nextScrollY === -headerHeight + if (!isPossiblyInvalid) { scrollY.value = nextScrollY runOnJS(queueThrottledOnScroll)() } From 8daa73956f6e09a561ad01e778880e660f0b8032 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 27 Sep 2024 08:45:11 +0100 Subject: [PATCH 4/4] apply same rounding logic to check as headerHeight --- src/view/com/pager/PagerWithHeader.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index bdfb5b5d1f..6d601c2899 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -163,11 +163,9 @@ export const PagerWithHeader = React.forwardRef( const nextScrollY = e.contentOffset.y // HACK: onScroll is reporting some strange values on load (negative header height). // Highly improbable that you'd be overscrolled by over 400px - - // in fact, I actually can't do it, so let's just ignore those. - // Let's only apply this hack if we've overscrolled by more than 300px - // so that it's not a false positive from overscrolling -sfn + // in fact, I actually can't do it, so let's just ignore those. -sfn const isPossiblyInvalid = - headerHeight > 0 && nextScrollY === -headerHeight + headerHeight > 0 && Math.round(nextScrollY * 2) / 2 === -headerHeight if (!isPossiblyInvalid) { scrollY.value = nextScrollY runOnJS(queueThrottledOnScroll)()