| 1 | import { useMemo } from "react"; |
| 2 | import { View } from "react-native"; |
| 3 | import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context"; |
| 4 | import { NativeStackScreenOptions } from "../../native/StackHeader"; |
| 5 | import { AndroidScreenHeader } from "../../components/AndroidScreenHeader"; |
| 6 | import { EmptyState } from "../../components/EmptyState"; |
| 7 | import { MaterialScreenContent } from "../../components/MaterialScreenContent"; |
| 8 | import { useAndroidControlSizing } from "../../components/useAndroidControlSizing"; |
| 9 | import { HomeRouteScreen } from "../home/HomeRouteScreen"; |
| 10 | import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen"; |
| 11 | import { MaterialPullRequestToolbar } from "../pull-requests/MaterialPullRequestToolbar.android"; |
| 12 | import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout"; |
| 13 | import { AndroidWorkspaceNavigation } from "./AndroidWorkspaceNavigation"; |
| 14 | import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext"; |
| 15 | |
| 16 | export function WorkspaceRootScreen() { |
| 17 | const { layout } = useAdaptiveWorkspaceLayout(); |
| 18 | const workspace = useWorkspaceTabs()!; |
| 19 | const insets = useSafeAreaInsets(); |
| 20 | const { fabClearance } = useAndroidControlSizing(); |
| 21 | const context = useMemo( |
| 22 | () => ({ |
| 23 | ...workspace, |
| 24 | bottomClearance: workspace.state.selectedTab === "threads" ? fabClearance + 16 : 16, |
| 25 | }), |
| 26 | [workspace, fabClearance], |
| 27 | ); |
| 28 | |
| 29 | // Split lists live beside the navigator; Home remains an empty detail pane. |
| 30 | if (layout.usesSplitView) { |
| 31 | return workspace.state.selectedTab === "threads" ? ( |
| 32 | <HomeRouteScreen /> |
| 33 | ) : ( |
| 34 | <> |
| 35 | <NativeStackScreenOptions options={{ headerShown: false }} /> |
| 36 | <AndroidScreenHeader title="Pull requests" /> |
| 37 | <View className="flex-1 items-center justify-center px-10"> |
| 38 | <EmptyState |
| 39 | title="Select a pull request" |
| 40 | detail="Choose a pull request from the sidebar to review it." |
| 41 | variant="plain" |
| 42 | /> |
| 43 | </View> |
| 44 | </> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | return ( |
| 49 | <WorkspaceTabsContext value={context}> |
| 50 | <View className="flex-1 bg-header"> |
| 51 | <NativeStackScreenOptions options={{ headerShown: false }} /> |
| 52 | <SafeAreaInsetsContext value={{ ...insets, bottom: 0 }}> |
| 53 | <View className="flex-1"> |
| 54 | {workspace.state.selectedTab === "threads" ? ( |
| 55 | <HomeRouteScreen /> |
| 56 | ) : ( |
| 57 | <> |
| 58 | <MaterialPullRequestToolbar /> |
| 59 | <MaterialScreenContent> |
| 60 | <PullRequestsScreen /> |
| 61 | </MaterialScreenContent> |
| 62 | </> |
| 63 | )} |
| 64 | </View> |
| 65 | </SafeAreaInsetsContext> |
| 66 | <AndroidWorkspaceNavigation /> |
| 67 | </View> |
| 68 | </WorkspaceTabsContext> |
| 69 | ); |
| 70 | } |