More scroll

This commit is contained in:
Dan Abramov
2023-12-07 05:50:58 +00:00
parent 8c81407ca9
commit e4cc7ea409
2 changed files with 27 additions and 16 deletions
+19 -11
View File
@@ -22,6 +22,7 @@ import {TabBar} from './TabBar'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {OnScrollHandler} from 'lib/hooks/useOnMainScroll' import {OnScrollHandler} from 'lib/hooks/useOnMainScroll'
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
import {isWeb} from '#/platform/detection'
const SCROLLED_DOWN_LIMIT = 200 const SCROLLED_DOWN_LIMIT = 200
@@ -257,21 +258,28 @@ let PagerTabBar = ({
return ( return (
<Animated.View <Animated.View
pointerEvents="box-none" pointerEvents="box-none"
style={[ style={
isMobile ? styles.tabBarMobile : styles.tabBarDesktop, isWeb
headerTransform, ? []
]}> : [
isMobile ? styles.tabBarMobile : styles.tabBarDesktop,
headerTransform,
]
}>
<View onLayout={onHeaderOnlyLayout} pointerEvents="box-none"> <View onLayout={onHeaderOnlyLayout} pointerEvents="box-none">
{renderHeader?.()} {renderHeader?.()}
</View> </View>
<View <View
onLayout={onTabBarLayout} onLayout={onTabBarLayout}
style={{ 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. // Render it immediately to measure it early since its size doesn't depend on the content.
opacity: isHeaderReady ? 1 : 0, // However, keep it invisible until the header above stabilizes in order to prevent jumps.
pointerEvents: isHeaderReady ? 'auto' : 'none', opacity: isHeaderReady ? 1 : 0,
}}> pointerEvents: isHeaderReady ? 'auto' : 'none',
},
isWeb ? {position: 'sticky', top: 0} : null,
]}>
<TabBar <TabBar
testID={testID} testID={testID}
items={items} items={items}
@@ -315,7 +323,7 @@ function PagerItem({
} }
return renderTab({ return renderTab({
headerHeight, headerHeight: isWeb ? 0 : headerHeight,
isFocused, isFocused,
isScrolledDown, isScrolledDown,
onScroll: scrollHandler, onScroll: scrollHandler,
+8 -5
View File
@@ -120,13 +120,13 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
ref, ref,
() => ({ () => ({
scrollToTop() { scrollToTop() {
console.log('yeahh') window.scrollTo({top: 0})
}, },
scrollToOffset({animated, offset}) { scrollToOffset({animated, offset}) {
nativeRef.current.scrollTo({ window.scrollTo({
x: 0, left: 0,
y: offset, top: offset,
animated, behavior: animated ? 'smooth' : 'instant',
}) })
}, },
}), }),
@@ -134,6 +134,9 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
) )
React.useEffect(() => { React.useEffect(() => {
if (!onScroll) {
return
}
function handleScroll(e) { function handleScroll(e) {
onScroll.current.worklet({ onScroll.current.worklet({
...e.nativeEvent, ...e.nativeEvent,