From e4cc7ea40971e4134159427eec3540362f1ea1f5 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 7 Dec 2023 05:50:58 +0000 Subject: [PATCH] More scroll --- src/view/com/pager/PagerWithHeader.tsx | 30 ++++++++++++++++---------- src/view/com/util/Views.web.tsx | 13 ++++++----- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index 22e2d86b17..80aa5dfc58 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -22,6 +22,7 @@ import {TabBar} from './TabBar' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {OnScrollHandler} from 'lib/hooks/useOnMainScroll' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' +import {isWeb} from '#/platform/detection' const SCROLLED_DOWN_LIMIT = 200 @@ -257,21 +258,28 @@ let PagerTabBar = ({ return ( + style={ + isWeb + ? [] + : [ + isMobile ? styles.tabBarMobile : styles.tabBarDesktop, + headerTransform, + ] + }> {renderHeader?.()} + style={[ + { + // Render it immediately to measure it early since its size doesn't depend on the content. + // However, keep it invisible until the header above stabilizes in order to prevent jumps. + opacity: isHeaderReady ? 1 : 0, + pointerEvents: isHeaderReady ? 'auto' : 'none', + }, + isWeb ? {position: 'sticky', top: 0} : null, + ]}> ( ref, () => ({ scrollToTop() { - console.log('yeahh') + window.scrollTo({top: 0}) }, scrollToOffset({animated, offset}) { - nativeRef.current.scrollTo({ - x: 0, - y: offset, - animated, + window.scrollTo({ + left: 0, + top: offset, + behavior: animated ? 'smooth' : 'instant', }) }, }), @@ -134,6 +134,9 @@ export const FlatList = React.forwardRef(function FlatListImpl( ) React.useEffect(() => { + if (!onScroll) { + return + } function handleScroll(e) { onScroll.current.worklet({ ...e.nativeEvent,