The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { selectedNavigationTab, visibleNavigationTabs } from "./navigation-tab-order"; |
| 2 | import { requireNativeView } from "expo"; |
| 3 | import type { NativeSyntheticEvent, ViewProps } from "react-native"; |
| 4 | import { useControlTheme } from "../../../components/ui/useControlTheme"; |
| 5 | import { useNavigationTabOrder, useHiddenNavigationTabs } from "./navigation-tabs"; |
| 6 | import { useWorkspaceTabs } from "./WorkspaceTabsContext"; |
| 7 | import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab"; |
| 8 | import { useAdaptiveWorkspaceLayout } from "../adaptive-workspace-context"; |
| 9 | |
| 10 | const NativeSidebarTabBar = requireNativeView< |
| 11 | ViewProps & { |
| 12 | tabs: readonly string[]; |
| 13 | selectedTab: string; |
| 14 | selectedColor: string; |
| 15 | appearance: string; |
| 16 | showsCompose: boolean; |
| 17 | compact?: boolean; |
| 18 | onSelectionChange: (event: NativeSyntheticEvent<{ tab: string }>) => void; |
| 19 | onCompose: () => void; |
| 20 | } |
| 21 | >("T3NativeControls", "SidebarTabBar"); |
| 22 | |
| 23 | export function WorkspaceSidebarTabs(props: { |
| 24 | readonly onNewTask?: () => void; |
| 25 | readonly compact?: boolean; |
| 26 | readonly reserveComposeSpace?: boolean; |
| 27 | }) { |
| 28 | const workspace = useWorkspaceTabs()!; |
| 29 | const { layout } = useAdaptiveWorkspaceLayout(); |
| 30 | const order = useNavigationTabOrder(); |
| 31 | const hidden = useHiddenNavigationTabs(); |
| 32 | const tabs = [...visibleNavigationTabs(order, hidden), "settings" as const]; |
| 33 | const selectTab = useSelectWorkspaceTab(); |
| 34 | const { colors, colorScheme } = useControlTheme(); |
| 35 | // UIKit loses accessible names when updating nil-titled items in place. |
| 36 | const tabBarKey = tabs.join(":"); |
| 37 | return ( |
| 38 | <NativeSidebarTabBar |
| 39 | key={tabBarKey} |
| 40 | tabs={tabs} |
| 41 | selectedTab={selectedNavigationTab( |
| 42 | order, |
| 43 | workspace.state.selectedTab, |
| 44 | workspace.settingsOpen, |
| 45 | hidden, |
| 46 | )} |
| 47 | selectedColor={colors["--color-primary"]} |
| 48 | appearance={colorScheme} |
| 49 | showsCompose={Boolean(props.onNewTask)} |
| 50 | compact={props.compact} |
| 51 | onCompose={() => props.onNewTask?.()} |
| 52 | onSelectionChange={({ nativeEvent }) => { |
| 53 | const tab = tabs.find((candidate) => candidate === nativeEvent.tab); |
| 54 | if (tab === "settings") selectTab("settings"); |
| 55 | else if (tab) selectTab(tab); |
| 56 | }} |
| 57 | // Keep the host stable while UIKit updates the bars' intrinsic size and safe area together. |
| 58 | style={{ |
| 59 | position: "absolute", |
| 60 | bottom: 0, |
| 61 | left: props.compact ? 8 : 0, |
| 62 | maxWidth: layout.variant === "medium" ? 280 : undefined, |
| 63 | // Keep the tab icons in place when Compose disappears on other destinations. |
| 64 | right: |
| 65 | (props.compact ? 12 : 0) + |
| 66 | ((props.reserveComposeSpace ?? props.compact) && !props.onNewTask |
| 67 | ? props.compact |
| 68 | ? 64 |
| 69 | : 76 |
| 70 | : 0), |
| 71 | height: 128, |
| 72 | }} |
| 73 | /> |
| 74 | ); |
| 75 | } |