feat: implement pull up to next functionality (#3760)
* feat: implement pull-up-to-next functionality in EntryDetailScreen * feat: add onScroll callback support in SafeNavigationScrollView * refactor: utilize EntryExtraData * feat: refactor Entry components to utilize EntryExtraData type * refactor: replace useSharedValue with useRef and useState for pull-up functionality * feat: enhance pull-up-to-next functionality with enabled prop * fix: types
This commit is contained in:
@@ -94,7 +94,9 @@ export const SafeNavigationScrollView = ({
|
||||
if (reanimatedScrollY) {
|
||||
reanimatedScrollY.value = event.contentOffset.y
|
||||
}
|
||||
|
||||
if (onScroll) {
|
||||
runOnJS(onScroll)(event)
|
||||
}
|
||||
runOnJS(checkScrollToBottom)()
|
||||
screenCtxValue.reAnimatedScrollY.value = event.contentOffset.y
|
||||
},
|
||||
|
||||
@@ -343,7 +343,11 @@ const PreviewFeeds = (props: { id: string; view: FeedViewType }) => {
|
||||
|
||||
const renderItem = useCallback(
|
||||
({ item: id }: ListRenderItemInfo<string>) => (
|
||||
<EntryNormalItem entryId={id} extraData="" view={props.view} />
|
||||
<EntryNormalItem
|
||||
entryId={id}
|
||||
extraData={{ entryIds: null, playingAudioUrl: null }}
|
||||
view={props.view}
|
||||
/>
|
||||
),
|
||||
[props.view],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import * as Haptics from "expo-haptics"
|
||||
import { useCallback, useRef, useState } from "react"
|
||||
import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native"
|
||||
import type { ReanimatedScrollEvent } from "react-native-reanimated/lib/typescript/hook/commonTypes"
|
||||
|
||||
export const usePullUpToNext = ({
|
||||
enabled: enabled = true,
|
||||
onRefresh,
|
||||
progressViewOffset = 70,
|
||||
}: {
|
||||
enabled?: boolean
|
||||
onRefresh?: (() => void) | undefined
|
||||
progressViewOffset?: number
|
||||
} = {}) => {
|
||||
const dragging = useRef(false)
|
||||
const isOverThreshold = useRef(false)
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
|
||||
const onScroll = useCallback(
|
||||
(e: ReanimatedScrollEvent) => {
|
||||
if (!dragging.current) return
|
||||
const overOffset = e.contentOffset.y - e.contentSize.height + e.layoutMeasurement.height
|
||||
|
||||
if (overOffset > progressViewOffset) {
|
||||
if (!isOverThreshold.current && onRefresh) {
|
||||
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy)
|
||||
}
|
||||
isOverThreshold.current = true
|
||||
setRefreshing(true)
|
||||
} else {
|
||||
if (isOverThreshold.current && onRefresh) {
|
||||
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Soft)
|
||||
}
|
||||
isOverThreshold.current = false
|
||||
setRefreshing(false)
|
||||
}
|
||||
return
|
||||
},
|
||||
[dragging, onRefresh, progressViewOffset],
|
||||
)
|
||||
|
||||
const onScrollBeginDrag = useCallback(
|
||||
(e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const beginOffset =
|
||||
e.nativeEvent.contentOffset.y -
|
||||
e.nativeEvent.contentSize.height +
|
||||
e.nativeEvent.layoutMeasurement.height
|
||||
if (beginOffset < -50) {
|
||||
// Maybe user is pulling down fast for overview
|
||||
return
|
||||
}
|
||||
dragging.current = true
|
||||
},
|
||||
[dragging],
|
||||
)
|
||||
|
||||
const onScrollEndDrag = useCallback(
|
||||
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
dragging.current = false
|
||||
const velocity = event.nativeEvent.velocity?.y || 0
|
||||
if (isOverThreshold.current && velocity < 3) {
|
||||
onRefresh?.()
|
||||
}
|
||||
isOverThreshold.current = false
|
||||
setRefreshing(false)
|
||||
},
|
||||
[dragging, onRefresh],
|
||||
)
|
||||
|
||||
if (!enabled) {
|
||||
return {
|
||||
scrollViewEventHandlers: {},
|
||||
pullUpViewProps: {},
|
||||
EntryPullUpToNext: () => null,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
scrollViewEventHandlers: {
|
||||
onScroll,
|
||||
onScrollBeginDrag,
|
||||
onScrollEndDrag,
|
||||
},
|
||||
pullUpViewProps: {
|
||||
refreshing,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { EntryListFooter } from "./EntryListFooter"
|
||||
import { useOnViewableItemsChanged, usePagerListPerformanceHack } from "./hooks"
|
||||
import { ItemSeparator } from "./ItemSeparator"
|
||||
import { EntryNormalItem } from "./templates/EntryNormalItem"
|
||||
import type { EntryExtraData } from "./types"
|
||||
|
||||
export const EntryListContentArticle = ({
|
||||
ref: forwardRef,
|
||||
@@ -23,13 +24,17 @@ export const EntryListContentArticle = ({
|
||||
ref?: React.Ref<ElementRef<typeof TimelineSelectorList> | null>
|
||||
}) => {
|
||||
const playingAudioUrl = usePlayingUrl()
|
||||
const extraData: EntryExtraData = useMemo(
|
||||
() => ({ playingAudioUrl, entryIds }),
|
||||
[playingAudioUrl, entryIds],
|
||||
)
|
||||
|
||||
const { fetchNextPage, isFetching, refetch, isRefetching, hasNextPage } =
|
||||
useFetchEntriesControls()
|
||||
|
||||
const renderItem = useCallback(
|
||||
({ item: id, extraData }: ListRenderItemInfo<string>) => (
|
||||
<EntryNormalItem entryId={id} extraData={extraData} view={view} />
|
||||
<EntryNormalItem entryId={id} extraData={extraData as EntryExtraData} view={view} />
|
||||
),
|
||||
[view],
|
||||
)
|
||||
@@ -56,7 +61,7 @@ export const EntryListContentArticle = ({
|
||||
onRefresh={refetch}
|
||||
isRefetching={isRefetching}
|
||||
data={entryIds}
|
||||
extraData={playingAudioUrl}
|
||||
extraData={extraData}
|
||||
keyExtractor={defaultKeyExtractor}
|
||||
estimatedItemSize={100}
|
||||
renderItem={renderItem}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { EntryListFooter } from "./EntryListFooter"
|
||||
import { useOnViewableItemsChanged, usePagerListPerformanceHack } from "./hooks"
|
||||
import { ItemSeparatorFullWidth } from "./ItemSeparator"
|
||||
import { EntrySocialItem } from "./templates/EntrySocialItem"
|
||||
import type { EntryExtraData } from "./types"
|
||||
|
||||
export const EntryListContentSocial = ({
|
||||
ref: forwardRef,
|
||||
@@ -21,12 +22,15 @@ export const EntryListContentSocial = ({
|
||||
}) => {
|
||||
const { fetchNextPage, isFetching, refetch, isRefetching, hasNextPage } =
|
||||
useFetchEntriesControls()
|
||||
const extraData: EntryExtraData = useMemo(() => ({ playingAudioUrl: null, entryIds }), [entryIds])
|
||||
|
||||
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<string>) => <EntrySocialItem entryId={id} />,
|
||||
({ item: id, extraData }: ListRenderItemInfo<string>) => (
|
||||
<EntrySocialItem entryId={id} extraData={extraData as EntryExtraData} />
|
||||
),
|
||||
[],
|
||||
)
|
||||
|
||||
@@ -50,6 +54,7 @@ export const EntryListContentSocial = ({
|
||||
}}
|
||||
isRefetching={isRefetching}
|
||||
data={entryIds}
|
||||
extraData={extraData}
|
||||
keyExtractor={(id) => id}
|
||||
estimatedItemSize={100}
|
||||
renderItem={renderItem}
|
||||
|
||||
@@ -27,10 +27,19 @@ import { useEntryTranslation } from "@/src/store/translation/hooks"
|
||||
|
||||
import { EntryItemContextMenu } from "../../context-menu/entry"
|
||||
import { EntryItemSkeleton } from "../EntryListContentArticle"
|
||||
import type { EntryExtraData } from "../types"
|
||||
import { EntryTranslation } from "./EntryTranslation"
|
||||
|
||||
export const EntryNormalItem = memo(
|
||||
({ entryId, extraData, view }: { entryId: string; extraData: string; view: FeedViewType }) => {
|
||||
({
|
||||
entryId,
|
||||
extraData,
|
||||
view,
|
||||
}: {
|
||||
entryId: string
|
||||
extraData: EntryExtraData
|
||||
view: FeedViewType
|
||||
}) => {
|
||||
const entry = useEntry(entryId)
|
||||
const translation = useEntryTranslation(entryId)
|
||||
const from = getInboxFrom(entry)
|
||||
@@ -46,10 +55,11 @@ export const EntryNormalItem = memo(
|
||||
|
||||
navigation.pushControllerView(EntryDetailScreen, {
|
||||
entryId,
|
||||
entryIds: extraData.entryIds ?? [],
|
||||
view,
|
||||
})
|
||||
}
|
||||
}, [entryId, entry, navigation, view])
|
||||
}, [entry, navigation, entryId, extraData.entryIds, view])
|
||||
|
||||
const audio = entry?.attachments?.find((attachment) =>
|
||||
attachment.mime_type?.startsWith("audio/"),
|
||||
@@ -125,7 +135,7 @@ export const EntryNormalItem = memo(
|
||||
)}
|
||||
</View>
|
||||
{view !== FeedViewType.Notifications && (
|
||||
<ThumbnailImage entry={entry} view={view} extraData={extraData} />
|
||||
<ThumbnailImage entry={entry} view={view} playingAudioUrl={extraData.playingAudioUrl} />
|
||||
)}
|
||||
</ItemPressable>
|
||||
</EntryItemContextMenu>
|
||||
@@ -137,11 +147,11 @@ EntryNormalItem.displayName = "EntryNormalItem"
|
||||
|
||||
const ThumbnailImage = ({
|
||||
view,
|
||||
extraData,
|
||||
playingAudioUrl,
|
||||
entry,
|
||||
}: {
|
||||
view: FeedViewType
|
||||
extraData: string
|
||||
playingAudioUrl: string | null
|
||||
entry: EntryModel
|
||||
}) => {
|
||||
const feed = useFeed(entry?.feedId as string)
|
||||
@@ -152,7 +162,7 @@ const ThumbnailImage = ({
|
||||
const blurhash = coverImage?.blurhash
|
||||
|
||||
const audio = entry?.attachments?.find((attachment) => attachment.mime_type?.startsWith("audio/"))
|
||||
const audioState = getAttachmentState(extraData, audio)
|
||||
const audioState = getAttachmentState(playingAudioUrl ?? undefined, audio)
|
||||
const isPlaying = audioState === "playing"
|
||||
const isLoading = audioState === "loading"
|
||||
|
||||
|
||||
@@ -23,154 +23,160 @@ import { unreadSyncService } from "@/src/store/unread/store"
|
||||
|
||||
import { EntryItemContextMenu } from "../../context-menu/entry"
|
||||
import { EntryItemSkeleton } from "../EntryListContentSocial"
|
||||
import type { EntryExtraData } from "../types"
|
||||
import { EntryTranslation } from "./EntryTranslation"
|
||||
|
||||
export const EntrySocialItem = memo(({ entryId }: { entryId: string }) => {
|
||||
const entry = useEntry(entryId)
|
||||
const translation = useEntryTranslation(entryId)
|
||||
export const EntrySocialItem = memo(
|
||||
({ entryId, extraData }: { entryId: string; extraData: EntryExtraData }) => {
|
||||
const entry = useEntry(entryId)
|
||||
const translation = useEntryTranslation(entryId)
|
||||
|
||||
const feed = useFeed(entry?.feedId || "")
|
||||
const feed = useFeed(entry?.feedId || "")
|
||||
|
||||
const navigation = useNavigation()
|
||||
const handlePress = useCallback(() => {
|
||||
unreadSyncService.markEntryAsRead(entryId)
|
||||
tracker.navigateEntry({
|
||||
feedId: entry?.feedId!,
|
||||
entryId,
|
||||
})
|
||||
navigation.pushControllerView(EntryDetailScreen, {
|
||||
entryId,
|
||||
view: FeedViewType.SocialMedia,
|
||||
})
|
||||
}, [entry?.feedId, entryId, navigation])
|
||||
const navigation = useNavigation()
|
||||
const handlePress = useCallback(() => {
|
||||
unreadSyncService.markEntryAsRead(entryId)
|
||||
tracker.navigateEntry({
|
||||
feedId: entry?.feedId!,
|
||||
entryId,
|
||||
})
|
||||
navigation.pushControllerView(EntryDetailScreen, {
|
||||
entryId,
|
||||
entryIds: extraData.entryIds ?? [],
|
||||
view: FeedViewType.SocialMedia,
|
||||
})
|
||||
}, [entry?.feedId, entryId, extraData.entryIds, navigation])
|
||||
|
||||
const autoExpandLongSocialMedia = useGeneralSettingKey("autoExpandLongSocialMedia")
|
||||
const autoExpandLongSocialMedia = useGeneralSettingKey("autoExpandLongSocialMedia")
|
||||
|
||||
const memoedMediaUrlList = useMemo(() => {
|
||||
return (entry?.media
|
||||
?.map((i) =>
|
||||
i.type === "video" ? i.preview_image_url : i.type === "photo" ? i.url : undefined,
|
||||
)
|
||||
.filter(Boolean) || []) as string[]
|
||||
}, [entry])
|
||||
const memoedMediaUrlList = useMemo(() => {
|
||||
return (entry?.media
|
||||
?.map((i) =>
|
||||
i.type === "video" ? i.preview_image_url : i.type === "photo" ? i.url : undefined,
|
||||
)
|
||||
.filter(Boolean) || []) as string[]
|
||||
}, [entry])
|
||||
|
||||
const navigationToFeedEntryList = useCallback(() => {
|
||||
if (!entry) return
|
||||
if (!entry.feedId) return
|
||||
navigation.pushControllerView(FeedScreen, {
|
||||
feedId: entry.feedId,
|
||||
})
|
||||
}, [entry?.feedId, navigation])
|
||||
const navigationToFeedEntryList = useCallback(() => {
|
||||
if (!entry) return
|
||||
if (!entry.feedId) return
|
||||
navigation.pushControllerView(FeedScreen, {
|
||||
feedId: entry.feedId,
|
||||
})
|
||||
}, [entry?.feedId, navigation])
|
||||
|
||||
if (!entry) return <EntryItemSkeleton />
|
||||
if (!entry) return <EntryItemSkeleton />
|
||||
|
||||
const { description, publishedAt, media } = entry
|
||||
const { description, publishedAt, media } = entry
|
||||
|
||||
return (
|
||||
<EntryItemContextMenu id={entryId} view={FeedViewType.SocialMedia}>
|
||||
<ItemPressable
|
||||
itemStyle={ItemPressableStyle.Plain}
|
||||
className="flex flex-col gap-2 p-4 pl-6"
|
||||
onPress={handlePress}
|
||||
>
|
||||
{!entry.read && <View className="bg-red absolute left-1.5 top-[25] size-2 rounded-full" />}
|
||||
return (
|
||||
<EntryItemContextMenu id={entryId} view={FeedViewType.SocialMedia}>
|
||||
<ItemPressable
|
||||
itemStyle={ItemPressableStyle.Plain}
|
||||
className="flex flex-col gap-2 p-4 pl-6"
|
||||
onPress={handlePress}
|
||||
>
|
||||
{!entry.read && (
|
||||
<View className="bg-red absolute left-1.5 top-[25] size-2 rounded-full" />
|
||||
)}
|
||||
|
||||
<View className="flex flex-1 flex-row items-start gap-4">
|
||||
<NativePressable hitSlop={10} onPress={navigationToFeedEntryList}>
|
||||
{entry.authorAvatar ? (
|
||||
<UserAvatar
|
||||
preview={false}
|
||||
size={28}
|
||||
name={entry.author ?? ""}
|
||||
image={entry.authorAvatar}
|
||||
/>
|
||||
) : (
|
||||
feed && <FeedIcon feed={feed} size={28} />
|
||||
)}
|
||||
</NativePressable>
|
||||
|
||||
<View className="flex-1 flex-row items-center gap-1.5">
|
||||
<View className="flex flex-1 flex-row items-start gap-4">
|
||||
<NativePressable hitSlop={10} onPress={navigationToFeedEntryList}>
|
||||
<Text numberOfLines={1} className="text-label shrink text-base font-semibold">
|
||||
{entry.author || feed?.title}
|
||||
</Text>
|
||||
{entry.authorAvatar ? (
|
||||
<UserAvatar
|
||||
preview={false}
|
||||
size={28}
|
||||
name={entry.author ?? ""}
|
||||
image={entry.authorAvatar}
|
||||
/>
|
||||
) : (
|
||||
feed && <FeedIcon feed={feed} size={28} />
|
||||
)}
|
||||
</NativePressable>
|
||||
<Text className="text-secondary-label">·</Text>
|
||||
<RelativeDateTime date={publishedAt} className="text-secondary-label text-[14px]" />
|
||||
|
||||
<View className="flex-1 flex-row items-center gap-1.5">
|
||||
<NativePressable hitSlop={10} onPress={navigationToFeedEntryList}>
|
||||
<Text numberOfLines={1} className="text-label shrink text-base font-semibold">
|
||||
{entry.author || feed?.title}
|
||||
</Text>
|
||||
</NativePressable>
|
||||
<Text className="text-secondary-label">·</Text>
|
||||
<RelativeDateTime date={publishedAt} className="text-secondary-label text-[14px]" />
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="relative -mt-4">
|
||||
<EntryTranslation
|
||||
numberOfLines={autoExpandLongSocialMedia ? undefined : 7}
|
||||
className="text-label ml-12 text-base"
|
||||
source={description}
|
||||
target={translation?.description}
|
||||
showTranslation={!!entry.settings?.translation}
|
||||
/>
|
||||
</View>
|
||||
<View className="relative -mt-4">
|
||||
<EntryTranslation
|
||||
numberOfLines={autoExpandLongSocialMedia ? undefined : 7}
|
||||
className="text-label ml-12 text-base"
|
||||
source={description}
|
||||
target={translation?.description}
|
||||
showTranslation={!!entry.settings?.translation}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{media && media.length > 0 && (
|
||||
<View className="ml-10 flex flex-row flex-wrap justify-between">
|
||||
<Galeria urls={memoedMediaUrlList}>
|
||||
{media.map((mediaItem, index) => {
|
||||
const imageUrl =
|
||||
mediaItem.type === "video"
|
||||
? mediaItem.preview_image_url
|
||||
: mediaItem.type === "photo"
|
||||
? mediaItem.url
|
||||
: undefined
|
||||
const fullWidth = index === media.length - 1 && media.length % 2 === 1
|
||||
if (!imageUrl) return null
|
||||
{media && media.length > 0 && (
|
||||
<View className="ml-10 flex flex-row flex-wrap justify-between">
|
||||
<Galeria urls={memoedMediaUrlList}>
|
||||
{media.map((mediaItem, index) => {
|
||||
const imageUrl =
|
||||
mediaItem.type === "video"
|
||||
? mediaItem.preview_image_url
|
||||
: mediaItem.type === "photo"
|
||||
? mediaItem.url
|
||||
: undefined
|
||||
const fullWidth = index === media.length - 1 && media.length % 2 === 1
|
||||
if (!imageUrl) return null
|
||||
|
||||
const ImageItem = (
|
||||
<Galeria.Image index={index}>
|
||||
<Image
|
||||
proxy={{
|
||||
width: fullWidth ? 400 : 200,
|
||||
}}
|
||||
source={{ uri: imageUrl }}
|
||||
blurhash={mediaItem.blurhash}
|
||||
className="border-secondary-system-background w-full rounded-lg border"
|
||||
aspectRatio={
|
||||
fullWidth && mediaItem.width && mediaItem.height
|
||||
? mediaItem.width / mediaItem.height
|
||||
: 1
|
||||
}
|
||||
/>
|
||||
</Galeria.Image>
|
||||
)
|
||||
|
||||
if (mediaItem.type === "video") {
|
||||
return (
|
||||
<View key={`${entryId}-${mediaItem.url}`} className="w-full">
|
||||
<VideoPlayer
|
||||
source={{
|
||||
uri: mediaItem.url,
|
||||
const ImageItem = (
|
||||
<Galeria.Image index={index}>
|
||||
<Image
|
||||
proxy={{
|
||||
width: fullWidth ? 400 : 200,
|
||||
}}
|
||||
height={mediaItem.height}
|
||||
width={mediaItem.width}
|
||||
placeholder={ImageItem}
|
||||
view={FeedViewType.SocialMedia}
|
||||
source={{ uri: imageUrl }}
|
||||
blurhash={mediaItem.blurhash}
|
||||
className="border-secondary-system-background w-full rounded-lg border"
|
||||
aspectRatio={
|
||||
fullWidth && mediaItem.width && mediaItem.height
|
||||
? mediaItem.width / mediaItem.height
|
||||
: 1
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</Galeria.Image>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Pressable
|
||||
key={`${entryId}-${imageUrl}`}
|
||||
className={fullWidth ? "w-full" : "w-1/2 p-0.5"}
|
||||
>
|
||||
{ImageItem}
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
</Galeria>
|
||||
</View>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</EntryItemContextMenu>
|
||||
)
|
||||
})
|
||||
|
||||
if (mediaItem.type === "video") {
|
||||
return (
|
||||
<View key={`${entryId}-${mediaItem.url}`} className="w-full">
|
||||
<VideoPlayer
|
||||
source={{
|
||||
uri: mediaItem.url,
|
||||
}}
|
||||
height={mediaItem.height}
|
||||
width={mediaItem.width}
|
||||
placeholder={ImageItem}
|
||||
view={FeedViewType.SocialMedia}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Pressable
|
||||
key={`${entryId}-${imageUrl}`}
|
||||
className={fullWidth ? "w-full" : "w-1/2 p-0.5"}
|
||||
>
|
||||
{ImageItem}
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
</Galeria>
|
||||
</View>
|
||||
)}
|
||||
</ItemPressable>
|
||||
</EntryItemContextMenu>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
EntrySocialItem.displayName = "EntrySocialItem"
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export type EntryExtraData = {
|
||||
playingAudioUrl: string | null
|
||||
entryIds: string[] | null
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { PortalProvider } from "@gorhom/portal"
|
||||
import { atom, useAtomValue, useSetAtom } from "jotai"
|
||||
import { useEffect, useMemo } from "react"
|
||||
import { useCallback, useEffect, useMemo } from "react"
|
||||
import { Text, View } from "react-native"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import { useColor } from "react-native-uikit-colors"
|
||||
@@ -16,10 +16,12 @@ import { ItemPressableStyle } from "@/src/components/ui/pressable/enum"
|
||||
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
|
||||
import { CalendarTimeAddCuteReIcon } from "@/src/icons/calendar_time_add_cute_re"
|
||||
import { openLink } from "@/src/lib/native"
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import type { NavigationControllerView } from "@/src/lib/navigation/types"
|
||||
import { EntryContentContext, useEntryContentContext } from "@/src/modules/entry-content/ctx"
|
||||
import { EntryAISummary } from "@/src/modules/entry-content/EntryAISummary"
|
||||
import { EntryNavigationHeader } from "@/src/modules/entry-content/EntryNavigationHeader"
|
||||
import { usePullUpToNext } from "@/src/modules/entry-content/use-pull-up-to-next"
|
||||
import { useEntry, usePrefetchEntryDetail } from "@/src/store/entry/hooks"
|
||||
import { entrySyncServices } from "@/src/store/entry/store"
|
||||
import type { EntryWithTranslation } from "@/src/store/entry/types"
|
||||
@@ -31,8 +33,9 @@ import { EntrySocialTitle, EntryTitle } from "../../../../modules/entry-content/
|
||||
|
||||
export const EntryDetailScreen: NavigationControllerView<{
|
||||
entryId: string
|
||||
entryIds?: string[]
|
||||
view: FeedViewType
|
||||
}> = ({ entryId, view: viewType }) => {
|
||||
}> = ({ entryId, entryIds, view: viewType }) => {
|
||||
useAutoMarkAsRead(entryId)
|
||||
const entry = useEntry(entryId)
|
||||
const translation = useEntryTranslation(entryId)
|
||||
@@ -56,6 +59,26 @@ export const EntryDetailScreen: NavigationControllerView<{
|
||||
[entry?.settings?.readability, entry?.settings?.summary, entry?.settings?.translation],
|
||||
)
|
||||
|
||||
const navigation = useNavigation()
|
||||
const nextEntryId = useMemo(() => {
|
||||
if (!entryIds) return
|
||||
const currentEntryIdx = entryIds.indexOf(entryId)
|
||||
return entryIds[currentEntryIdx + 1]
|
||||
}, [entryId, entryIds])
|
||||
|
||||
const { scrollViewEventHandlers } = usePullUpToNext({
|
||||
enabled: !!nextEntryId,
|
||||
onRefresh: useCallback(() => {
|
||||
if (!nextEntryId) return
|
||||
navigation.back()
|
||||
navigation.pushControllerView(EntryDetailScreen, {
|
||||
entryId: nextEntryId,
|
||||
entryIds,
|
||||
view: viewType,
|
||||
})
|
||||
}, [entryIds, navigation, nextEntryId, viewType]),
|
||||
})
|
||||
|
||||
return (
|
||||
<EntryContentContext value={ctxValue}>
|
||||
<PortalProvider>
|
||||
@@ -63,12 +86,13 @@ export const EntryDetailScreen: NavigationControllerView<{
|
||||
<SafeNavigationScrollView
|
||||
Header={<EntryNavigationHeader entryId={entryId} />}
|
||||
automaticallyAdjustContentInsets={false}
|
||||
className="bg-system-background"
|
||||
contentContainerClassName="flex min-h-full pb-16"
|
||||
{...scrollViewEventHandlers}
|
||||
>
|
||||
<ItemPressable
|
||||
itemStyle={ItemPressableStyle.UnStyled}
|
||||
onPress={() => entry?.url && openLink(entry.url)}
|
||||
className="relative rounded-xl py-4"
|
||||
className="rounded-xl py-4"
|
||||
>
|
||||
{viewType === FeedViewType.SocialMedia ? (
|
||||
<EntrySocialTitle entryId={entryId} />
|
||||
|
||||
Reference in New Issue
Block a user