Files
Folo/apps/mobile/src/modules/screen/TimelineSelectorProvider.tsx
T
Innei 09ed50a4d7 refactor(mobile): reorganize navigation and layout components
This commit restructures the mobile app's navigation and layout components, moving them from scattered locations into a more organized structure. Key changes include:

- Created new layout and navigation-related directories
- Moved context, hooks, and view components to more logical locations
- Improved imports and component organization
- Added constants for UI-related values
- Simplified and standardized navigation and tab bar components

Signed-off-by: Innei <tukon479@gmail.com>
2025-02-26 21:00:51 +08:00

88 lines
3.2 KiB
TypeScript

import { useLocalSearchParams } from "expo-router"
import { useMemo } from "react"
import { Share, useAnimatedValue, View } from "react-native"
import { useColor } from "react-native-uikit-colors"
import { NavigationContext } from "@/src/components/layouts/views/NavigationContext"
import { NavigationBlurEffectHeader } from "@/src/components/layouts/views/SafeNavigationScrollView"
import { UIBarButton } from "@/src/components/ui/button/UIBarButton"
import { TIMELINE_VIEW_SELECTOR_HEIGHT } from "@/src/constants/ui"
import { Share3CuteReIcon } from "@/src/icons/share_3_cute_re"
import { getWebUrl } from "@/src/lib/env"
import {
HomeLeftAction,
HomeSharedRightAction,
UnreadOnlyActionButton,
} from "@/src/modules/screen/action"
import { TimelineViewSelector } from "@/src/modules/screen/TimelineViewSelector"
import { getFeed } from "@/src/store/feed/getter"
import { useEntryListContext, useSelectedFeedTitle } from "./atoms"
export function TimelineSelectorProvider({ children }: { children: React.ReactNode }) {
const scrollY = useAnimatedValue(0)
const viewTitle = useSelectedFeedTitle()
const screenType = useEntryListContext().type
const params = useLocalSearchParams()
const isFeed = screenType === "feed"
const isTimeline = screenType === "timeline"
const isSubscriptions = screenType === "subscriptions"
return (
<NavigationContext.Provider value={useMemo(() => ({ scrollY }), [scrollY])}>
<NavigationBlurEffectHeader
headerShown
title={viewTitle}
headerLeft={useMemo(
() => (isTimeline || isSubscriptions ? () => <HomeLeftAction /> : undefined),
[isTimeline, isSubscriptions],
)}
headerRight={useMemo(() => {
const buttonVariant = isFeed ? "secondary" : "primary"
if (isTimeline)
return () => (
<HomeSharedRightAction>
<UnreadOnlyActionButton variant={buttonVariant} />
</HomeSharedRightAction>
)
if (isSubscriptions) return () => <HomeSharedRightAction />
if (isFeed)
return () => (
<View className="-mr-2 flex-row gap-2">
<UnreadOnlyActionButton variant={buttonVariant} />
<FeedShareAction params={params} />
</View>
)
return
}, [isFeed, isTimeline, isSubscriptions, params])}
headerHideableBottom={isTimeline || isSubscriptions ? TimelineViewSelector : undefined}
headerHideableBottomHeight={TIMELINE_VIEW_SELECTOR_HEIGHT}
/>
{children}
</NavigationContext.Provider>
)
}
function FeedShareAction({ params }: { params: any }) {
const label = useColor("label")
const { feedId } = params
if (!feedId) return null
return (
<UIBarButton
label="Share"
normalIcon={<Share3CuteReIcon height={24} width={24} color={label} />}
onPress={() => {
const feed = getFeed(feedId)
if (!feed) return
const webUrl = getWebUrl()
const url = `${webUrl}/share/feeds/${feedId}`
Share.share({
message: `Check out ${feed.title} on Follow: ${url}`,
title: feed.title!,
url,
})
}}
/>
)
}