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