diff --git a/apps/mobile/src/components/ui/accordion/index.tsx b/apps/mobile/src/components/ui/accordion/AccordionItem.tsx similarity index 100% rename from apps/mobile/src/components/ui/accordion/index.tsx rename to apps/mobile/src/components/ui/accordion/AccordionItem.tsx diff --git a/apps/mobile/src/modules/subscription/list.tsx b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx similarity index 79% rename from apps/mobile/src/modules/subscription/list.tsx rename to apps/mobile/src/modules/subscription/SubscriptionLists.tsx index 015165869..5f1f647f2 100644 --- a/apps/mobile/src/modules/subscription/list.tsx +++ b/apps/mobile/src/modules/subscription/SubscriptionLists.tsx @@ -2,19 +2,22 @@ import { FeedViewType } from "@follow/constants" import { cn } from "@follow/utils" import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs" import { useHeaderHeight } from "@react-navigation/elements" -import { FlashList } from "@shopify/flash-list" import { router } from "expo-router" import { useAtom } from "jotai" import { useColorScheme } from "nativewind" import type { FC } from "react" -import { createContext, memo, useContext, useEffect, useMemo, useRef } from "react" -import { Animated, Easing, Image, StyleSheet, Text, useAnimatedValue, View } from "react-native" +import { createContext, memo, useContext, useEffect, useMemo, useRef, useState } from "react" +import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native" import PagerView from "react-native-pager-view" -import { useSharedValue } from "react-native-reanimated" +import ReAnimated, { + FadeOutUp, + LinearTransition, + useAnimatedStyle, + useSharedValue, + withSpring, +} from "react-native-reanimated" import { useSafeAreaInsets } from "react-native-safe-area-context" -import { AnimatedTouchableOpacity } from "@/src/components/common/AnimatedComponents" -import { AccordionItem } from "@/src/components/ui/accordion" import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon" import { FeedIcon } from "@/src/components/ui/icon/feed-icon" import { ItemPressable } from "@/src/components/ui/pressable/item-pressable" @@ -45,7 +48,7 @@ import { SubscriptionListItemContextMenu } from "../context-menu/lists" import { useFeedListSortMethod, useFeedListSortOrder, viewAtom } from "./atoms" import { useViewPageCurrentView, ViewPageCurrentViewProvider } from "./ctx" -export const SubscriptionList = memo(() => { +export const SubscriptionLists = memo(() => { const [currentView, setCurrentView] = useAtom(viewAtom) const pagerRef = useRef(null) @@ -79,7 +82,7 @@ export const SubscriptionList = memo(() => { ].map((view) => { return ( - + ) })} @@ -87,7 +90,13 @@ export const SubscriptionList = memo(() => { ) }) -const RecycleList = ({ view }: { view: FeedViewType }) => { +const keyExtractor = (item: string | { category: string; subscriptionIds: string[] }) => { + if (typeof item === "string") { + return item + } + return item.category +} +const SubscriptionList = ({ view }: { view: FeedViewType }) => { const headerHeight = useHeaderHeight() const insets = useSafeAreaInsets() const tabHeight = useBottomTabBarHeight() @@ -105,7 +114,7 @@ const RecycleList = ({ view }: { view: FeedViewType }) => { ) return ( - { paddingBottom: tabHeight, }} data={data} - estimatedItemSize={48} ListHeaderComponent={ListHeaderComponent} renderItem={ItemRender} + keyExtractor={keyExtractor} + itemLayoutAnimation={LinearTransition} extraData={{ total: data.length, }} @@ -298,54 +308,50 @@ const GroupedContext = createContext(null) const CategoryGrouped = memo( ({ category, subscriptionIds }: { category: string; subscriptionIds: string[] }) => { const unreadCounts = useUnreadCounts(subscriptionIds) - const isExpanded = useSharedValue(false) - const rotateValue = useAnimatedValue(1) + const [expanded, setExpanded] = useState(false) + const rotateSharedValue = useSharedValue(0) + const rotateStyle = useAnimatedStyle(() => { + return { + transform: [{ rotate: `${rotateSharedValue.value}deg` }], + } + }, [rotateSharedValue]) return ( - - { - // TODO navigate to category - }} - className="border-item-pressed h-12 flex-row items-center border-b px-3" - > - + + { - Animated.timing(rotateValue, { - toValue: isExpanded.value ? 1 : 0, - easing: Easing.linear, - - useNativeDriver: true, - }).start() - isExpanded.value = !isExpanded.value + // TODO navigate to category }} - style={[ - { - transform: [ - { - rotate: rotateValue.interpolate({ - inputRange: [0, 1], - outputRange: ["90deg", "0deg"], - }), - }, - ], - }, - style.accordionIcon, - ]} + className="border-item-pressed h-12 flex-row items-center border-b px-3" > - - - {category} - {!!unreadCounts && ( - {unreadCounts} - )} - - + { + rotateSharedValue.value = withSpring(expanded ? 90 : 0, {}) + setExpanded(!expanded) + }} + style={style.accordionIcon} + > + + + + + {category} + {!!unreadCounts && ( + {unreadCounts} + )} + + + {/* */} + {expanded && ( - + + + - - + )} + {/* */} + ) }, ) @@ -407,33 +413,34 @@ const SubscriptionItem = memo(({ id, className }: { id: string; className?: stri // }} // > // - - { - router.push({ - pathname: `/feeds/[feedId]`, - params: { - feedId: id, - }, - }) - }} - > - - - - {subscription.title || feed.title} - {!!unreadCount && ( - {unreadCount} - )} - - - // + + + { + router.push({ + pathname: `/feeds/[feedId]`, + params: { + feedId: id, + }, + }) + }} + > + + + + {subscription.title || feed.title} + {!!unreadCount && ( + {unreadCount} + )} + + + // ) }) diff --git a/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx b/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx index 216f21511..a2d51462e 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/subscription.tsx @@ -6,7 +6,7 @@ import { views } from "@/src/constants/views" import { AddCuteReIcon } from "@/src/icons/add_cute_re" import { useCurrentView } from "@/src/modules/subscription/atoms" import { SortActionButton } from "@/src/modules/subscription/header-actions" -import { SubscriptionList } from "@/src/modules/subscription/list" +import { SubscriptionLists } from "@/src/modules/subscription/SubscriptionLists" import { usePrefetchUnread } from "@/src/store/unread/hooks" import { accentColor } from "@/src/theme/colors" @@ -27,7 +27,7 @@ export default function FeedList() { headerTransparent: true, }} /> - + )