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