Open History to see the last commit
1import { useAtomSet, useAtomValue } from "@effect/atom-react";
2import { AsyncResult } from "effect/reactivity";
3import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
4import { Platform, View } from "react-native";
5import { useSafeAreaInsets } from "react-native-safe-area-context";
6import {
7 moveNavigationTab,
8 navigationCustomizationAvailable,
9 toggleNavigationTabVisibility,
10} from "../layout/workspace/navigation-tab-order";
11import { AppText as Text } from "../../components/ui/AppText";
12import { IconButton } from "../../components/ui/IconButton";
13import { Button } from "../../components/ui/Button";
14import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
15import { SymbolView } from "../../components/ui/AppSymbol";
16import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
17import {
18 NAVIGATION_TAB_ICONS,
19 WORKSPACE_TAB_LABELS,
20 useNavigationTabOrder,
21 useHiddenNavigationTabs,
22 useEnabledNavigationTabs,
23} from "../layout/workspace/navigation-tabs";
24import { SettingsScreen } from "./components/SettingsScreen";
25import { SettingsSection } from "./components/SettingsSection";
26import { resolveWorkspaceTabOrder } from "../layout/workspace/workspace-tabs-state";
27
28export function SettingsNavigationRouteScreen() {
29 const insets = useSafeAreaInsets();
30 const order = useNavigationTabOrder();
31 const { layout } = useAdaptiveWorkspaceLayout();
32 const capacity = Platform.OS === "android" && layout.usesSplitView ? 5 : 4;
33 const hidden = useHiddenNavigationTabs();
34 const enabled = useEnabledNavigationTabs();
35 const preferences = useAtomValue(mobilePreferencesAtom);
36 const customizable = navigationCustomizationAvailable();
37 const ready = customizable && AsyncResult.isSuccess(preferences) && !preferences.waiting;
38 const save = useAtomSet(updateMobilePreferencesAtom);
39 return (
40 <SettingsScreen title="Navigation tabs">
41 <ScreenScrollView
42 contentInsetAdjustmentBehavior="automatic"
43 contentContainerClassName="gap-4 px-5 pt-4"
44 contentContainerStyle={{ paddingBottom: insets.bottom + 24 }}
45 >
46 <Text className="px-2 text-sm text-foreground-muted">
47 {customizable
48 ? "Phones show the first four enabled sections; Android tablet rails show all enabled sections. Remaining sections appear at the top of Settings. Hidden sections appear only here. Settings always stays last. Saved on this device."
49 : "Tab customization becomes available when there are six sections, including Settings."}
50 </Text>
51 <SettingsSection title="Tab order">
52 {order.map((tab, index) => (
53 <View key={tab} className="flex-row items-center gap-3 px-4 py-3">
54 <SymbolView
55 name={NAVIGATION_TAB_ICONS[tab]}
56 size={22}
57 tintColorClassName="accent-icon"
58 />
59 <View className="flex-1">
60 <Text>{WORKSPACE_TAB_LABELS[tab]}</Text>
61 <Text className="text-xs text-foreground-muted">
62 {hidden.includes(tab)
63 ? "Hidden"
64 : enabled.indexOf(tab) < capacity
65 ? `Tab ${enabled.indexOf(tab) + 1}`
66 : "In Settings"}
67 </Text>
68 </View>
69 <IconButton
70 icon={hidden.includes(tab) ? "eye.slash" : "eye"}
71 accessibilityLabel={`${hidden.includes(tab) ? "Show" : "Hide"} ${WORKSPACE_TAB_LABELS[tab]}`}
72 disabled={!ready}
73 onPress={() =>
74 save({
75 transform: (current) => ({
76 hiddenNavigationTabs: toggleNavigationTabVisibility(
77 current.hiddenNavigationTabs,
78 tab,
79 ),
80 }),
81 })
82 }
83 />
84 <IconButton
85 icon="arrow.up"
86 accessibilityLabel={`Move ${WORKSPACE_TAB_LABELS[tab]} up`}
87 disabled={!ready || index === 0}
88 onPress={() =>
89 save({
90 transform: (current) => ({
91 navigationTabOrder: moveNavigationTab(
92 resolveWorkspaceTabOrder(current.navigationTabOrder),
93 tab,
94 index - 1,
95 ),
96 }),
97 })
98 }
99 />
100 <IconButton
101 icon="arrow.down"
102 accessibilityLabel={`Move ${WORKSPACE_TAB_LABELS[tab]} down`}
103 disabled={!ready || index === order.length - 1}
104 onPress={() =>
105 save({
106 transform: (current) => ({
107 navigationTabOrder: moveNavigationTab(
108 resolveWorkspaceTabOrder(current.navigationTabOrder),
109 tab,
110 index + 1,
111 ),
112 }),
113 })
114 }
115 />
116 </View>
117 ))}
118 </SettingsSection>
119 <Button
120 label="Reset tabs"
121 tone="text"
122 disabled={!ready}
123 onPress={() => save({ navigationTabOrder: [], hiddenNavigationTabs: [] })}
124 />
125 </ScreenScrollView>
126 </SettingsScreen>
127 );
128}