Open History to see the last commit
1import { useNavigation } from "@react-navigation/native";
2import { selectedNavigationTab, visibleNavigationTabs } from "./navigation-tab-order";
3import { requireNativeView } from "expo";
4import type { NativeSyntheticEvent, ViewProps } from "react-native";
5import { useControlTheme } from "../../components/ui/useControlTheme";
6import { useNavigationTabOrder, useHiddenNavigationTabs } from "./navigation-tabs";
7import { useWorkspaceTabs } from "./WorkspaceTabsContext";
8import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
9
10const 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
23export function WorkspaceSidebarTabs(props: {
24 readonly onNewTask?: () => void;
25 readonly compact?: boolean;
26 readonly reserveComposeSpace?: boolean;
27}) {
28 const workspace = useWorkspaceTabs()!;
29 const order = useNavigationTabOrder();
30 const hidden = useHiddenNavigationTabs();
31 const tabs = [...visibleNavigationTabs(order, hidden), "settings" as const];
32 const navigation = useNavigation();
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 // Keep the tab icons in place when Compose disappears on other destinations.
63 right:
64 (props.compact ? 12 : 0) +
65 ((props.reserveComposeSpace ?? props.compact) && !props.onNewTask
66 ? props.compact
67 ? 64
68 : 76
69 : 0),
70 height: 128,
71 }}
72 />
73 );
74}