feat(rn): subscription list refresh contril
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -1 +0,0 @@
|
||||
export const bottomViewTabHeight = 35
|
||||
@@ -0,0 +1,69 @@
|
||||
import { memo, useState } from "react"
|
||||
import { Text, TouchableOpacity, View } from "react-native"
|
||||
import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated"
|
||||
|
||||
import { ItemPressable } from "@/src/components/ui/pressable/item-pressable"
|
||||
import { MingcuteRightLine } from "@/src/icons/mingcute_right_line"
|
||||
import { useUnreadCounts } from "@/src/store/unread/hooks"
|
||||
|
||||
import { SubscriptionFeedCategoryContextMenu } from "../context-menu/feeds"
|
||||
import { GroupedContext } from "./ctx"
|
||||
import { UnGroupedList } from "./UnGroupedList"
|
||||
|
||||
// const CategoryList: FC<{
|
||||
// grouped: Record<string, string[]>
|
||||
// }> = ({ grouped }) => {
|
||||
// const sortedGrouped = useSortedGroupedSubscription(grouped, "alphabet")
|
||||
// return sortedGrouped.map(({ category, subscriptionIds }) => {
|
||||
// return <CategoryGrouped key={category} category={category} subscriptionIds={subscriptionIds} />
|
||||
// })
|
||||
// }
|
||||
export const CategoryGrouped = memo(
|
||||
({ category, subscriptionIds }: { category: string; subscriptionIds: string[] }) => {
|
||||
const unreadCounts = useUnreadCounts(subscriptionIds)
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const rotateSharedValue = useSharedValue(0)
|
||||
const rotateStyle = useAnimatedStyle(() => {
|
||||
return {
|
||||
transform: [{ rotate: `${rotateSharedValue.value}deg` }],
|
||||
}
|
||||
}, [rotateSharedValue])
|
||||
return (
|
||||
<>
|
||||
<SubscriptionFeedCategoryContextMenu category={category} feedIds={subscriptionIds}>
|
||||
<ItemPressable
|
||||
onPress={() => {
|
||||
// TODO navigate to category
|
||||
}}
|
||||
className="border-item-pressed h-12 flex-row items-center border-b px-3"
|
||||
>
|
||||
<TouchableOpacity
|
||||
hitSlop={10}
|
||||
onPress={() => {
|
||||
rotateSharedValue.value = withSpring(expanded ? 0 : 90, {})
|
||||
setExpanded(!expanded)
|
||||
}}
|
||||
className="size-5 flex-row items-center justify-center"
|
||||
>
|
||||
<Animated.View style={rotateStyle}>
|
||||
<MingcuteRightLine color="gray" height={18} width={18} />
|
||||
</Animated.View>
|
||||
</TouchableOpacity>
|
||||
<Text className="text-text ml-3">{category}</Text>
|
||||
{!!unreadCounts && (
|
||||
<Text className="text-tertiary-label ml-auto text-xs">{unreadCounts}</Text>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</SubscriptionFeedCategoryContextMenu>
|
||||
|
||||
{expanded && (
|
||||
<GroupedContext.Provider value={category}>
|
||||
<View>
|
||||
<UnGroupedList subscriptionIds={subscriptionIds} />
|
||||
</View>
|
||||
</GroupedContext.Provider>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
},
|
||||
)
|
||||
@@ -1,32 +1,16 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { cn } from "@follow/utils"
|
||||
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs"
|
||||
import { useHeaderHeight } from "@react-navigation/elements"
|
||||
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, useState } from "react"
|
||||
import { Image, StyleSheet, Text, TouchableOpacity, View } from "react-native"
|
||||
import { memo, useEffect, useMemo, useRef, useState } from "react"
|
||||
import { RefreshControl, StyleSheet, Text, View } from "react-native"
|
||||
import PagerView from "react-native-pager-view"
|
||||
import ReAnimated, {
|
||||
FadeOutUp,
|
||||
LinearTransition,
|
||||
useAnimatedStyle,
|
||||
useSharedValue,
|
||||
withSpring,
|
||||
} from "react-native-reanimated"
|
||||
import ReAnimated, { LinearTransition } from "react-native-reanimated"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
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"
|
||||
import { bottomViewTabHeight } from "@/src/constants/ui"
|
||||
import { InboxCuteFiIcon } from "@/src/icons/inbox_cute_fi"
|
||||
import { MingcuteRightLine } from "@/src/icons/mingcute_right_line"
|
||||
import { StarCuteFiIcon } from "@/src/icons/star_cute_fi"
|
||||
import { useFeed } from "@/src/store/feed/hooks"
|
||||
import { useList } from "@/src/store/list/hooks"
|
||||
import {
|
||||
useGroupedSubscription,
|
||||
useInboxSubscription,
|
||||
@@ -35,18 +19,16 @@ import {
|
||||
useSortedGroupedSubscription,
|
||||
useSortedListSubscription,
|
||||
useSortedUngroupedSubscription,
|
||||
useSubscription,
|
||||
} from "@/src/store/subscription/hooks"
|
||||
import { getInboxStoreId } from "@/src/store/subscription/utils"
|
||||
import { useUnreadCount, useUnreadCounts } from "@/src/store/unread/hooks"
|
||||
import { subscriptionSyncService } from "@/src/store/subscription/store"
|
||||
|
||||
import {
|
||||
SubscriptionFeedCategoryContextMenu,
|
||||
SubscriptionFeedItemContextMenu,
|
||||
} from "../context-menu/feeds"
|
||||
import { SubscriptionListItemContextMenu } from "../context-menu/lists"
|
||||
import { useFeedListSortMethod, useFeedListSortOrder, viewAtom } from "./atoms"
|
||||
import { CategoryGrouped } from "./CategoryGrouped"
|
||||
import { ViewTabHeight } from "./constants"
|
||||
import { useViewPageCurrentView, ViewPageCurrentViewProvider } from "./ctx"
|
||||
import { InboxItem } from "./items/InboxItem"
|
||||
import { ListSubscriptionItem } from "./items/ListSubscriptionItem"
|
||||
import { SubscriptionItem } from "./items/SubscriptionItem"
|
||||
|
||||
export const SubscriptionLists = memo(() => {
|
||||
const [currentView, setCurrentView] = useAtom(viewAtom)
|
||||
@@ -58,36 +40,32 @@ export const SubscriptionLists = memo(() => {
|
||||
}, [currentView])
|
||||
|
||||
return (
|
||||
<>
|
||||
<StarItem />
|
||||
|
||||
<PagerView
|
||||
pageMargin={1}
|
||||
onPageSelected={({ nativeEvent }) => {
|
||||
setCurrentView(nativeEvent.position)
|
||||
}}
|
||||
scrollEnabled
|
||||
style={style.flex}
|
||||
initialPage={0}
|
||||
ref={pagerRef}
|
||||
offscreenPageLimit={3}
|
||||
>
|
||||
{[
|
||||
FeedViewType.Articles,
|
||||
FeedViewType.SocialMedia,
|
||||
FeedViewType.Pictures,
|
||||
FeedViewType.Videos,
|
||||
FeedViewType.Audios,
|
||||
FeedViewType.Notifications,
|
||||
].map((view) => {
|
||||
return (
|
||||
<ViewPageCurrentViewProvider key={view} value={view}>
|
||||
<SubscriptionList view={view} />
|
||||
</ViewPageCurrentViewProvider>
|
||||
)
|
||||
})}
|
||||
</PagerView>
|
||||
</>
|
||||
<PagerView
|
||||
pageMargin={1}
|
||||
onPageSelected={({ nativeEvent }) => {
|
||||
setCurrentView(nativeEvent.position)
|
||||
}}
|
||||
scrollEnabled
|
||||
style={style.flex}
|
||||
initialPage={0}
|
||||
ref={pagerRef}
|
||||
offscreenPageLimit={3}
|
||||
>
|
||||
{[
|
||||
FeedViewType.Articles,
|
||||
FeedViewType.SocialMedia,
|
||||
FeedViewType.Pictures,
|
||||
FeedViewType.Videos,
|
||||
FeedViewType.Audios,
|
||||
FeedViewType.Notifications,
|
||||
].map((view) => {
|
||||
return (
|
||||
<ViewPageCurrentViewProvider key={view} value={view}>
|
||||
<SubscriptionList view={view} />
|
||||
</ViewPageCurrentViewProvider>
|
||||
)
|
||||
})}
|
||||
</PagerView>
|
||||
)
|
||||
})
|
||||
const keyExtractor = (item: string | { category: string; subscriptionIds: string[] }) => {
|
||||
@@ -113,15 +91,34 @@ const SubscriptionList = ({ view }: { view: FeedViewType }) => {
|
||||
[sortedGrouped, sortedUnGrouped],
|
||||
)
|
||||
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
const onRefresh = useEventCallback(() => {
|
||||
return subscriptionSyncService.fetch(view)
|
||||
})
|
||||
|
||||
const offsetTop = headerHeight - insets.top + ViewTabHeight * 2 + 23
|
||||
|
||||
return (
|
||||
<ReAnimated.FlatList
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
progressViewOffset={offsetTop}
|
||||
onRefresh={() => {
|
||||
setRefreshing(true)
|
||||
onRefresh().finally(() => {
|
||||
setRefreshing(false)
|
||||
})
|
||||
}}
|
||||
refreshing={refreshing}
|
||||
/>
|
||||
}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
scrollIndicatorInsets={{
|
||||
bottom: tabHeight - insets.bottom,
|
||||
top: headerHeight - insets.top + bottomViewTabHeight,
|
||||
top: offsetTop,
|
||||
}}
|
||||
contentContainerStyle={{
|
||||
paddingTop: headerHeight - insets.top + bottomViewTabHeight,
|
||||
paddingTop: offsetTop,
|
||||
paddingBottom: tabHeight,
|
||||
}}
|
||||
data={data}
|
||||
@@ -173,23 +170,6 @@ const ListHeaderComponent = () => {
|
||||
)
|
||||
}
|
||||
|
||||
// This not used FlashList
|
||||
// const ViewPage = memo(({ view }: { view: FeedViewType }) => {
|
||||
// const { grouped, unGrouped } = useGroupedSubscription(view)
|
||||
// usePrefetchSubscription(view)
|
||||
|
||||
// return (
|
||||
// <ViewPageCurrentViewProvider value={view}>
|
||||
// <StarItem />
|
||||
// {view === FeedViewType.Articles && <InboxList />}
|
||||
// <ListList />
|
||||
// <Text className="text-tertiary-label mb-2 ml-3 mt-4 text-sm font-medium">Feeds</Text>
|
||||
// <CategoryList grouped={grouped} />
|
||||
// <UnGroupedList subscriptionIds={unGrouped} />
|
||||
// </ViewPageCurrentViewProvider>
|
||||
// )
|
||||
// })
|
||||
|
||||
const InboxList = () => {
|
||||
const inboxes = useInboxSubscription(FeedViewType.Articles)
|
||||
if (inboxes.length === 0) return null
|
||||
@@ -203,27 +183,6 @@ const InboxList = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const InboxItem = memo(({ id }: { id: string }) => {
|
||||
const subscription = useSubscription(getInboxStoreId(id))
|
||||
const unreadCount = useUnreadCount(id)
|
||||
const { colorScheme } = useColorScheme()
|
||||
if (!subscription) return null
|
||||
return (
|
||||
<ItemPressable className="border-item-pressed h-12 flex-row items-center border-b px-3">
|
||||
<View className="ml-0.5 overflow-hidden rounded">
|
||||
<InboxCuteFiIcon
|
||||
height={20}
|
||||
width={20}
|
||||
color={colorScheme === "dark" ? "white" : "black"}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<Text className="text-text ml-2.5">{subscription.title}</Text>
|
||||
{!!unreadCount && <Text className="text-tertiary-label ml-auto text-xs">{unreadCount}</Text>}
|
||||
</ItemPressable>
|
||||
)
|
||||
})
|
||||
|
||||
const StarItem = () => {
|
||||
return (
|
||||
<ItemPressable
|
||||
@@ -253,206 +212,8 @@ const ListList = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const ListSubscriptionItem = memo(({ id }: { id: string; className?: string }) => {
|
||||
const list = useList(id)
|
||||
const unreadCount = useUnreadCount(id)
|
||||
if (!list) return null
|
||||
return (
|
||||
<SubscriptionListItemContextMenu id={id}>
|
||||
<ItemPressable className="border-item-pressed h-12 flex-row items-center border-b px-3">
|
||||
<View className="overflow-hidden rounded">
|
||||
{!!list.image && (
|
||||
<Image source={{ uri: list.image, width: 24, height: 24 }} resizeMode="cover" />
|
||||
)}
|
||||
{!list.image && <FallbackIcon title={list.title} size={24} />}
|
||||
</View>
|
||||
|
||||
<Text className="text-text ml-2">{list.title}</Text>
|
||||
{!!unreadCount && <View className="bg-tertiary-label ml-auto size-1 rounded-full" />}
|
||||
</ItemPressable>
|
||||
</SubscriptionListItemContextMenu>
|
||||
)
|
||||
})
|
||||
|
||||
const UnGroupedList: FC<{
|
||||
subscriptionIds: string[]
|
||||
}> = ({ subscriptionIds }) => {
|
||||
const sortBy = useFeedListSortMethod()
|
||||
const sortOrder = useFeedListSortOrder()
|
||||
const sortedSubscriptionIds = useSortedUngroupedSubscription(subscriptionIds, sortBy, sortOrder)
|
||||
const lastSubscriptionId = sortedSubscriptionIds.at(-1)
|
||||
|
||||
return sortedSubscriptionIds.map((id) => {
|
||||
return (
|
||||
<SubscriptionItem
|
||||
key={id}
|
||||
id={id}
|
||||
className={id === lastSubscriptionId ? "border-b-transparent" : ""}
|
||||
/>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const GroupedContext = createContext<string | null>(null)
|
||||
|
||||
// const CategoryList: FC<{
|
||||
// grouped: Record<string, string[]>
|
||||
// }> = ({ grouped }) => {
|
||||
// const sortedGrouped = useSortedGroupedSubscription(grouped, "alphabet")
|
||||
|
||||
// return sortedGrouped.map(({ category, subscriptionIds }) => {
|
||||
// return <CategoryGrouped key={category} category={category} subscriptionIds={subscriptionIds} />
|
||||
// })
|
||||
// }
|
||||
|
||||
const CategoryGrouped = memo(
|
||||
({ category, subscriptionIds }: { category: string; subscriptionIds: string[] }) => {
|
||||
const unreadCounts = useUnreadCounts(subscriptionIds)
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const rotateSharedValue = useSharedValue(0)
|
||||
const rotateStyle = useAnimatedStyle(() => {
|
||||
return {
|
||||
transform: [{ rotate: `${rotateSharedValue.value}deg` }],
|
||||
}
|
||||
}, [rotateSharedValue])
|
||||
return (
|
||||
<>
|
||||
<SubscriptionFeedCategoryContextMenu category={category} feedIds={subscriptionIds}>
|
||||
<ItemPressable
|
||||
onPress={() => {
|
||||
// TODO navigate to category
|
||||
}}
|
||||
className="border-item-pressed h-12 flex-row items-center border-b px-3"
|
||||
>
|
||||
<TouchableOpacity
|
||||
hitSlop={10}
|
||||
onPress={() => {
|
||||
rotateSharedValue.value = withSpring(expanded ? 90 : 0, {})
|
||||
setExpanded(!expanded)
|
||||
}}
|
||||
style={style.accordionIcon}
|
||||
>
|
||||
<ReAnimated.View style={rotateStyle}>
|
||||
<MingcuteRightLine color="gray" height={18} width={18} />
|
||||
</ReAnimated.View>
|
||||
</TouchableOpacity>
|
||||
<Text className="text-text ml-3">{category}</Text>
|
||||
{!!unreadCounts && (
|
||||
<Text className="text-tertiary-label ml-auto text-xs">{unreadCounts}</Text>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</SubscriptionFeedCategoryContextMenu>
|
||||
{/* <AccordionItem isExpanded={isExpanded} viewKey={category}> */}
|
||||
{expanded && (
|
||||
<GroupedContext.Provider value={category}>
|
||||
<View>
|
||||
<UnGroupedList subscriptionIds={subscriptionIds} />
|
||||
</View>
|
||||
</GroupedContext.Provider>
|
||||
)}
|
||||
{/* </AccordionItem> */}
|
||||
</>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
// const renderRightActions = () => {
|
||||
// return (
|
||||
// <ReAnimated.View entering={FadeIn} className="flex-row items-center">
|
||||
// <TouchableOpacity
|
||||
// className="bg-red h-full justify-center px-4"
|
||||
// onPress={() => {
|
||||
// // TODO: Handle unsubscribe
|
||||
// }}
|
||||
// >
|
||||
// <Text className="text-base font-semibold text-white">Unsubscribe</Text>
|
||||
// </TouchableOpacity>
|
||||
// </ReAnimated.View>
|
||||
// )
|
||||
// }
|
||||
|
||||
// const renderLeftActions = () => {
|
||||
// return (
|
||||
// <ReAnimated.View entering={FadeIn} className="flex-row items-center">
|
||||
// <TouchableOpacity
|
||||
// className="bg-blue h-full justify-center px-4"
|
||||
// onPress={() => {
|
||||
// // TODO: Handle unsubscribe
|
||||
// }}
|
||||
// >
|
||||
// <Text className="text-base font-semibold text-white">Read</Text>
|
||||
// </TouchableOpacity>
|
||||
// </ReAnimated.View>
|
||||
// )
|
||||
// }
|
||||
|
||||
// let prevOpenedRow: SwipeableMethods | null = null
|
||||
const SubscriptionItem = memo(({ id, className }: { id: string; className?: string }) => {
|
||||
const subscription = useSubscription(id)
|
||||
const unreadCount = useUnreadCount(id)
|
||||
const feed = useFeed(id)
|
||||
const inGrouped = !!useContext(GroupedContext)
|
||||
const view = useViewPageCurrentView()
|
||||
// const swipeableRef: SwipeableRef = useRef(null)
|
||||
|
||||
if (!subscription || !feed) return null
|
||||
|
||||
return (
|
||||
// FIXME: Here leads to very serious performance issues, the frame rate of both the UI and JS threads has dropped
|
||||
// <Swipeable
|
||||
// renderRightActions={renderRightActions}
|
||||
// renderLeftActions={renderLeftActions}
|
||||
// leftThreshold={40}
|
||||
// rightThreshold={40}
|
||||
// ref={swipeableRef}
|
||||
// onSwipeableWillOpen={() => {
|
||||
// if (prevOpenedRow && prevOpenedRow !== swipeableRef.current) {
|
||||
// prevOpenedRow.close()
|
||||
// }
|
||||
// prevOpenedRow = swipeableRef.current
|
||||
// }}
|
||||
// >
|
||||
// <ReAnimated.View key={id} layout={CurvedTransition} exiting={FadeOut}>
|
||||
<ReAnimated.View exiting={FadeOutUp}>
|
||||
<SubscriptionFeedItemContextMenu id={id} view={view}>
|
||||
<ItemPressable
|
||||
className={cn(
|
||||
"flex h-12 flex-row items-center",
|
||||
inGrouped ? "pl-8 pr-4" : "px-4",
|
||||
"border-item-pressed border-b",
|
||||
className,
|
||||
)}
|
||||
onPress={() => {
|
||||
router.push({
|
||||
pathname: `/feeds/[feedId]`,
|
||||
params: {
|
||||
feedId: id,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<View className="dark:border-tertiary-system-background mr-3 size-5 items-center justify-center overflow-hidden rounded-full border border-transparent dark:bg-[#222]">
|
||||
<FeedIcon feed={feed} />
|
||||
</View>
|
||||
<Text className="text-text">{subscription.title || feed.title}</Text>
|
||||
{!!unreadCount && (
|
||||
<Text className="text-tertiary-label ml-auto text-xs">{unreadCount}</Text>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</SubscriptionFeedItemContextMenu>
|
||||
</ReAnimated.View>
|
||||
// </Swipeable>
|
||||
)
|
||||
})
|
||||
|
||||
const style = StyleSheet.create({
|
||||
flex: {
|
||||
flex: 1,
|
||||
},
|
||||
accordionIcon: {
|
||||
height: 20,
|
||||
width: 20,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { FC } from "react"
|
||||
|
||||
import { useSortedUngroupedSubscription } from "@/src/store/subscription/hooks"
|
||||
|
||||
import { useFeedListSortMethod, useFeedListSortOrder } from "./atoms"
|
||||
import { SubscriptionItem } from "./items/SubscriptionItem"
|
||||
|
||||
export const UnGroupedList: FC<{
|
||||
subscriptionIds: string[]
|
||||
}> = ({ subscriptionIds }) => {
|
||||
const sortBy = useFeedListSortMethod()
|
||||
const sortOrder = useFeedListSortOrder()
|
||||
const sortedSubscriptionIds = useSortedUngroupedSubscription(subscriptionIds, sortBy, sortOrder)
|
||||
const lastSubscriptionId = sortedSubscriptionIds.at(-1)
|
||||
|
||||
return sortedSubscriptionIds.map((id) => {
|
||||
return (
|
||||
<SubscriptionItem
|
||||
key={id}
|
||||
id={id}
|
||||
className={id === lastSubscriptionId ? "border-b-transparent" : ""}
|
||||
/>
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import Animated, { useAnimatedStyle, useSharedValue, withSpring } from "react-na
|
||||
|
||||
import { ThemedBlurView } from "@/src/components/common/ThemedBlurView"
|
||||
import { ContextMenu } from "@/src/components/ui/context-menu"
|
||||
import { bottomViewTabHeight } from "@/src/constants/ui"
|
||||
import type { ViewDefinition } from "@/src/constants/views"
|
||||
import { views } from "@/src/constants/views"
|
||||
import { useUnreadCountByView } from "@/src/store/unread/hooks"
|
||||
import { unreadSyncService } from "@/src/store/unread/store"
|
||||
|
||||
import { offsetAtom, setCurrentView, viewAtom } from "./atoms"
|
||||
import { ViewTabHeight } from "./constants"
|
||||
|
||||
const springConfig: WithSpringConfig = {
|
||||
damping: 20,
|
||||
@@ -65,10 +65,10 @@ export const ViewTab = () => {
|
||||
|
||||
return (
|
||||
<ThemedBlurView
|
||||
style={[styles.tabContainer, { height: headerHeight + bottomViewTabHeight }]}
|
||||
style={[styles.tabContainer, { height: headerHeight + ViewTabHeight }]}
|
||||
className="border-system-fill/60 relative border-b"
|
||||
>
|
||||
<View className="absolute inset-x-0 bottom-0" style={{ height: bottomViewTabHeight }}>
|
||||
<View className="absolute inset-x-0 bottom-0" style={{ height: ViewTabHeight }}>
|
||||
<ScrollView
|
||||
onScroll={(event) => {
|
||||
scrollOffsetX.current = event.nativeEvent.contentOffset.x
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const ViewTabHeight = 35
|
||||
@@ -4,3 +4,4 @@ import { createContext, useContext } from "react"
|
||||
const ViewPageCurrentViewContext = createContext<FeedViewType>(null!)
|
||||
export const ViewPageCurrentViewProvider = ViewPageCurrentViewContext.Provider
|
||||
export const useViewPageCurrentView = () => useContext(ViewPageCurrentViewContext)
|
||||
export const GroupedContext = createContext<string | null>(null)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { useColorScheme } from "nativewind"
|
||||
import { memo } from "react"
|
||||
import { Text, View } from "react-native"
|
||||
import Animated, { FadeOutUp } from "react-native-reanimated"
|
||||
|
||||
import { ItemPressable } from "@/src/components/ui/pressable/item-pressable"
|
||||
import { InboxCuteFiIcon } from "@/src/icons/inbox_cute_fi"
|
||||
import { useSubscription } from "@/src/store/subscription/hooks"
|
||||
import { getInboxStoreId } from "@/src/store/subscription/utils"
|
||||
import { useUnreadCount } from "@/src/store/unread/hooks"
|
||||
|
||||
export const InboxItem = memo(({ id }: { id: string }) => {
|
||||
const subscription = useSubscription(getInboxStoreId(id))
|
||||
const unreadCount = useUnreadCount(id)
|
||||
const { colorScheme } = useColorScheme()
|
||||
if (!subscription) return null
|
||||
return (
|
||||
<Animated.View exiting={FadeOutUp}>
|
||||
<ItemPressable className="border-item-pressed h-12 flex-row items-center border-b px-3">
|
||||
<View className="ml-0.5 overflow-hidden rounded">
|
||||
<InboxCuteFiIcon
|
||||
height={20}
|
||||
width={20}
|
||||
color={colorScheme === "dark" ? "white" : "black"}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<Text className="text-text ml-2.5">{subscription.title}</Text>
|
||||
{!!unreadCount && (
|
||||
<Text className="text-tertiary-label ml-auto text-xs">{unreadCount}</Text>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</Animated.View>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { memo } from "react"
|
||||
import { Image, Text, View } from "react-native"
|
||||
import Animated, { FadeOutUp } from "react-native-reanimated"
|
||||
|
||||
import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon"
|
||||
import { ItemPressable } from "@/src/components/ui/pressable/item-pressable"
|
||||
import { useList } from "@/src/store/list/hooks"
|
||||
import { useUnreadCount } from "@/src/store/unread/hooks"
|
||||
|
||||
import { SubscriptionListItemContextMenu } from "../../context-menu/lists"
|
||||
|
||||
export const ListSubscriptionItem = memo(({ id }: { id: string; className?: string }) => {
|
||||
const list = useList(id)
|
||||
const unreadCount = useUnreadCount(id)
|
||||
if (!list) return null
|
||||
return (
|
||||
<Animated.View exiting={FadeOutUp}>
|
||||
<SubscriptionListItemContextMenu id={id}>
|
||||
<ItemPressable className="border-item-pressed h-12 flex-row items-center border-b px-3">
|
||||
<View className="overflow-hidden rounded">
|
||||
{!!list.image && (
|
||||
<Image source={{ uri: list.image, width: 24, height: 24 }} resizeMode="cover" />
|
||||
)}
|
||||
{!list.image && <FallbackIcon title={list.title} size={24} />}
|
||||
</View>
|
||||
|
||||
<Text className="text-text ml-2">{list.title}</Text>
|
||||
{!!unreadCount && <View className="bg-tertiary-label ml-auto size-1 rounded-full" />}
|
||||
</ItemPressable>
|
||||
</SubscriptionListItemContextMenu>
|
||||
</Animated.View>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,100 @@
|
||||
import { cn } from "@follow/utils"
|
||||
import { router } from "expo-router"
|
||||
import { memo, useContext } from "react"
|
||||
import { Text, View } from "react-native"
|
||||
import Animated, { FadeOutUp } from "react-native-reanimated"
|
||||
|
||||
import { FeedIcon } from "@/src/components/ui/icon/feed-icon"
|
||||
import { ItemPressable } from "@/src/components/ui/pressable/item-pressable"
|
||||
import { useFeed } from "@/src/store/feed/hooks"
|
||||
import { useSubscription } from "@/src/store/subscription/hooks"
|
||||
import { useUnreadCount } from "@/src/store/unread/hooks"
|
||||
|
||||
import { SubscriptionFeedItemContextMenu } from "../../context-menu/feeds"
|
||||
import { GroupedContext, useViewPageCurrentView } from "../ctx"
|
||||
|
||||
// const renderRightActions = () => {
|
||||
// return (
|
||||
// <ReAnimated.View entering={FadeIn} className="flex-row items-center">
|
||||
// <TouchableOpacity
|
||||
// className="bg-red h-full justify-center px-4"
|
||||
// onPress={() => {
|
||||
// // TODO: Handle unsubscribe
|
||||
// }}
|
||||
// >
|
||||
// <Text className="text-base font-semibold text-white">Unsubscribe</Text>
|
||||
// </TouchableOpacity>
|
||||
// </ReAnimated.View>
|
||||
// )
|
||||
// }
|
||||
// const renderLeftActions = () => {
|
||||
// return (
|
||||
// <ReAnimated.View entering={FadeIn} className="flex-row items-center">
|
||||
// <TouchableOpacity
|
||||
// className="bg-blue h-full justify-center px-4"
|
||||
// onPress={() => {
|
||||
// // TODO: Handle unsubscribe
|
||||
// }}
|
||||
// >
|
||||
// <Text className="text-base font-semibold text-white">Read</Text>
|
||||
// </TouchableOpacity>
|
||||
// </ReAnimated.View>
|
||||
// )
|
||||
// }
|
||||
// let prevOpenedRow: SwipeableMethods | null = null
|
||||
export const SubscriptionItem = memo(({ id, className }: { id: string; className?: string }) => {
|
||||
const subscription = useSubscription(id)
|
||||
const unreadCount = useUnreadCount(id)
|
||||
const feed = useFeed(id)
|
||||
const inGrouped = !!useContext(GroupedContext)
|
||||
const view = useViewPageCurrentView()
|
||||
// const swipeableRef: SwipeableRef = useRef(null)
|
||||
if (!subscription || !feed) return null
|
||||
|
||||
return (
|
||||
// FIXME: Here leads to very serious performance issues, the frame rate of both the UI and JS threads has dropped
|
||||
// <Swipeable
|
||||
// renderRightActions={renderRightActions}
|
||||
// renderLeftActions={renderLeftActions}
|
||||
// leftThreshold={40}
|
||||
// rightThreshold={40}
|
||||
// ref={swipeableRef}
|
||||
// onSwipeableWillOpen={() => {
|
||||
// if (prevOpenedRow && prevOpenedRow !== swipeableRef.current) {
|
||||
// prevOpenedRow.close()
|
||||
// }
|
||||
// prevOpenedRow = swipeableRef.current
|
||||
// }}
|
||||
// >
|
||||
// <ReAnimated.View key={id} layout={CurvedTransition} exiting={FadeOut}>
|
||||
<Animated.View exiting={FadeOutUp}>
|
||||
<SubscriptionFeedItemContextMenu id={id} view={view}>
|
||||
<ItemPressable
|
||||
className={cn(
|
||||
"flex h-12 flex-row items-center",
|
||||
inGrouped ? "pl-8 pr-4" : "px-4",
|
||||
"border-item-pressed border-b",
|
||||
className,
|
||||
)}
|
||||
onPress={() => {
|
||||
router.push({
|
||||
pathname: `/feeds/[feedId]`,
|
||||
params: {
|
||||
feedId: id,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<View className="dark:border-tertiary-system-background mr-3 size-5 items-center justify-center overflow-hidden rounded-full border border-transparent dark:bg-[#222]">
|
||||
<FeedIcon feed={feed} />
|
||||
</View>
|
||||
<Text className="text-text">{subscription.title || feed.title}</Text>
|
||||
{!!unreadCount && (
|
||||
<Text className="text-tertiary-label ml-auto text-xs">{unreadCount}</Text>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</SubscriptionFeedItemContextMenu>
|
||||
</Animated.View>
|
||||
// </Swipeable>
|
||||
)
|
||||
})
|
||||
@@ -27,6 +27,7 @@ export default function FeedList() {
|
||||
headerTransparent: true,
|
||||
}}
|
||||
/>
|
||||
|
||||
<SubscriptionLists />
|
||||
<ViewTab />
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user