diff --git a/apps/mobile/src/lib/navigation/WrappedScreenItem.tsx b/apps/mobile/src/lib/navigation/WrappedScreenItem.tsx index 8a627643b..58c2768c5 100644 --- a/apps/mobile/src/lib/navigation/WrappedScreenItem.tsx +++ b/apps/mobile/src/lib/navigation/WrappedScreenItem.tsx @@ -3,7 +3,7 @@ import type { PrimitiveAtom } from "jotai" import { atom, useAtomValue, useSetAtom } from "jotai" import type { FC, ReactNode } from "react" import { memo, useCallback, useContext, useMemo, useRef } from "react" -import type { NativeSyntheticEvent } from "react-native" +import type { NativeSyntheticEvent, StyleProp, ViewStyle } from "react-native" import { StyleSheet, View } from "react-native" import { useSharedValue } from "react-native-reanimated" import type { ScreenStackHeaderConfigProps, StackPresentationTypes } from "react-native-screens" @@ -33,6 +33,7 @@ export const WrappedScreenItem: FC< headerConfig?: ScreenStackHeaderConfigProps screenOptions?: NavigationControllerViewExtraProps + style?: StyleProp } & ScreenOptionsContextType > = memo( ({ @@ -41,6 +42,7 @@ export const WrappedScreenItem: FC< stackPresentation, headerConfig, screenOptions: screenOptionsProp, + style, ...rest }) => { const navigation = useNavigation() @@ -143,6 +145,7 @@ export const WrappedScreenItem: FC< style={[ StyleSheet.absoluteFill, { backgroundColor: screenOptionsProp?.transparent ? undefined : backgroundColor }, + style, ]} {...rest} {...mergedScreenOptions} diff --git a/apps/mobile/src/lib/navigation/bottom-tab/TabScreen.ios.tsx b/apps/mobile/src/lib/navigation/bottom-tab/TabScreen.ios.tsx index c128a9bc5..185302d49 100644 --- a/apps/mobile/src/lib/navigation/bottom-tab/TabScreen.ios.tsx +++ b/apps/mobile/src/lib/navigation/bottom-tab/TabScreen.ios.tsx @@ -95,15 +95,15 @@ export const TabScreen: FC - {shouldLoadReact && ( + {shouldLoadReact && optimize && ( {children} - {/* */} )} diff --git a/apps/mobile/src/modules/context-menu/feeds.tsx b/apps/mobile/src/modules/context-menu/feeds.tsx index 0237f8420..1bfd1c30b 100644 --- a/apps/mobile/src/modules/context-menu/feeds.tsx +++ b/apps/mobile/src/modules/context-menu/feeds.tsx @@ -328,7 +328,7 @@ const PreviewFeeds = (props: { id: string; view: FeedViewType }) => { ({ item: id }: ListRenderItemInfo) => ( ), - [], + [props.view], ) return ( diff --git a/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx b/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx index 4ffc3a3ad..4c4c63160 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentArticle.tsx @@ -1,7 +1,7 @@ import type { FeedViewType } from "@follow/constants" import type { ListRenderItemInfo } from "@shopify/flash-list" import type { ElementRef } from "react" -import { forwardRef, useCallback, useMemo } from "react" +import { forwardRef, useCallback, useImperativeHandle, useMemo } from "react" import { View } from "react-native" import { usePlayingUrl } from "@/src/lib/player" @@ -10,14 +10,14 @@ import { usePrefetchEntryTranslation } from "@/src/store/translation/hooks" import { useFetchEntriesControls } from "../screen/atoms" import { TimelineSelectorList } from "../screen/TimelineSelectorList" import { EntryListFooter } from "./EntryListFooter" -import { useOnViewableItemsChanged } from "./hooks" +import { useOnViewableItemsChanged, usePagerListPerformanceHack } from "./hooks" import { ItemSeparator } from "./ItemSeparator" import { EntryNormalItem } from "./templates/EntryNormalItem" export const EntryListContentArticle = forwardRef< ElementRef, { entryIds: string[] | null; active?: boolean; view: FeedViewType } ->(({ entryIds, active, view }, ref) => { +>(({ entryIds, active, view }, forwardRef) => { const playingAudioUrl = usePlayingUrl() const { fetchNextPage, isFetching, refetch, isRefetching, hasNextPage } = @@ -35,10 +35,15 @@ export const EntryListContentArticle = forwardRef< [hasNextPage], ) + const { onScroll: hackOnScroll, ref, style: hackStyle } = usePagerListPerformanceHack() + const { onViewableItemsChanged, onScroll, viewableItems } = useOnViewableItemsChanged({ disabled: active === false || isFetching, + onScroll: hackOnScroll, }) + useImperativeHandle(forwardRef, () => ref.current!) + usePrefetchEntryTranslation(active ? viewableItems.map((item) => item.key) : []) return ( @@ -48,7 +53,7 @@ export const EntryListContentArticle = forwardRef< isRefetching={isRefetching} data={entryIds} extraData={playingAudioUrl} - keyExtractor={(id) => id} + keyExtractor={defaultKeyExtractor} estimatedItemSize={100} renderItem={renderItem} onEndReached={fetchNextPage} @@ -56,10 +61,13 @@ export const EntryListContentArticle = forwardRef< onViewableItemsChanged={onViewableItemsChanged} ItemSeparatorComponent={ItemSeparator} ListFooterComponent={ListFooterComponent} + style={hackStyle} /> ) }) +const defaultKeyExtractor = (id: string) => id + export function EntryItemSkeleton() { return ( diff --git a/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx b/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx index fc69da2ff..bd99c9dd8 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentPicture.tsx @@ -1,7 +1,7 @@ import { useTypeScriptHappyCallback } from "@follow/hooks" import type { MasonryFlashListProps } from "@shopify/flash-list" import type { ElementRef } from "react" -import { forwardRef } from "react" +import { forwardRef, useImperativeHandle } from "react" import { View } from "react-native" import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator" @@ -10,7 +10,7 @@ import { usePrefetchEntryTranslation } from "@/src/store/translation/hooks" import { TimelineSelectorMasonryList } from "../screen/TimelineSelectorList" import { GridEntryListFooter } from "./EntryListFooter" -import { useOnViewableItemsChanged } from "./hooks" +import { useOnViewableItemsChanged, usePagerListPerformanceHack } from "./hooks" // import type { MasonryItem } from "./templates/EntryGridItem" import { EntryPictureItem } from "./templates/EntryPictureItem" @@ -20,11 +20,14 @@ export const EntryListContentPicture = forwardRef< MasonryFlashListProps, "data" | "renderItem" > ->(({ entryIds, active, ...rest }, ref) => { +>(({ entryIds, active, ...rest }, forwardRef) => { + const { onScroll: hackOnScroll, ref, style: hackStyle } = usePagerListPerformanceHack() + useImperativeHandle(forwardRef, () => ref.current!) const { fetchNextPage, refetch, isRefetching, hasNextPage, isFetching } = useFetchEntriesControls() const { onViewableItemsChanged, onScroll, viewableItems } = useOnViewableItemsChanged({ disabled: active === false || isFetching, + onScroll: hackOnScroll, }) usePrefetchEntryTranslation(active ? viewableItems.map((item) => item.key) : []) @@ -42,6 +45,7 @@ export const EntryListContentPicture = forwardRef< onScroll={onScroll} onEndReached={fetchNextPage} numColumns={2} + style={hackStyle} estimatedItemSize={100} ListFooterComponent={ hasNextPage ? ( diff --git a/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx b/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx index cea312f00..ebae20229 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentSocial.tsx @@ -1,6 +1,6 @@ import type { ListRenderItemInfo } from "@shopify/flash-list" import type { ElementRef } from "react" -import { forwardRef, useCallback, useMemo } from "react" +import { forwardRef, useCallback, useImperativeHandle, useMemo } from "react" import { View } from "react-native" import { usePrefetchEntryTranslation } from "@/src/store/translation/hooks" @@ -8,17 +8,20 @@ import { usePrefetchEntryTranslation } from "@/src/store/translation/hooks" import { useFetchEntriesControls } from "../screen/atoms" import { TimelineSelectorList } from "../screen/TimelineSelectorList" import { EntryListFooter } from "./EntryListFooter" -import { useOnViewableItemsChanged } from "./hooks" +import { useOnViewableItemsChanged, usePagerListPerformanceHack } from "./hooks" import { ItemSeparatorFullWidth } from "./ItemSeparator" import { EntrySocialItem } from "./templates/EntrySocialItem" export const EntryListContentSocial = forwardRef< ElementRef, { entryIds: string[] | null; active?: boolean } ->(({ entryIds, active }, ref) => { +>(({ entryIds, active }, forwardRef) => { const { fetchNextPage, isFetching, refetch, isRefetching, hasNextPage } = useFetchEntriesControls() + const { onScroll: hackOnScroll, ref, style: hackStyle } = usePagerListPerformanceHack() + useImperativeHandle(forwardRef, () => ref.current!) + // eslint-disable-next-line @eslint-react/hooks-extra/no-unnecessary-use-callback const renderItem = useCallback( ({ item: id }: ListRenderItemInfo) => , [], @@ -31,6 +34,7 @@ export const EntryListContentSocial = forwardRef< const { onViewableItemsChanged, onScroll, viewableItems } = useOnViewableItemsChanged({ disabled: active === false || isFetching, + onScroll: hackOnScroll, }) usePrefetchEntryTranslation(active ? viewableItems.map((item) => item.key) : []) @@ -51,6 +55,7 @@ export const EntryListContentSocial = forwardRef< onScroll={onScroll} ItemSeparatorComponent={ItemSeparatorFullWidth} ListFooterComponent={ListFooterComponent} + style={hackStyle} /> ) }) diff --git a/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx b/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx index 8101c6432..2aa29ba5e 100644 --- a/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx +++ b/apps/mobile/src/modules/entry-list/EntryListContentVideo.tsx @@ -1,7 +1,7 @@ import { useTypeScriptHappyCallback } from "@follow/hooks" import type { MasonryFlashListProps } from "@shopify/flash-list" import type { ElementRef } from "react" -import { forwardRef, useMemo } from "react" +import { forwardRef, useImperativeHandle, useMemo } from "react" import { View } from "react-native" import { useFetchEntriesControls } from "@/src/modules/screen/atoms" @@ -9,7 +9,7 @@ import { usePrefetchEntryTranslation } from "@/src/store/translation/hooks" import { TimelineSelectorMasonryList } from "../screen/TimelineSelectorList" import { GridEntryListFooter } from "./EntryListFooter" -import { useOnViewableItemsChanged } from "./hooks" +import { useOnViewableItemsChanged, usePagerListPerformanceHack } from "./hooks" import { EntryVideoItem } from "./templates/EntryVideoItem" export const EntryListContentVideo = forwardRef< @@ -18,11 +18,14 @@ export const EntryListContentVideo = forwardRef< MasonryFlashListProps, "data" | "renderItem" > ->(({ entryIds, active, ...rest }, ref) => { +>(({ entryIds, active, ...rest }, forwardRef) => { + const { onScroll: hackOnScroll, ref, style: hackStyle } = usePagerListPerformanceHack() + useImperativeHandle(forwardRef, () => ref.current!) const { fetchNextPage, refetch, isRefetching, isFetching, hasNextPage } = useFetchEntriesControls() const { onViewableItemsChanged, onScroll, viewableItems } = useOnViewableItemsChanged({ disabled: active === false || isFetching, + onScroll: hackOnScroll, }) usePrefetchEntryTranslation(active ? viewableItems.map((item) => item.key) : []) @@ -57,6 +60,7 @@ export const EntryListContentVideo = forwardRef< ListFooterComponent={ListFooterComponent} {...rest} onRefresh={refetch} + style={hackStyle} /> ) }) diff --git a/apps/mobile/src/modules/entry-list/hooks.ts b/apps/mobile/src/modules/entry-list/hooks.ts index 96ce3ed64..a999111e2 100644 --- a/apps/mobile/src/modules/entry-list/hooks.ts +++ b/apps/mobile/src/modules/entry-list/hooks.ts @@ -1,18 +1,33 @@ +import type { FlashList } from "@shopify/flash-list" import type ViewToken from "@shopify/flash-list/dist/viewability/ViewToken" -import { useCallback, useEffect, useInsertionEffect, useMemo, useRef, useState } from "react" -import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native" +import type { RefObject } from "react" +import { + useCallback, + useContext, + useEffect, + useInsertionEffect, + useMemo, + useRef, + useState, +} from "react" +import type { NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle } from "react-native" +import { useEventCallback } from "usehooks-ts" import { useGeneralSettingKey } from "@/src/atoms/settings/general" import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store" import { unreadSyncService } from "@/src/store/unread/store" +import { PagerListVisibleContext, PagerListWillVisibleContext } from "../screen/PagerListContext" + const defaultIdExtractor = (item: ViewToken) => item.key export function useOnViewableItemsChanged({ disabled, idExtractor = defaultIdExtractor, + onScroll: onScrollProp, }: { disabled?: boolean idExtractor?: (item: ViewToken) => string + onScroll?: (e: NativeSyntheticEvent) => void } = {}) { const orientation = useRef<"down" | "up">("down") const lastOffset = useRef(0) @@ -82,12 +97,16 @@ export function useOnViewableItemsChanged({ stableIdExtractor, ]) - const onScroll = useCallback((e: NativeSyntheticEvent) => { - const currentOffset = e.nativeEvent.contentOffset.y - const currentOrientation = currentOffset > lastOffset.current ? "down" : "up" - orientation.current = currentOrientation - lastOffset.current = currentOffset - }, []) + const onScroll = useCallback( + (e: NativeSyntheticEvent) => { + const currentOffset = e.nativeEvent.contentOffset.y + const currentOrientation = currentOffset > lastOffset.current ? "down" : "up" + orientation.current = currentOrientation + lastOffset.current = currentOffset + onScrollProp?.(e) + }, + [onScrollProp], + ) return useMemo( () => ({ onViewableItemsChanged, onScroll, viewableItems }), @@ -108,3 +127,33 @@ function useNonReactiveCallback any>(fn: T): T { [ref], ) as unknown as T } + +export const usePagerListPerformanceHack = (provideRef?: RefObject>) => { + const lastY = useRef(0) + + const onScroll = useEventCallback((e: NativeSyntheticEvent) => { + if (!visible) return + + lastY.current = e.nativeEvent.contentOffset.y + }) + + const visible = useContext(PagerListVisibleContext) + const willVisible = useContext(PagerListWillVisibleContext) + + const nextVisible = visible || willVisible + + const ref = useRef>(null) + + const usingRef = provideRef ?? ref + const [style, setStyle] = useState>({}) + useEffect(() => { + setStyle({ display: nextVisible ? "flex" : "none" }) + if (nextVisible && lastY.current > 0) { + requestAnimationFrame(() => { + usingRef.current?.scrollToOffset({ offset: lastY.current, animated: false }) + }) + } + }, [nextVisible, usingRef]) + + return { onScroll, ref, style } +} diff --git a/apps/mobile/src/modules/screen/PageList.tsx b/apps/mobile/src/modules/screen/PageList.tsx index 40fa71584..d22895327 100644 --- a/apps/mobile/src/modules/screen/PageList.tsx +++ b/apps/mobile/src/modules/screen/PageList.tsx @@ -1,7 +1,7 @@ import type { FeedViewType } from "@follow/constants" import { EventBus } from "@follow/utils/src/event-bus" import * as Haptics from "expo-haptics" -import { useCallback, useEffect, useId, useMemo, useRef } from "react" +import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react" import type { StyleProp, ViewStyle } from "react-native" import { Animated, StyleSheet } from "react-native" import PagerView from "react-native-pager-view" @@ -11,6 +11,7 @@ import { selectTimeline, useSelectedFeed } from "@/src/modules/screen/atoms" import { useViewWithSubscription } from "@/src/store/subscription/hooks" import { setHorizontalScrolling } from "./atoms" +import { PagerListVisibleContext, PagerListWillVisibleContext } from "./PagerListContext" const AnimatedPagerView = Animated.createAnimatedComponent(PagerView) @@ -43,6 +44,7 @@ export function PagerList({ }, [activeViews, pagerRef, rid]) const userInitiatedDragRef = useSharedValue(false) + const [dragging, setDragging] = useState(false) const pageScrollHandler = useCallback( (e: { nativeEvent: { @@ -86,11 +88,16 @@ export function PagerList({ overdrag onPageScroll={pageScrollHandler} onPageScrollStateChanged={(e) => { - if (e.nativeEvent.pageScrollState === "dragging") { + const { pageScrollState } = e.nativeEvent + if (pageScrollState === "dragging") { + setDragging(true) userInitiatedDragRef.value = true + } else if (pageScrollState === "idle") { + setDragging(false) } - setHorizontalScrolling(e.nativeEvent.pageScrollState !== "idle") - if (e.nativeEvent.pageScrollState === "settling") { + + setHorizontalScrolling(pageScrollState !== "idle") + if (pageScrollState === "settling") { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light) } }} @@ -98,8 +105,17 @@ export function PagerList({ orientation="horizontal" > {useMemo( - () => activeViews.map((view, index) => renderItem(view.view, index === activeViewIndex)), - [activeViews, activeViewIndex, renderItem], + () => + activeViews.map((view, index) => ( + + + {renderItem(view.view, index === activeViewIndex)} + + + )), + [activeViews, activeViewIndex, dragging, renderItem], )} ) diff --git a/apps/mobile/src/modules/screen/PagerListContext.ts b/apps/mobile/src/modules/screen/PagerListContext.ts new file mode 100644 index 000000000..48b0773fb --- /dev/null +++ b/apps/mobile/src/modules/screen/PagerListContext.ts @@ -0,0 +1,4 @@ +import { createContext } from "react" + +export const PagerListVisibleContext = createContext(false) +export const PagerListWillVisibleContext = createContext(false) diff --git a/apps/mobile/src/modules/screen/TimelineSelectorList.tsx b/apps/mobile/src/modules/screen/TimelineSelectorList.tsx index d759588c5..cf4698b31 100644 --- a/apps/mobile/src/modules/screen/TimelineSelectorList.tsx +++ b/apps/mobile/src/modules/screen/TimelineSelectorList.tsx @@ -8,15 +8,21 @@ import type { import { FlashList, MasonryFlashList } from "@shopify/flash-list" import * as Haptics from "expo-haptics" import type { ElementRef, RefObject } from "react" -import { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useRef } from "react" +import { + forwardRef, + useCallback, + useContext, + useImperativeHandle, + useLayoutEffect, + useRef, +} from "react" import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native" -import { findNodeHandle, RefreshControl } from "react-native" +import { RefreshControl, View } from "react-native" import { useSafeAreaInsets } from "react-native-safe-area-context" import { useColor } from "react-native-uikit-colors" import { BottomTabBarBackgroundContext } from "@/src/components/layouts/tabbar/contexts/BottomTabBarBackgroundContext" import { useBottomTabBarHeight } from "@/src/components/layouts/tabbar/hooks" -import { isScrollToEnd } from "@/src/lib/native" import { useTabScreenIsFocused } from "@/src/lib/navigation/bottom-tab/hooks" import { ScreenItemContext } from "@/src/lib/navigation/ScreenItemContext" import { useHeaderHeight } from "@/src/modules/screen/hooks/useHeaderHeight" @@ -40,36 +46,24 @@ export const TimelineSelectorList = forwardRef< const { refetch: subscriptionRefetch } = usePrefetchSubscription() const headerHeight = useHeaderHeight() - const { reAnimatedScrollY, scrollViewHeight, scrollViewContentHeight } = + const { scrollViewHeight, scrollViewContentHeight, reAnimatedScrollY } = useContext(ScreenItemContext)! const { opacity } = useContext(BottomTabBarBackgroundContext) - const checkScrollToBottom = useCallback(() => { - const handle = findNodeHandle(ref.current!) - if (!handle) { - return - } - isScrollToEnd(handle).then((isEnd) => { - opacity.value = isEnd ? 0 : 1 - }) - }, [opacity]) const tabScreenIsFocus = useTabScreenIsFocused() - useEffect(() => { + useLayoutEffect(() => { if (tabScreenIsFocus) { - checkScrollToBottom() + opacity.value = 1 } - }, [checkScrollToBottom, tabScreenIsFocus]) + }, [tabScreenIsFocus, opacity]) + const tabBarHeight = useBottomTabBarHeight() const onScroll = useCallback( (e: NativeSyntheticEvent) => { props.onScroll?.(e) reAnimatedScrollY.value = e.nativeEvent.contentOffset.y - checkScrollToBottom() }, - [props, reAnimatedScrollY, checkScrollToBottom], + [props, reAnimatedScrollY], ) - - const tabBarHeight = useBottomTabBarHeight() - const systemFill = useColor("secondaryLabel") const onLayout = useTypeScriptHappyCallback( @@ -91,42 +85,44 @@ export const TimelineSelectorList = forwardRef< } return ( - { - unreadRefetch() - subscriptionRefetch() - Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light) - onRefresh() - }} - refreshing={isRefetching} - /> - } - scrollIndicatorInsets={{ - top: headerHeight, - bottom: tabBarHeight, - }} - contentContainerStyle={{ - paddingTop: headerHeight, - paddingBottom: tabBarHeight, - }} - {...props} - onScroll={onScroll} - onEndReached={() => { - nextFrame(() => { - props.onEndReached?.() - }) - }} - /> + + { + unreadRefetch() + subscriptionRefetch() + Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light) + onRefresh() + }} + refreshing={isRefetching} + /> + } + scrollIndicatorInsets={{ + top: headerHeight, + bottom: tabBarHeight, + }} + contentContainerStyle={{ + paddingTop: headerHeight, + paddingBottom: tabBarHeight, + }} + {...props} + onScroll={onScroll} + onEndReached={() => { + nextFrame(() => { + props.onEndReached?.() + }) + }} + /> + ) }) diff --git a/apps/mobile/src/modules/screen/usePagerView.ts b/apps/mobile/src/modules/screen/usePagerView.ts deleted file mode 100644 index e3caaa9db..000000000 --- a/apps/mobile/src/modules/screen/usePagerView.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * @Author: czy0729 - * @Date: 2023-12-27 15:42:54 - * @Last Modified by: czy0729 - * @Last Modified time: 2024-08-13 16:14:43 - * - * Ported from https://github.com/czy0729/Bangumi/blob/6f2c46bba0bb2c1ffa98fb54d9609d87cb5f06a2/src/components/nested-scroll/hooks/usePagerView.tsx - * License: MIT - */ -import { useCallback, useMemo, useRef, useState } from "react" -import { Animated, Platform, useAnimatedValue } from "react-native" -import type { - default as PagerView, - PagerViewOnPageScrollEventData, - PagerViewOnPageSelectedEvent, - PageScrollStateChangedNativeEvent, -} from "react-native-pager-view" - -export function usePagerView({ - initialPage = 0, - onIndexChange, -}: { - initialPage?: number - onIndexChange?: (index: number) => void -}) { - const pagerRef = useRef(null) - const [activePage, setActivePage] = useState(initialPage) - const [isIdle, setIdle] = useState(true) - - const setPage = useCallback((page: number, animated = true) => { - if (animated) { - pagerRef.current?.setPage(page) - } else { - pagerRef.current?.setPageWithoutAnimation(page) - } - setActivePage(page) - }, []) - - const offset = useAnimatedValue(0) - const position = useAnimatedValue(initialPage) - - const onPageScroll = useMemo( - () => - Animated.event( - [ - { - nativeEvent: { - offset, - position, - }, - }, - ], - { - useNativeDriver: true, - }, - ), - [offset, position], - ) - - const onPageSelected = useCallback( - (e: PagerViewOnPageSelectedEvent) => { - const { position } = e.nativeEvent - setActivePage(position) - if (Platform.OS === "ios") setIdle(true) - - if (typeof onIndexChange === "function") onIndexChange(position) - }, - [onIndexChange], - ) - - const onPageScrollStateChanged = useCallback( - ({ nativeEvent: { pageScrollState } }: PageScrollStateChangedNativeEvent) => { - setIdle(pageScrollState === "idle") - }, - [], - ) - - return { - pagerRef, - setPage, - page: activePage, - isIdle, - position, - offset, - onPageScroll, - onPageSelected, - onPageScrollStateChanged, - } -} diff --git a/apps/mobile/src/modules/settings/UserHeaderBanner.tsx b/apps/mobile/src/modules/settings/UserHeaderBanner.tsx index 5a948e269..0ecbdd679 100644 --- a/apps/mobile/src/modules/settings/UserHeaderBanner.tsx +++ b/apps/mobile/src/modules/settings/UserHeaderBanner.tsx @@ -64,7 +64,7 @@ export const UserHeaderBanner = ({ if (!gradientColors) return {} return { transform: [{ scale: scaleValue }], - height: 250 + (scrollY.value < 0 ? -scrollY.value : 0), + height: 250, } }) @@ -118,8 +118,8 @@ export const UserHeaderBanner = ({ )} >(active) + const { onScroll, style } = usePagerListPerformanceHack(scrollViewRef) + return ( ) } diff --git a/apps/mobile/src/screens/(stack)/(tabs)/discover.tsx b/apps/mobile/src/screens/(stack)/(tabs)/discover.tsx index d2e7f598c..4ad97dec1 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/discover.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/discover.tsx @@ -20,6 +20,7 @@ export default function Discover() { () => ({ animatedX, currentTabAtom, headerHeightAtom, animatedY }), [animatedX, currentTabAtom, headerHeightAtom, animatedY], ) + return ( diff --git a/apps/mobile/src/store/entry/hooks.ts b/apps/mobile/src/store/entry/hooks.ts index 6b0c256b4..d6ffa67ea 100644 --- a/apps/mobile/src/store/entry/hooks.ts +++ b/apps/mobile/src/store/entry/hooks.ts @@ -20,6 +20,7 @@ export const usePrefetchEntries = (props: Omit {