Fix profile and types

This commit is contained in:
Dan Abramov
2024-11-30 18:59:57 +00:00
parent 7a6d4ff91c
commit b38ea9d6cc
5 changed files with 22 additions and 8 deletions
+2 -1
View File
@@ -59,7 +59,8 @@ export function HomeHeader(
onSelect={onSelect}
testID={props.testID}
items={items}
dragGesture={props.dragGesture}
dragProgress={props.dragProgress}
dragState={props.dragState}
/>
</HomeHeaderLayout>
)
+5 -4
View File
@@ -8,6 +8,7 @@ import PagerView, {
} from 'react-native-pager-view'
import Animated, {
runOnJS,
SharedValue,
useEvent,
useHandler,
useSharedValue,
@@ -25,6 +26,8 @@ export interface RenderTabBarFnProps {
selectedPage: number
onSelect?: (index: number) => void
tabBarAnchor?: JSX.Element | null | undefined // Ignored on native.
dragProgress: SharedValue<number> // Ignored on web.
dragState: SharedValue<'idle' | 'dragging' | 'settling'> // Ignored on web.
}
export type RenderTabBarFn = (props: RenderTabBarFnProps) => JSX.Element
@@ -107,10 +110,8 @@ export const Pager = forwardRef<PagerRef, React.PropsWithChildren<Props>>(
{renderTabBar({
selectedPage,
onSelect: onTabBarSelect,
dragGesture: {
dragProgress,
dragState,
},
dragProgress,
dragState,
})}
<AnimatedPagerView
ref={pagerView}
+8
View File
@@ -97,6 +97,8 @@ export const PagerWithHeader = React.forwardRef<PagerRef, PagerWithHeaderProps>(
scrollY={scrollY}
testID={testID}
allowHeaderOverScroll={allowHeaderOverScroll}
dragProgress={props.dragProgress}
dragState={props.dragState}
/>
</PagerHeaderProvider>
)
@@ -226,6 +228,8 @@ let PagerTabBar = ({
onCurrentPageSelected,
onSelect,
allowHeaderOverScroll,
dragProgress,
dragState,
}: {
currentPage: number
headerOnlyHeight: number
@@ -239,6 +243,8 @@ let PagerTabBar = ({
onCurrentPageSelected?: (index: number) => void
onSelect?: (index: number) => void
allowHeaderOverScroll?: boolean
dragProgress: SharedValue<number>
dragState: SharedValue<'idle' | 'dragging' | 'settling'>
}): React.ReactNode => {
const headerTransform = useAnimatedStyle(() => {
const translateY = Math.min(scrollY.get(), headerOnlyHeight) * -1
@@ -297,6 +303,8 @@ let PagerTabBar = ({
selectedPage={currentPage}
onSelect={onSelect}
onPressSelected={onCurrentPageSelected}
dragProgress={dragProgress}
dragState={dragState}
/>
</View>
</Animated.View>
@@ -151,6 +151,8 @@ let PagerTabBar = ({
selectedPage={currentPage}
onSelect={onSelect}
onPressSelected={onCurrentPageSelected}
dragProgress={undefined as any /* native-only */}
dragState={undefined as any /* native-only */}
/>
</View>
</>
+5 -3
View File
@@ -21,6 +21,8 @@ export interface TabBarProps {
items: string[]
onSelect?: (index: number) => void
onPressSelected?: (index: number) => void
dragProgress: SharedValue<number>
dragState: SharedValue<'idle' | 'dragging' | 'settling'>
}
export function TabBar({
@@ -29,17 +31,17 @@ export function TabBar({
items,
onSelect,
onPressSelected,
dragGesture,
dragProgress,
dragState,
}: TabBarProps) {
const pal = usePalette('default')
const scrollElRef = useAnimatedRef()
const scrollElRef = useAnimatedRef<ScrollView>()
const isSyncingScroll = useSharedValue(true)
const contentSize = useSharedValue(0)
const containerSize = useSharedValue(0)
const scrollX = useSharedValue(0)
const layouts = useSharedValue<{x: number; width: number}[]>([])
const itemsLength = items.length
const {dragProgress, dragState} = dragGesture
// When you swipe the pager, the tabbar should scroll automatically
// as you're dragging the page and then even during deceleration.