Skip to content
TypeScript

feat(mobile): add Usage and Settings to workspace navigation (#23841)

Alex91455de0f222
diff --git a/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3WorkspaceNavigationModule.kt b/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3WorkspaceNavigationModule.kt
index 3a924af4889..315d25c1300 100644
--- a/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3WorkspaceNavigationModule.kt
+++ b/apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/T3WorkspaceNavigationModule.kt
@@ -63,12 +63,11 @@ import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.views.ExpoView
-private val TABS = listOf("threads", "pullRequests", "settings")
-
class T3WorkspaceNavigationModule : Module() {
override fun definition() = ModuleDefinition {
Name("T3WorkspaceNavigation")
View(T3WorkspaceNavigationView::class) {
+ Prop("tabs") { view: T3WorkspaceNavigationView, value: List<String> -> view.tabs = value }
Prop("selectedTab") { view: T3WorkspaceNavigationView, value: String ->
view.selectedTab = value
}
@@ -121,6 +120,7 @@ class T3WorkspaceNavigationView(
private val onTabSelected by EventDispatcher()
private val onNewThread by EventDispatcher()
private val onOverlayChange by EventDispatcher()
+ var tabs by mutableStateOf(listOf("threads", "pullRequests", "usage", "settings"))
var selectedTab by mutableStateOf("threads")
var rail by mutableStateOf(false)
var dark by mutableStateOf(false)
@@ -175,7 +175,7 @@ class T3WorkspaceNavigationView(
tonalElevation = androidx.compose.ui.unit.Dp(0f),
windowInsets = WindowInsets(0),
) {
- TABS.forEach { tab ->
+ tabs.forEach { tab ->
NavigationBarItem(
selected = selectedTab == tab,
onClick = { onTabSelected(mapOf("tab" to tab)) },
@@ -267,12 +267,14 @@ class T3WorkspaceNavigationView(
)
}
}
- newThreadButton(fraction) {
- expanded = false
- onNewThread(emptyMap<String, Any>())
+ if (selectedTab == "threads") {
+ newThreadButton(fraction) {
+ expanded = false
+ onNewThread(emptyMap<String, Any>())
+ }
}
Spacer(Modifier.weight(1f))
- TABS.forEach { tab ->
+ tabs.forEach { tab ->
railItem(tab, fraction) {
expanded = false
onTabSelected(mapOf("tab" to tab))
@@ -356,7 +358,8 @@ class T3WorkspaceNavigationView(
private fun tabTitle(tab: String) = when (tab) {
"threads" -> "Chats"
- "pullRequests" -> "PRs"
+ "pullRequests" -> "Pulls"
+ "usage" -> "Usage"
else -> "Settings"
}
@@ -368,6 +371,7 @@ class T3WorkspaceNavigationView(
when (tab) {
"threads" -> R.drawable.t3_chats
"pullRequests" -> R.drawable.t3_pull_requests
+ "usage" -> R.drawable.t3_usage
else -> R.drawable.t3_settings
}
)
diff --git a/apps/mobile/modules/t3-native-controls/android/src/main/res/drawable/t3_usage.xml b/apps/mobile/modules/t3-native-controls/android/src/main/res/drawable/t3_usage.xml
new file mode 100644
index 00000000000..da09809d177
--- /dev/null
+++ b/apps/mobile/modules/t3-native-controls/android/src/main/res/drawable/t3_usage.xml
@@ -0,0 +1,3 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
+ <path android:fillColor="#000000" android:fillType="evenOdd" android:pathData="M4,20V10H8V20ZM10,20V4H14V20ZM16,20V7H20V20Z" />
+</vector>
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
index 81a892c8bec..bbd71e72db0 100644
--- a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
+++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
@@ -34,9 +34,12 @@ public final class T3NativeControlsModule: Module {
View(T3SidebarTabBarView.self) {
ViewName("SidebarTabBar")
- Events("onSelectionChange")
- Prop("selectedIndex") { (view: T3SidebarTabBarView, value: Int) in view.selectedIndex = value }
+ Events("onSelectionChange", "onCompose")
+ Prop("tabs") { (view: T3SidebarTabBarView, value: [String]) in view.tabs = value }
+ Prop("selectedTab") { (view: T3SidebarTabBarView, value: String) in view.selectedTab = value }
Prop("selectedColor") { (view: T3SidebarTabBarView, value: UIColor) in view.selectedColor = value }
+ Prop("showsCompose") { (view: T3SidebarTabBarView, value: Bool) in view.showsCompose = value }
+ Prop("compact") { (view: T3SidebarTabBarView, value: Bool) in view.compact = value }
Prop("appearance") { (view: T3SidebarTabBarView, value: String) in view.appearance = value }
}
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3SidebarTabBarView.swift b/apps/mobile/modules/t3-native-controls/ios/T3SidebarTabBarView.swift
index 3bfd730facd..2f9fa98f0d5 100644
--- a/apps/mobile/modules/t3-native-controls/ios/T3SidebarTabBarView.swift
+++ b/apps/mobile/modules/t3-native-controls/ios/T3SidebarTabBarView.swift
@@ -1,37 +1,139 @@
import ExpoModulesCore
import UIKit
+private final class WorkspaceTabBar: UITabBar {
+ var onContentLayout: ((CGRect) -> Void)?
+
+ override func layoutSubviews() {
+ super.layoutSubviews()
+ let row = tabButtons(in: self).reduce(CGRect.null) { $0.union(convert($1.bounds, from: $1)) }
+ if !row.isNull { onContentLayout?(row) }
+ }
+
+ override func safeAreaInsetsDidChange() {
+ super.safeAreaInsetsDidChange()
+ invalidateIntrinsicContentSize()
+ }
+
+ private func tabButtons(in view: UIView) -> [UIView] {
+ view.subviews.filter { !$0.isHidden }.flatMap { subview in
+ if subview is UIControl, subview.accessibilityIdentifier?.hasPrefix("workspace-tab-") == true {
+ return [subview]
+ }
+ return tabButtons(in: subview)
+ }
+ }
+}
+
final class T3SidebarTabBarView: ExpoView, UITabBarDelegate {
let onSelectionChange = EventDispatcher()
- private let tabBar = UITabBar()
- var selectedIndex = 0 { didSet { updateSelection() } }
+ let onCompose = EventDispatcher()
+ private let tabBar = WorkspaceTabBar()
+ private let composeButton = UIButton(type: .system)
+ private lazy var tabBarTrailing = tabBar.trailingAnchor.constraint(equalTo: trailingAnchor)
+ private var itemsByTab: [String: UITabBarItem] = [:]
+ var tabs = ["threads", "pullRequests", "usage", "settings"] {
+ didSet { if tabs != oldValue { updateItems() } }
+ }
+ var selectedTab = "threads" { didSet { updateSelection() } }
var selectedColor: UIColor = .systemBlue { didSet { tabBar.tintColor = selectedColor } }
+ var compact = false {
+ didSet {
+ tabBarTrailing.constant = showsCompose ? (compact ? -64 : -76) : 0
+ tabBar.setNeedsLayout()
+ }
+ }
+ var showsCompose = false {
+ didSet {
+ composeButton.isHidden = !showsCompose
+ tabBarTrailing.constant = showsCompose ? (compact ? -64 : -76) : 0
+ setNeedsLayout()
+ }
+ }
var appearance = "light" {
didSet { overrideUserInterfaceStyle = appearance == "dark" ? .dark : .light }
}
required init(appContext: AppContext? = nil) {
super.init(appContext: appContext)
- let iconBundle = Bundle(for: Self.self).url(forResource: "T3NativeControlIcons", withExtension: "bundle").flatMap(Bundle.init(url:))
- let pullRequestIcon = UIImage(named: "pull-request", in: iconBundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
- tabBar.items = [
- UITabBarItem(title: "Threads", image: tabIcon(UIImage(systemName: "text.bubble")), tag: 0),
- UITabBarItem(title: "Pulls", image: tabIcon(pullRequestIcon), tag: 1),
- ]
- tabBar.items?.last?.accessibilityLabel = "Pull requests"
- tabBar.items?.first?.selectedImage = tabIcon(UIImage(systemName: "text.bubble.fill"))
tabBar.itemPositioning = .fill
+ // iPad's regular bar uses a compressed inline row even with fill positioning.
+ // This floating sidebar control needs the same full-size items as a phone bar.
+ if #available(iOS 17.0, *) {
+ tabBar.traitOverrides.horizontalSizeClass = .compact
+ }
tabBar.delegate = self
+ tabBar.translatesAutoresizingMaskIntoConstraints = false
addSubview(tabBar)
- updateSelection()
+ NSLayoutConstraint.activate([
+ tabBar.leadingAnchor.constraint(equalTo: leadingAnchor),
+ tabBarTrailing,
+ tabBar.bottomAnchor.constraint(equalTo: bottomAnchor),
+ ])
+ // UIKit's floating row changes with window geometry. Follow its laid-out items
+ // instead of estimating their position from a second set of safe-area updates.
+ tabBar.onContentLayout = { [weak self] frame in self?.layoutCompose(alongside: frame) }
+ composeButton.accessibilityLabel = "New chat"
+ composeButton.addAction(UIAction { [weak self] _ in self?.onCompose() }, for: .touchUpInside)
+ composeButton.isHidden = true
+ addSubview(composeButton)
+ configureCompose()
+ prepareItems()
+ updateItems()
}
- override func layoutSubviews() {
- super.layoutSubviews()
- tabBar.frame = bounds
+ private func configureCompose() {
+ var configuration: UIButton.Configuration
+ if #available(iOS 26.0, *) {
+ configuration = .glass()
+ } else {
+ configuration = .gray()
+ }
+ configuration.cornerStyle = .capsule
+ configuration.baseForegroundColor = .label
+ configuration.image = UIImage(systemName: "square.and.pencil")
+ configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 24)
+ composeButton.configuration = configuration
+ }
+
+ private func prepareItems() {
+ let iconBundle = Bundle(for: Self.self).url(forResource: "T3NativeControlIcons", withExtension: "bundle").flatMap(Bundle.init(url:))
+ let pullRequestIcon = UIImage(named: "pull-request", in: iconBundle, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
+ let labels = ["threads": "Chats", "pullRequests": "PRs", "usage": "Usage", "settings": "Settings"]
+ let symbols = ["threads": "text.bubble", "usage": "chart.bar.xaxis", "settings": "gearshape"]
+ for (tab, label) in labels {
+ let icon = tab == "pullRequests" ? pullRequestIcon : UIImage(systemName: symbols[tab] ?? "circle")
+ let item = UITabBarItem(title: nil, image: tabIcon(icon), tag: 0)
+ item.accessibilityLabel = label
+ item.accessibilityIdentifier = "workspace-tab-\(tab)"
+ if tab == "threads" { item.selectedImage = tabIcon(UIImage(systemName: "text.bubble.fill")) }
+ itemsByTab[tab] = item
+ }
+ }
+
+ private func updateItems() {
+ tabBar.items = tabs.enumerated().compactMap { index, tab in
+ guard let item = itemsByTab[tab] else { return nil }
+ item.tag = index
+ return item
+ }
updateSelection()
}
+ private func layoutCompose(alongside frame: CGRect) {
+ guard showsCompose, frame.height > 0 else { return }
+ let row = convert(frame, from: tabBar)
+ let size = row.height + 8
+ composeButton.frame = CGRect(x: row.maxX + 16, y: row.midY - size / 2, width: size, height: size)
+ }
+
+ override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
+ if showsCompose, let target = composeButton.hitTest(convert(point, to: composeButton), with: event) {
+ return target
+ }
+ return tabBar.hitTest(convert(point, to: tabBar), with: event)
+ }
+
override func didMoveToWindow() {
super.didMoveToWindow()
updateSelection()
@@ -49,12 +151,13 @@ final class T3SidebarTabBarView: ExpoView, UITabBarDelegate {
}
private func updateSelection() {
- guard let items = tabBar.items, items.indices.contains(selectedIndex) else { return }
- guard tabBar.selectedItem !== items[selectedIndex] else { return }
- tabBar.selectedItem = items[selectedIndex]
+ guard let item = itemsByTab[selectedTab], tabBar.items?.contains(item) == true else { return }
+ guard tabBar.selectedItem !== item else { return }
+ tabBar.selectedItem = item
}
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
- onSelectionChange(["index": item.tag])
+ guard tabs.indices.contains(item.tag) else { return }
+ onSelectionChange(["tab": tabs[item.tag]])
}
}
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx
index d89baa82e40..bcd1a97ce52 100644
--- a/apps/mobile/src/Stack.tsx
+++ b/apps/mobile/src/Stack.tsx
@@ -85,6 +85,7 @@ import {
} from "./features/threads/ThreadSettingsSheet";
import { NewTaskFlowProvider } from "./features/threads/new-task-flow-provider";
import { NewTaskRouteScreen } from "./features/threads/NewTaskRouteScreen";
+import { SettingsNavigationRouteScreen } from "./features/settings/SettingsNavigationRouteScreen";
import { SettingsAppearanceRouteScreen } from "./features/settings/SettingsAppearanceRouteScreen";
import { SettingsClientStorageRouteScreen } from "./features/settings/SettingsClientStorageRouteScreen";
import { SettingsDiagnosticsRouteScreen } from "./features/diagnostics/SettingsDiagnosticsRouteScreen";
@@ -237,6 +238,7 @@ const SettingsContentStack = createV5SheetStackNavigator({
// Android draws its own app bar here. Hidden only from inside the screen, the native one
// showed for the first frame of the Settings tab and pushed the page down.
headerShown: Platform.OS !== "android",
+ headerBackVisible: false,
},
}),
SettingsEnvironments: createNativeStackScreen({
@@ -305,6 +307,11 @@ const SettingsContentStack = createV5SheetStackNavigator({
title: "Archived Threads",
},
}),
+ SettingsNavigation: createNativeStackScreen({
+ screen: SettingsNavigationRouteScreen,
+ linking: "navigation-tabs",
+ options: { title: "Navigation tabs" },
+ }),
SettingsAppearance: createNativeStackScreen({
screen: SettingsAppearanceRouteScreen,
linking: "appearance",
@@ -975,8 +982,8 @@ const RootStackConfig = createWorkspaceStackNavigator({
...NESTED_NAVIGATOR_OPTIONS,
gestureEnabled: true,
headerShown: false,
- // Android opens Settings as a top-level tab, so it swaps like the other tabs.
- ...(Platform.OS === "android" ? { animation: "none" as const } : null),
+ presentation: "card",
+ animation: "none",
},
}),
SettingsLegal: createNativeStackScreen({
@@ -1066,42 +1073,15 @@ export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navig
const { width, height } = useWindowDimensions();
const nativeMetrics = useNativeLayoutMetrics();
const usesSplitView = deriveLayout({ width, height, nativeMetrics }).usesSplitView;
- const usesWorkspaceFlowScreens = Platform.OS === "android" || usesSplitView;
- const flowPresentations = useRef(new Map<string, boolean>());
return (
<Navigator
screenLayout={(props) => <GuardedScreenLayout {...props} />}
- screenListeners={{
- state: ({ data }) => {
- const keys = new Set(data.state.routes.map((route) => route.key));
- for (const key of flowPresentations.current.keys()) {
- if (!keys.has(key)) flowPresentations.current.delete(key);
- }
- },
- }}
- screenOptions={({ route }) => {
- if (route.name !== "SettingsSheet") {
- return Platform.OS === "android"
- ? { animation: androidWorkspaceDestinationAnimation(route.name, usesSplitView) }
- : {};
- }
-
- // Moving an open flow between a sheet and a split column remounts its nested
- // navigator. Keep its presentation until dismissal so folding preserves the settings flow.
- let usesCard = flowPresentations.current.get(route.key);
- if (usesCard === undefined) {
- usesCard = usesWorkspaceFlowScreens;
- flowPresentations.current.set(route.key, usesCard);
- }
- return usesCard
- ? { presentation: "card" }
- : {
- presentation: "formSheet",
- sheetAllowedDetents: [1],
- sheetGrabberVisible: true,
- };
- }}
+ screenOptions={({ route }) =>
+ Platform.OS === "android" && route.name !== "SettingsSheet"
+ ? { animation: androidWorkspaceDestinationAnimation(route.name, usesSplitView) }
+ : {}
+ }
/>
);
});
diff --git a/apps/mobile/src/components/ui/ScreenScrollView.tsx b/apps/mobile/src/components/ui/ScreenScrollView.tsx
index 9a83807ec55..684d2e3bdf5 100644
--- a/apps/mobile/src/components/ui/ScreenScrollView.tsx
+++ b/apps/mobile/src/components/ui/ScreenScrollView.tsx
@@ -1,11 +1,19 @@
-import type { ComponentProps } from "react";
+import { createContext, use, type ComponentProps } from "react";
import { Platform } from "react-native";
import { NativeScrollView as ScrollView } from "../../native/NativeScrollViewMarker";
+export const ScreenScrollViewBottomInset = createContext(0);
+
export function ScreenScrollView(props: ComponentProps<typeof ScrollView>) {
+ const bottomInset = use(ScreenScrollViewBottomInset);
return (
<ScrollView
{...props}
+ contentInset={
+ Platform.OS === "ios" && bottomInset > 0
+ ? { ...props.contentInset, bottom: (props.contentInset?.bottom ?? 0) + bottomInset }
+ : props.contentInset
+ }
contentContainerStyle={[
props.contentContainerStyle,
Platform.OS === "android" && {
diff --git a/apps/mobile/src/features/home/home-thread-navigation.test.ts b/apps/mobile/src/features/home/home-thread-navigation.test.ts
index 820a6666505..d02d602767a 100644
--- a/apps/mobile/src/features/home/home-thread-navigation.test.ts
+++ b/apps/mobile/src/features/home/home-thread-navigation.test.ts
@@ -21,6 +21,10 @@ function loadRouters() {
vi.mock("react-native", () => ({ Platform: { OS: "ios" }, Keyboard: { dismiss: vi.fn() } }));
+vi.mock("../workspace/useAndroidWorkspaceSelection", () => ({
+ useAndroidWorkspaceSelection: vi.fn(),
+}));
+
vi.mock("@react-navigation/native", () => {
const { CommonActions, StackActions } = loadRouters();
return { CommonActions, StackActions };
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index bec83816b58..ffcab2aa310 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -1,3 +1,4 @@
+import { AdaptiveWorkspaceContext, useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
import { createDeferredNavigation } from "./deferred-navigation";
import { uuidv4 } from "../../lib/uuid";
import type {
@@ -15,7 +16,6 @@ import {
useNavigation,
} from "@react-navigation/native";
import {
- createContext,
use,
useDeferredValue,
useEffect,
@@ -43,10 +43,7 @@ import {
type VerticalHinge,
deriveWorkspacePaneLayout,
isPrimarySidebarPinned,
- type FileInspectorPaneLayout,
- type Layout,
type WorkspaceAuxiliaryPaneRole,
- type WorkspacePaneLayout,
} from "../../lib/layout";
import {
resolveThreadSelectionNavigationAction,
@@ -73,6 +70,7 @@ import {
} from "../workspace/AndroidWorkspaceNavigation";
import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
+import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import { HomeListOptionsProvider } from "../home/home-list-options";
import { newTaskDestination } from "../threads/new-task-project-selection";
import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
@@ -94,65 +92,7 @@ import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { AndroidHingeObserver } from "../../native/AndroidHingeObserver";
import { WindowHingeContext } from "../../native/window-hinge-context";
-interface AdaptiveWorkspaceContextValue {
- readonly layout: Layout;
- readonly panes: WorkspacePaneLayout;
- readonly fileInspector: FileInspectorPaneLayout;
- readonly primarySidebarSearchQuery: string;
- readonly startNewTask: () => void;
- readonly deferThreadSelectionUntil: (operation: Promise<unknown>) => void;
- readonly selectThread: (thread: EnvironmentThreadShell) => void;
- readonly selectThreadRoute: (params: ReactNavigation.RootParamList["Thread"]) => void;
- readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
- readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void;
- readonly setPrimarySidebarSearchQuery: (query: string) => void;
- readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
- readonly toggleAuxiliaryPane: () => void;
- readonly togglePrimarySidebar: () => void;
- readonly setAuxiliaryPaneWidth: (width: number) => void;
- /**
- * Android split view while the thread composer has the soft keyboard: the
- * sidebar and rail step aside and the thread header drops to one line.
- */
- readonly composerKeyboardActive: boolean;
- /** The thread composer reports its focus so the layout can make room for typing. */
- readonly setComposerEditing: (editing: boolean) => void;
-}
-
-const compactLayout = deriveLayout({ width: 0, height: 0 });
-const compactPanes = deriveWorkspacePaneLayout({
- layout: compactLayout,
- viewportWidth: 0,
- primarySidebarPreferredVisible: true,
- auxiliaryPanePreferredVisible: true,
-});
-const compactFileInspector = deriveFileInspectorPaneLayout({
- layout: compactLayout,
- viewportWidth: 0,
-});
-const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextValue>({
- layout: compactLayout,
- panes: compactPanes,
- fileInspector: compactFileInspector,
- primarySidebarSearchQuery: "",
- startNewTask: () => undefined,
- deferThreadSelectionUntil: () => undefined,
- selectThread: () => undefined,
- selectThreadRoute: () => undefined,
- activateAuxiliaryPaneRole: () => () => undefined,
- registerWorkspaceInspector: () => () => undefined,
- setPrimarySidebarSearchQuery: () => undefined,
- showAuxiliaryPane: () => undefined,
- toggleAuxiliaryPane: () => undefined,
- togglePrimarySidebar: () => undefined,
- setAuxiliaryPaneWidth: () => undefined,
- composerKeyboardActive: false,
- setComposerEditing: () => undefined,
-});
-
-export function useAdaptiveWorkspaceLayout(): AdaptiveWorkspaceContextValue {
- return use(AdaptiveWorkspaceContext);
-}
+export { useAdaptiveWorkspaceLayout };
export function useAdaptiveWorkspacePaneRole(role: WorkspaceAuxiliaryPaneRole) {
const { activateAuxiliaryPaneRole } = useAdaptiveWorkspaceLayout();
@@ -265,9 +205,11 @@ function AdaptiveWorkspaceLayoutContent(
const nativeMetrics = useNativeLayoutMetrics();
const { width: viewportWidth, height } = nativeMetrics ?? windowDimensions;
const pathname = props.pathname;
- // Android's Settings tab is a full workspace page: the rail stays, the sidebar and
- // auxiliary panes hide.
- const workspacePage = Platform.OS === "android" && pathname.startsWith("/settings");
+ const workspace = useWorkspaceTabs();
+ // Settings and Usage occupy the workspace rather than a list/detail pair.
+ const workspacePage =
+ Platform.OS === "android" &&
+ (pathname.startsWith("/settings") || workspace?.state.selectedTab === "usage");
const navigation = useNavigation();
const activeRoleOwner = useRef<symbol | null>(null);
const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
diff --git a/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx b/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx
index d719c85525d..d58360e7e99 100644
--- a/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx
+++ b/apps/mobile/src/features/layout/WorkspaceEmptyDetail.tsx
@@ -13,6 +13,8 @@ export function WorkspaceEmptyDetail(props: {
readonly onAddConnection?: () => void;
}) {
const pullRequests = props.tab === "pullRequests";
+ if (props.tab && props.tab !== "threads" && props.tab !== "pullRequests")
+ return <View className="flex-1 bg-screen" />;
return (
<View
className={
diff --git a/apps/mobile/src/features/layout/adaptive-workspace-context.ts b/apps/mobile/src/features/layout/adaptive-workspace-context.ts
new file mode 100644
index 00000000000..cb64e3cfa3f
--- /dev/null
+++ b/apps/mobile/src/features/layout/adaptive-workspace-context.ts
@@ -0,0 +1,71 @@
+import { createContext, use, type ReactNode } from "react";
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
+import {
+ deriveFileInspectorPaneLayout,
+ deriveLayout,
+ deriveWorkspacePaneLayout,
+ type FileInspectorPaneLayout,
+ type Layout,
+ type WorkspaceAuxiliaryPaneRole,
+ type WorkspacePaneLayout,
+} from "../../lib/layout";
+
+interface AdaptiveWorkspaceContextValue {
+ readonly layout: Layout;
+ readonly panes: WorkspacePaneLayout;
+ readonly fileInspector: FileInspectorPaneLayout;
+ readonly primarySidebarSearchQuery: string;
+ readonly startNewTask: () => void;
+ readonly deferThreadSelectionUntil: (operation: Promise<unknown>) => void;
+ readonly selectThread: (thread: EnvironmentThreadShell) => void;
+ readonly selectThreadRoute: (params: ReactNavigation.RootParamList["Thread"]) => void;
+ readonly activateAuxiliaryPaneRole: (role: WorkspaceAuxiliaryPaneRole) => () => void;
+ readonly registerWorkspaceInspector: (render: () => ReactNode) => () => void;
+ readonly setPrimarySidebarSearchQuery: (query: string) => void;
+ readonly showAuxiliaryPane: (role: WorkspaceAuxiliaryPaneRole) => void;
+ readonly toggleAuxiliaryPane: () => void;
+ readonly togglePrimarySidebar: () => void;
+ readonly setAuxiliaryPaneWidth: (width: number) => void;
+ /**
+ * Android split view while the thread composer has the soft keyboard: the
+ * sidebar and rail step aside and the thread header drops to one line.
+ */
+ readonly composerKeyboardActive: boolean;
+ /** The thread composer reports its focus so the layout can make room for typing. */
+ readonly setComposerEditing: (editing: boolean) => void;
+}
+
+const compactLayout = deriveLayout({ width: 0, height: 0 });
+const compactPanes = deriveWorkspacePaneLayout({
+ layout: compactLayout,
+ viewportWidth: 0,
+ primarySidebarPreferredVisible: true,
+ auxiliaryPanePreferredVisible: true,
+});
+const compactFileInspector = deriveFileInspectorPaneLayout({
+ layout: compactLayout,
+ viewportWidth: 0,
+});
+export const AdaptiveWorkspaceContext = createContext<AdaptiveWorkspaceContextValue>({
+ layout: compactLayout,
+ panes: compactPanes,
+ fileInspector: compactFileInspector,
+ primarySidebarSearchQuery: "",
+ startNewTask: () => undefined,
+ deferThreadSelectionUntil: () => undefined,
+ selectThread: () => undefined,
+ selectThreadRoute: () => undefined,
+ activateAuxiliaryPaneRole: () => () => undefined,
+ registerWorkspaceInspector: () => () => undefined,
+ setPrimarySidebarSearchQuery: () => undefined,
+ showAuxiliaryPane: () => undefined,
+ toggleAuxiliaryPane: () => undefined,
+ togglePrimarySidebar: () => undefined,
+ setAuxiliaryPaneWidth: () => undefined,
+ composerKeyboardActive: false,
+ setComposerEditing: () => undefined,
+});
+
+export function useAdaptiveWorkspaceLayout(): AdaptiveWorkspaceContextValue {
+ return use(AdaptiveWorkspaceContext);
+}
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index 262e0ac7167..6af2cda6dca 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -26,7 +26,7 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { WorkspaceTabsProvider, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import { WorkspaceNativeTabs } from "../workspace/WorkspaceNativeTabs.ios";
-import { isDuoDevice } from "../../lib/device-type";
+import { workspaceUsesColumns } from "../workspace/workspace-tabs-state";
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
@@ -178,12 +178,10 @@ function WorkspaceColumns(
const selectedTab = useWorkspaceTabs()?.state.selectedTab;
const openNewTask = startNewTask;
- // The Duo keeps compose in the detail column's bar, which is its vertical bar in landscape
- // and folded, so it sits with the column's other actions whichever screen is shown. Pull
- // requests leave it out, including one opened from a thread; their bar is already full of
- // review actions.
+ // The cover detail rail needs room for thread tools above the fixed tabs.
+ // The unfolded Duo keeps compose beside its sidebar control.
const detailCompose =
- isDuoDevice(deviceType) && selectedTab !== "pullRequests" ? openNewTask : undefined;
+ deviceType === "duo-unfolded" && selectedTab !== "pullRequests" ? openNewTask : undefined;
const inspector = use(NativeWorkspaceInspectorContext);
const hostRef = useRef<SplitHostCommands>(null);
const activeDetailKey = props.detail.at(-1)?.key;
@@ -362,7 +360,8 @@ function WorkspaceColumns(
}
function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean }) {
- const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
+ const { layout } = useAdaptiveWorkspaceLayout();
+ const workspace = useWorkspaceTabs()!;
// Native dismiss commits the route pop after the transition. Restore the dock
// when the primary screen starts appearing, including interactive back gestures.
const [primaryVisible, setPrimaryVisible] = useState(false);
@@ -380,6 +379,7 @@ function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean
const descriptors = props.descriptors;
const baseRoute = { key: `${props.state.key}:workspace`, name: "Workspace" };
const visibleRoute = projection.detail.at(-1) ?? primaryRoute;
+ const workspacePage = !workspaceUsesColumns(workspace.state.selectedTab, visibleRoute.name);
const baseDescriptor: Descriptor = {
...primaryDescriptor,
navigation: props.descriptors[visibleRoute.key]!.navigation,
@@ -389,8 +389,8 @@ function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean
options: { headerShown: false },
render: () => (
<WorkspaceNativeTabs
- onNewTask={startNewTask}
hidden={
+ !workspacePage &&
projection.detail.length > 0 &&
!primaryVisible &&
!layout.usesSplitView &&
@@ -401,7 +401,7 @@ function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean
props.navigation.dispatch({ type: "POP_TO_TOP", target: props.state.key });
}}
>
- {props.nativeColumns ? (
+ {props.nativeColumns && !workspacePage ? (
<WorkspaceColumns
{...props}
descriptors={descriptors}
@@ -503,7 +503,7 @@ function WorkspaceStackNavigator({
return (
<NativeWorkspaceModeContext value={usesNativeWorkspaceColumns}>
<NavigationContent>
- <WorkspaceTabsProvider>
+ <WorkspaceTabsProvider settingsOpen={state.routes[state.index]?.name === "SettingsSheet"}>
<WorkspaceStackView
nativeColumns={usesNativeWorkspaceColumns}
{...rest}
diff --git a/apps/mobile/src/features/layout/workspace-sidebar-toolbar.tsx b/apps/mobile/src/features/layout/workspace-sidebar-toolbar.tsx
index 9b4e0982122..a5731a1c98b 100644
--- a/apps/mobile/src/features/layout/workspace-sidebar-toolbar.tsx
+++ b/apps/mobile/src/features/layout/workspace-sidebar-toolbar.tsx
@@ -2,7 +2,7 @@ import { Platform } from "react-native";
import { AndroidHeaderIconButton } from "../../components/ui/AndroidScreenHeader";
-import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
+import { useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
export function AndroidWorkspaceSidebarButton() {
const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
diff --git a/apps/mobile/src/features/settings/SettingsNavigationRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsNavigationRouteScreen.tsx
new file mode 100644
index 00000000000..a4196c07d97
--- /dev/null
+++ b/apps/mobile/src/features/settings/SettingsNavigationRouteScreen.tsx
@@ -0,0 +1,128 @@
+import { useAtomSet, useAtomValue } from "@effect/atom-react";
+import { AsyncResult } from "effect/reactivity";
+import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context";
+import { Platform, View } from "react-native";
+import { useSafeAreaInsets } from "react-native-safe-area-context";
+import {
+ moveNavigationTab,
+ navigationCustomizationAvailable,
+ toggleNavigationTabVisibility,
+} from "../workspace/navigation-tab-order";
+import { AppText as Text } from "../../components/ui/AppText";
+import { IconButton } from "../../components/ui/IconButton";
+import { Button } from "../../components/ui/Button";
+import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
+import { SymbolView } from "../../components/ui/AppSymbol";
+import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
+import {
+ NAVIGATION_TAB_ICONS,
+ WORKSPACE_TAB_LABELS,
+ useNavigationTabOrder,
+ useHiddenNavigationTabs,
+ useEnabledNavigationTabs,
+} from "../workspace/navigation-tabs";
+import { SettingsScreen } from "./components/SettingsScreen";
+import { SettingsSection } from "./components/SettingsSection";
+import { resolveWorkspaceTabOrder } from "../workspace/workspace-tabs-state";
+
+export function SettingsNavigationRouteScreen() {
+ const insets = useSafeAreaInsets();
+ const order = useNavigationTabOrder();
+ const { layout } = useAdaptiveWorkspaceLayout();
+ const capacity = Platform.OS === "android" && layout.usesSplitView ? 5 : 4;
+ const hidden = useHiddenNavigationTabs();
+ const enabled = useEnabledNavigationTabs();
+ const preferences = useAtomValue(mobilePreferencesAtom);
+ const customizable = navigationCustomizationAvailable();
+ const ready = customizable && AsyncResult.isSuccess(preferences) && !preferences.waiting;
+ const save = useAtomSet(updateMobilePreferencesAtom);
+ return (
+ <SettingsScreen title="Navigation tabs">
+ <ScreenScrollView
+ contentInsetAdjustmentBehavior="automatic"
+ contentContainerClassName="gap-4 px-5 pt-4"
+ contentContainerStyle={{ paddingBottom: insets.bottom + 24 }}
+ >
+ <Text className="px-2 text-sm text-foreground-muted">
+ {customizable
+ ? "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."
+ : "Tab customization becomes available when there are six sections, including Settings."}
+ </Text>
+ <SettingsSection title="Tab order">
+ {order.map((tab, index) => (
+ <View key={tab} className="flex-row items-center gap-3 px-4 py-3">
+ <SymbolView
+ name={NAVIGATION_TAB_ICONS[tab]}
+ size={22}
+ tintColorClassName="accent-icon"
+ />
+ <View className="flex-1">
+ <Text>{WORKSPACE_TAB_LABELS[tab]}</Text>
+ <Text className="text-xs text-foreground-muted">
+ {hidden.includes(tab)
+ ? "Hidden"
+ : enabled.indexOf(tab) < capacity
+ ? `Tab ${enabled.indexOf(tab) + 1}`
+ : "In Settings"}
+ </Text>
+ </View>
+ <IconButton
+ icon={hidden.includes(tab) ? "eye.slash" : "eye"}
+ accessibilityLabel={`${hidden.includes(tab) ? "Show" : "Hide"} ${WORKSPACE_TAB_LABELS[tab]}`}
+ disabled={!ready}
+ onPress={() =>
+ save({
+ transform: (current) => ({
+ hiddenNavigationTabs: toggleNavigationTabVisibility(
+ current.hiddenNavigationTabs,
+ tab,
+ ),
+ }),
+ })
+ }
+ />
+ <IconButton
+ icon="arrow.up"
+ accessibilityLabel={`Move ${WORKSPACE_TAB_LABELS[tab]} up`}
+ disabled={!ready || index === 0}
+ onPress={() =>
+ save({
+ transform: (current) => ({
+ navigationTabOrder: moveNavigationTab(
+ resolveWorkspaceTabOrder(current.navigationTabOrder),
+ tab,
+ index - 1,
+ ),
+ }),
+ })
+ }
+ />
+ <IconButton
+ icon="arrow.down"
+ accessibilityLabel={`Move ${WORKSPACE_TAB_LABELS[tab]} down`}
+ disabled={!ready || index === order.length - 1}
+ onPress={() =>
+ save({
+ transform: (current) => ({
+ navigationTabOrder: moveNavigationTab(
+ resolveWorkspaceTabOrder(current.navigationTabOrder),
+ tab,
+ index + 1,
+ ),
+ }),
+ })
+ }
+ />
+ </View>
+ ))}
+ </SettingsSection>
+ <Button
+ label="Reset tabs"
+ tone="text"
+ disabled={!ready}
+ onPress={() => save({ navigationTabOrder: [], hiddenNavigationTabs: [] })}
+ />
+ </ScreenScrollView>
+ </SettingsScreen>
+ );
+}
diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
index 4a60794c271..87537c2236c 100644
--- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
@@ -1,14 +1,30 @@
-import { Toolbar } from "../../components/ui/Toolbar";
-import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
+import {
+ navigationCustomizationAvailable,
+ overflowNavigationTabs,
+} from "../workspace/navigation-tab-order";
+import {
+ NAVIGATION_TAB_ICONS,
+ WORKSPACE_TAB_LABELS,
+ useNavigationTabOrder,
+ useHiddenNavigationTabs,
+} from "../workspace/navigation-tabs";
+import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
+import {
+ ScreenScrollView as ScrollView,
+ ScreenScrollViewBottomInset,
+} from "../../components/ui/ScreenScrollView";
import { useAuth, useUser } from "@clerk/expo";
import { useNavigation } from "@react-navigation/native";
import { Platform, View } from "react-native";
+import { useWorkspaceSurface } from "../workspace/useWorkspaceSurface";
+import { useDeviceType } from "../../native/native-layout-metrics";
+import { useCompactWorkspaceTabs } from "../workspace/useSystemWorkspaceTabBar";
+import { NativeStackScreenOptions } from "../../native/StackHeader";
import { deriveProjectGroupLabel } from "@t3tools/client-runtime/state/project-grouping";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { hasCloudPublicConfig } from "../cloud/publicConfig";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
-import { NativeStackScreenOptions } from "../../native/StackHeader";
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
import { SettingsRow } from "./components/SettingsRow";
import { SettingsSection } from "./components/SettingsSection";
@@ -20,8 +36,9 @@ import {
import { useSettingsEnvironmentFilter } from "./settings-environment-filter";
export function SettingsRouteScreen() {
- const navigation = useNavigation();
- const { layout } = useAdaptiveWorkspaceLayout();
+ const surface = useWorkspaceSurface();
+ const deviceType = useDeviceType();
+ const compactTabs = useCompactWorkspaceTabs();
const content = hasCloudPublicConfig() ? (
<ConfiguredSettingsRouteScreen />
) : (
@@ -29,30 +46,27 @@ export function SettingsRouteScreen() {
);
return (
- <>
+ <View className={`flex-1 ${surface.className}`}>
{Platform.OS === "ios" ? (
- <NativeStackScreenOptions options={{ headerBackVisible: !layout.usesSplitView }} />
- ) : null}
- {Platform.OS === "ios" && layout.usesSplitView ? (
- <>
- <Toolbar placement="left">
- <Toolbar.Button
- accessibilityLabel="Go back"
- icon="chevron.left"
- onPress={() => navigation.goBack()}
- />
- </Toolbar>
- </>
+ <NativeStackScreenOptions
+ options={{
+ headerTransparent: false,
+ headerStyle: { backgroundColor: surface.backgroundColor },
+ contentStyle: { backgroundColor: surface.backgroundColor },
+ }}
+ />
) : null}
- <SettingsEnvironmentFilterHeader closeSettings />
- {Platform.OS === "android" ? (
- <SettingsScreen title="Settings" trailing={<AndroidSettingsEnvironmentFilter />}>
- {content}
- </SettingsScreen>
- ) : (
- content
- )}
- </>
+ <SettingsEnvironmentFilterHeader />
+ <ScreenScrollViewBottomInset value={deviceType === "pad" || compactTabs ? 80 : 0}>
+ {Platform.OS === "android" ? (
+ <SettingsScreen title="Settings" trailing={<AndroidSettingsEnvironmentFilter />}>
+ {content}
+ </SettingsScreen>
+ ) : (
+ content
+ )}
+ </ScreenScrollViewBottomInset>
+ </View>
);
}
@@ -69,7 +83,7 @@ function ConfiguredSettingsRouteScreen() {
: (user?.primaryEmailAddress?.emailAddress ?? "Signed in");
return (
- <View collapsable={false} className="flex-1 bg-sheet">
+ <View collapsable={false} className="flex-1">
<ScrollView
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
@@ -77,6 +91,7 @@ function ConfiguredSettingsRouteScreen() {
contentContainerClassName="gap-4 px-5 pt-4"
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
>
+ <OverflowSection />
<SettingsSection title="Connections">
<SettingsRow
icon="person.crop.circle"
@@ -107,7 +122,7 @@ function LocalSettingsRouteScreen() {
const environmentCount = Object.keys(savedConnectionsById).length;
return (
- <View collapsable={false} className="flex-1 bg-sheet">
+ <View collapsable={false} className="flex-1">
<ScrollView
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
@@ -117,6 +132,7 @@ function LocalSettingsRouteScreen() {
paddingBottom: Math.max(insets.bottom, 18) + 18,
}}
>
+ <OverflowSection />
<SettingsSection title="Connections">
<SettingsRow
icon="desktopcomputer"
@@ -154,6 +170,13 @@ function SettingsIndexSections() {
<>
<SettingsSection title="Interface">
<SettingsRow icon="paintbrush" label="Appearance" target="SettingsAppearance" />
+ {navigationCustomizationAvailable() ? (
+ <SettingsRow
+ icon="line.3.horizontal"
+ label="Navigation tabs"
+ target="SettingsNavigation"
+ />
+ ) : null}
{Platform.OS === "ios" ? (
<>
<SettingsRow icon="keyboard" label="Keyboard" target="SettingsKeyboard" />
@@ -215,9 +238,29 @@ function SettingsIndexSections() {
</SettingsSection>
<SettingsSection title="App">
- <SettingsRow icon="chart.bar.xaxis" label="Usage" target="SettingsUsage" />
<SettingsRow icon="info.circle" label="About T3 Code" target="SettingsAbout" />
</SettingsSection>
</>
);
}
+
+function OverflowSection() {
+ const order = useNavigationTabOrder();
+ const hidden = useHiddenNavigationTabs();
+ const { layout } = useAdaptiveWorkspaceLayout();
+ const tabs =
+ Platform.OS === "android" && layout.usesSplitView ? [] : overflowNavigationTabs(order, hidden);
+ const selectTab = useSelectWorkspaceTab();
+ return tabs.length ? (
+ <SettingsSection>
+ {tabs.map((tab) => (
+ <SettingsRow
+ key={tab}
+ icon={NAVIGATION_TAB_ICONS[tab]}
+ label={WORKSPACE_TAB_LABELS[tab]}
+ onPress={() => selectTab(tab)}
+ />
+ ))}
+ </SettingsSection>
+ ) : null;
+}
diff --git a/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx b/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx
index bbc8515f04c..d298e972b40 100644
--- a/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx
@@ -1,4 +1,3 @@
-import { useNavigation } from "@react-navigation/native";
import type { NativeStackHeaderItem } from "@react-navigation/native-stack";
import { resolveEnvironmentMachineKind } from "@t3tools/contracts";
import { Platform, Pressable } from "react-native";
@@ -8,16 +7,11 @@ import { SymbolView } from "../../../components/ui/AppSymbol";
import { ENVIRONMENT_MACHINE_SYMBOLS } from "../../../components/EnvironmentMachineSymbol";
import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { withNativeGlassHeaderItem } from "../../layout/native-glass-header-items";
-import { useAdaptiveWorkspaceLayout } from "../../layout/AdaptiveWorkspaceLayout";
import { useSettingsEnvironmentFilter } from "../settings-environment-filter";
export function SettingsEnvironmentFilterHeader(props: {
- readonly closeSettings?: boolean;
readonly trailingItems?: readonly NativeStackHeaderItem[];
}) {
- const navigation = useNavigation();
- const { layout } = useAdaptiveWorkspaceLayout();
- const closeSettings = props.closeSettings === true && !layout.usesSplitView;
const {
availableTargets,
selectedTargets,
@@ -35,7 +29,6 @@ export function SettingsEnvironmentFilterHeader(props: {
? "line.3.horizontal.decrease"
: "line.3.horizontal.decrease.circle.fill";
const filterVersion = JSON.stringify({
- closeSettings,
selection: selectedIds === null ? null : [...selectedIds].sort(),
targets: availableTargets.map((entry) => [
entry.environmentId,
@@ -117,18 +110,6 @@ export function SettingsEnvironmentFilterHeader(props: {
},
}),
...(props.trailingItems ?? []),
- ...(closeSettings
- ? [
- withNativeGlassHeaderItem({
- accessibilityLabel: "Close settings",
- icon: { name: "xmark", type: "sfSymbol" },
- identifier: "settings-close",
- label: "",
- onPress: () => navigation.goBack(),
- type: "button",
- }),
- ]
- : []),
],
}}
/>
diff --git a/apps/mobile/src/features/settings/components/SettingsScreen.tsx b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
index b3f8176ebce..7eb807ec86c 100644
--- a/apps/mobile/src/features/settings/components/SettingsScreen.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
@@ -6,6 +6,11 @@ import type { AppBarProps } from "../../../components/ui/AppBar.types";
import { AppBar } from "../../../components/ui/AppBar";
import { ScreenContent as SettingsScreenContent } from "../../../components/ui/ScreenContent";
import { useWorkspaceTabs } from "../../workspace/WorkspaceTabsContext";
+import { useWorkspaceSurface } from "../../workspace/useWorkspaceSurface";
+import { useDeviceType } from "../../../native/native-layout-metrics";
+import { NativeStackScreenOptions } from "../../../native/StackHeader";
+import { useCompactWorkspaceTabs } from "../../workspace/useSystemWorkspaceTabBar";
+import { ScreenScrollViewBottomInset } from "../../../components/ui/ScreenScrollView";
export { SettingsScreenContent };
@@ -13,18 +18,27 @@ export function SettingsScreen(
props: Pick<AppBarProps, "title" | "actions" | "trailing"> & {
readonly children: ReactNode;
readonly formSheet?: boolean;
+ readonly workspaceRoot?: boolean;
},
) {
const navigation = useNavigation();
const route = useRoute();
const index = useNavigationState((state) => state.index);
const workspace = useWorkspaceTabs();
+ const surface = useWorkspaceSurface();
+ const deviceType = useDeviceType();
+ const compactTabs = useCompactWorkspaceTabs();
+ const cover = deviceType === "duo-folded";
// Android opens Settings as a workspace tab; its root page has nothing to go back to.
const workspaceRoot =
- Platform.OS === "android" && workspace !== null && index === 0 && route.name === "Settings";
+ props.workspaceRoot ||
+ (Platform.OS === "android" && workspace !== null && index === 0 && route.name === "Settings");
return (
- <View collapsable={false} className="flex-1 bg-sheet">
+ <View
+ collapsable={false}
+ className={`flex-1 ${workspaceRoot || cover ? surface.className : "bg-sheet"}`}
+ >
<AppBar
title={props.title}
actions={props.actions}
@@ -33,11 +47,22 @@ export function SettingsScreen(
onBack={workspaceRoot ? undefined : () => navigation.goBack()}
hideBottomBorder={!props.formSheet}
/>
- {props.formSheet ? (
- props.children
- ) : (
- <SettingsScreenContent>{props.children}</SettingsScreenContent>
- )}
+ {Platform.OS === "ios" && (workspaceRoot || cover) ? (
+ <NativeStackScreenOptions
+ options={{
+ headerTransparent: false,
+ headerStyle: { backgroundColor: surface.backgroundColor },
+ contentStyle: { backgroundColor: surface.backgroundColor },
+ }}
+ />
+ ) : null}
+ <ScreenScrollViewBottomInset value={deviceType === "pad" || compactTabs ? 80 : 0}>
+ {props.formSheet ? (
+ props.children
+ ) : (
+ <SettingsScreenContent>{props.children}</SettingsScreenContent>
+ )}
+ </ScreenScrollViewBottomInset>
</View>
);
}
diff --git a/apps/mobile/src/features/settings/components/settings-sheet-targets.ts b/apps/mobile/src/features/settings/components/settings-sheet-targets.ts
index 611a1b3410c..22fa5b4b98f 100644
--- a/apps/mobile/src/features/settings/components/settings-sheet-targets.ts
+++ b/apps/mobile/src/features/settings/components/settings-sheet-targets.ts
@@ -5,6 +5,7 @@ export type SettingsSheetTarget =
| "SettingsAbout"
| "SettingsArchive"
| "SettingsAppearance"
+ | "SettingsNavigation"
| "SettingsOrganization"
| "SettingsProjectOverview"
| "SettingsEnvironmentNewThreads"
diff --git a/apps/mobile/src/features/usage/UsageRouteScreen.tsx b/apps/mobile/src/features/usage/UsageRouteScreen.tsx
index 4b38162c850..5e9ca9f9afa 100644
--- a/apps/mobile/src/features/usage/UsageRouteScreen.tsx
+++ b/apps/mobile/src/features/usage/UsageRouteScreen.tsx
@@ -3,7 +3,7 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
import { ChatGptUsageSummary } from "./ChatGptUsageSummary";
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
import { EnvironmentId, USAGE_CONTRACT_VERSION, type UsageProviderKind } from "@t3tools/contracts";
-import { type RouteProp, useIsFocused, useNavigation, useRoute } from "@react-navigation/native";
+import { type RouteProp, useIsFocused, useRoute } from "@react-navigation/native";
import { cursorKeychainAccessEnvironments } from "@t3tools/client-runtime/state/usage";
import {
updatingProvidersLabel,
@@ -55,6 +55,7 @@ import { useRefreshLimits } from "./UsageLimitsSection";
import { UsageLimitsSection } from "./UsageLimitsPooled";
import { Menu } from "../../components/ui/Menu";
import { SymbolView } from "../../components/ui/AppSymbol";
+import { NativeStackScreenOptions } from "../../native/StackHeader";
import type { UsageChartMetric } from "./usageChartData";
import { PROVIDER_LABEL, useProviderColors, useUsageMixColors } from "./usageProviders";
@@ -80,22 +81,28 @@ const CHART_HEIGHT = 180;
const providerLabel = (provider: UsageProviderKind) => PROVIDER_LABEL[provider];
const CURSOR_KEYCHAIN_COPY = "Requires access to your Cursor login in macOS Keychain.";
-export function UsageRouteScreen() {
+export function UsageRouteScreen(props: { readonly workspace?: boolean }) {
const route = useRoute<RouteProp<{ Usage: { tab?: string } | undefined }, "Usage">>();
- const navigation = useNavigation();
+ return <UsageScreen workspace={props.workspace} tabParam={route.params?.tab} />;
+}
+
+function UsageScreen(props: {
+ readonly workspace?: boolean;
+ readonly tabParam: string | undefined;
+}) {
const insets = useSafeAreaInsets();
const [selection, setSelection] = useState(() => ({
- params: route.params,
- tab: (route.params?.tab === "usage" ? "usage" : "limits") as UsageTab,
+ params: props.tabParam,
+ tab: (props.tabParam === "usage" ? "usage" : "limits") as UsageTab,
}));
- if (selection.params !== route.params) {
+ if (selection.params !== props.tabParam) {
setSelection({
- params: route.params,
- tab: route.params?.tab === "usage" ? "usage" : "limits",
+ params: props.tabParam,
+ tab: props.tabParam === "usage" ? "usage" : "limits",
});
}
const { tab } = selection;
- const setTab = (tab: UsageTab) => setSelection({ params: route.params, tab });
+ const setTab = (tab: UsageTab) => setSelection({ params: props.tabParam, tab });
const [windowSelection, setWindowSelection] = useState(() => ({
days: 30,
window: makeWindow(30),
@@ -234,14 +241,14 @@ export function UsageRouteScreen() {
</Menu>
) : null;
- useLayoutEffect(() => {
- if (Platform.OS === "ios") {
- navigation.setOptions({ headerRight: () => environmentFilter });
- }
- }, [navigation, environmentFilter]);
-
return (
- <SettingsScreen title="Usage" trailing={environmentFilter}>
+ <SettingsScreen title="Usage" trailing={environmentFilter} workspaceRoot={props.workspace}>
+ {Platform.OS === "ios" ? (
+ <NativeStackScreenOptions
+ optionsVersion={environmentFilter}
+ options={{ headerRight: () => environmentFilter }}
+ />
+ ) : null}
<ScrollView
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
diff --git a/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx b/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx
index b813e61a1bc..ee690d10082 100644
--- a/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx
+++ b/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx
@@ -1,3 +1,4 @@
+import { selectedNavigationTab, visibleNavigationTabs } from "./navigation-tab-order";
import { requireNativeView } from "expo";
import { CommonActions, useNavigation } from "@react-navigation/native";
import {
@@ -20,6 +21,7 @@ import {
} from "./android-workspace-tabs";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import { useAndroidWorkspaceRoot } from "./AndroidWorkspaceTabsProvider";
+import { useNavigationTabOrder, useHiddenNavigationTabs } from "./navigation-tabs";
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
// Matches RAIL_WIDTH in the native rail.
@@ -27,6 +29,7 @@ export const ANDROID_WORKSPACE_RAIL_WIDTH = 72;
interface NativeNavigationProps extends ViewProps {
readonly rail: boolean;
+ readonly tabs: readonly string[];
readonly selectedTab: AndroidWorkspaceNavigationTab;
readonly dark: boolean;
readonly textScale: number;
@@ -62,6 +65,8 @@ export function AndroidWorkspaceNavigation(props: {
readonly onOverlayChange?: (overlay: boolean) => void;
}) {
const workspace = useWorkspaceTabs()!;
+ const order = useNavigationTabOrder();
+ const hidden = useHiddenNavigationTabs();
const root = useAndroidWorkspaceRoot();
const navigation = useNavigation();
const insets = useSafeAreaInsets();
@@ -73,9 +78,13 @@ export function AndroidWorkspaceNavigation(props: {
const rail = Boolean(props.rail);
const { containerColor, indicatorColor, selectedColor, unselectedColor } =
androidWorkspaceNavigationColors(colors, rail);
- const selectedTab: AndroidWorkspaceNavigationTab = root?.settingsOpen
- ? "settings"
- : workspace.state.selectedTab;
+ const selectedTab = selectedNavigationTab(
+ order,
+ workspace.state.selectedTab,
+ root?.settingsOpen ?? false,
+ hidden,
+ rail ? 5 : 4,
+ );
if (!rail && keyboardVisible) return null;
return (
@@ -88,6 +97,7 @@ export function AndroidWorkspaceNavigation(props: {
>
<NativeNavigation
rail={rail}
+ tabs={[...visibleNavigationTabs(order, hidden, rail ? 5 : 4), "settings"]}
selectedTab={selectedTab}
dark={themeAppearance === "dark"}
textScale={scale}
@@ -104,15 +114,13 @@ export function AndroidWorkspaceNavigation(props: {
onTabSelected={(event) => {
Keyboard.dismiss();
const tab = event.nativeEvent.tab;
- if (tab !== selectedTab) {
- if (tab !== "settings") workspace.dispatch({ type: "select", tab });
- // Reset the root stack even when a nested settings navigator has focus.
- if (root) {
- navigation.dispatch({
- ...CommonActions.reset(androidWorkspaceTabNavigationState(root.getState(), tab)),
- target: root.key,
- });
- }
+ if (tab !== "settings") workspace.dispatch({ type: "select", tab });
+ // Reset the root stack even when a nested settings navigator has focus.
+ if (root) {
+ navigation.dispatch({
+ ...CommonActions.reset(androidWorkspaceTabNavigationState(root.getState(), tab)),
+ target: root.key,
+ });
}
props.onSelect?.();
}}
diff --git a/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx b/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx
index 498550d2a11..65fa9d1d37e 100644
--- a/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx
+++ b/apps/mobile/src/features/workspace/AndroidWorkspaceSidebar.android.tsx
@@ -1,3 +1,6 @@
+import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
+import { useEnabledNavigationTabs } from "./navigation-tabs";
+import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
import { useMemo, type ReactNode } from "react";
import { View } from "react-native";
import { ScreenContent } from "../../components/ui/ScreenContent";
@@ -13,14 +16,18 @@ export function AndroidWorkspaceSidebar(props: {
readonly selectedPullRequestKey: string | null;
}) {
const workspace = useWorkspaceTabs()!;
+ const enabled = useEnabledNavigationTabs();
const context = useMemo(() => ({ ...workspace, bottomClearance: 16 }), [workspace]);
+ if (enabled.length === 0) return <WorkspaceNoTabs />;
return (
<WorkspaceTabPanes
- tabs={["threads", "pullRequests"]}
+ tabs={NAVIGATION_TAB_ORDER}
selected={workspace.state.selectedTab}
renderTab={(tab) =>
tab === "threads" ? (
props.children
+ ) : tab !== "pullRequests" ? (
+ <View className="flex-1 bg-screen" />
) : (
<WorkspaceTabsContext value={context}>
<PullRequestFilterMenuProvider>
diff --git a/apps/mobile/src/features/workspace/WorkspaceExtraTab.tsx b/apps/mobile/src/features/workspace/WorkspaceExtraTab.tsx
new file mode 100644
index 00000000000..48ef15f6f67
--- /dev/null
+++ b/apps/mobile/src/features/workspace/WorkspaceExtraTab.tsx
@@ -0,0 +1,16 @@
+import { type NavigationTab } from "./navigation-tab-order";
+import { NativeStackScreenOptions } from "../../native/StackHeader";
+import { UsageRouteScreen } from "../usage/UsageRouteScreen";
+
+export function WorkspaceExtraTab(_props: {
+ tab: Exclude<NavigationTab, "threads" | "pullRequests">;
+}) {
+ return (
+ <>
+ <NativeStackScreenOptions
+ options={{ headerSearchBarOptions: undefined, unstable_headerRightItems: undefined }}
+ />
+ <UsageRouteScreen workspace />
+ </>
+ );
+}
diff --git a/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
index 66571a1a309..5c1fc78f95d 100644
--- a/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceNativeTabs.ios.tsx
@@ -1,6 +1,11 @@
-import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
+import { useNavigation } from "@react-navigation/native";
+import {
+ WORKSPACE_TAB_LABELS,
+ NAVIGATION_TAB_ICONS,
+ useEnabledNavigationTabs,
+} from "./navigation-tabs";
import { useCallback, useMemo, useState, type ReactNode } from "react";
-import { Keyboard, Platform, View, type NativeSyntheticEvent } from "react-native";
+import { Keyboard, View, useWindowDimensions, type NativeSyntheticEvent } from "react-native";
import {
Tabs,
type TabSelectedEvent,
@@ -9,12 +14,19 @@ import {
} from "react-native-screens";
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
-import type { WorkspaceTab } from "./workspace-tabs-state";
+import {
+ NATIVE_WORKSPACE_TAB_SLOTS,
+ workspaceTabForNativeSlot,
+ type WorkspaceTab,
+} from "./workspace-tabs-state";
import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-context";
-import { useSystemWorkspaceTabBar } from "./useSystemWorkspaceTabBar";
+import { useCompactWorkspaceTabs, useSystemWorkspaceTabBar } from "./useSystemWorkspaceTabBar";
+import { useControlTheme } from "../../components/ui/useControlTheme";
+import { useDeviceType } from "../../native/native-layout-metrics";
+import { WorkspaceSidebarTabs } from "./WorkspaceSidebarTabs";
+import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
-const COMPOSE_TAB = "compose";
/** Retain each native controller tree; removing its root can leave RNS's stack empty. */
function RetainedWorkspaceTab(props: {
@@ -48,86 +60,130 @@ export function WorkspaceNativeTabs(props: {
readonly children: ReactNode;
readonly hidden: boolean;
readonly onSelect: () => void;
- readonly onNewTask: () => void;
}) {
const workspace = useWorkspaceTabs()!;
- const metrics = useNativeLayoutMetrics();
- const deviceType = useDeviceType();
- const phoneBar =
- Platform.OS === "ios" &&
- deviceType !== "pad" &&
- (metrics?.verticalBarEdge ?? "none") === "none";
+ const order = useEnabledNavigationTabs();
+ const primaryTabs = order.slice(0, 4);
+ const overflow = order[4];
+ const navigation = useNavigation();
const [provenance, setProvenance] = useState(0);
const systemTabBar = useSystemWorkspaceTabBar();
+ const deviceType = useDeviceType();
+ const compactTabs = useCompactWorkspaceTabs();
+ const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
+ const compactSidebarTabs = deviceType === "phone" || !layout.usesSplitView;
+ const { width } = useWindowDimensions();
+ const { colors } = useControlTheme();
const selectedTab = workspace.state.selectedTab;
+ const selectedSlot = workspace.settingsOpen ? -1 : primaryTabs.indexOf(selectedTab);
const request = useMemo(
- () => ({ selectedScreenKey: selectedTab, baseProvenance: provenance }),
- [selectedTab, provenance],
+ () => ({
+ selectedScreenKey:
+ selectedSlot === -1 ? "settings" : NATIVE_WORKSPACE_TAB_SLOTS[selectedSlot]!,
+ baseProvenance: provenance,
+ }),
+ [selectedSlot, provenance],
);
return (
<View style={{ flex: 1 }}>
<Tabs.Host
navStateRequest={request}
tabBarHidden={props.hidden || !systemTabBar}
- ios={{ tabBarControllerMode: "tabBar", tabBarMinimizeBehavior: "never" }}
+ ios={{
+ tabBarControllerMode: "tabBar",
+ tabBarMinimizeBehavior: "never",
+ tabBarTintColor: colors["--color-primary"],
+ }}
onTabSelectionPrevented={({
nativeEvent,
}: NativeSyntheticEvent<TabSelectionPreventedEvent>) => {
- if (nativeEvent.preventedScreenKey === COMPOSE_TAB) props.onNewTask();
+ if (nativeEvent.preventedScreenKey === "settings") {
+ navigation.navigate("SettingsSheet", {
+ screen: "SettingsContent",
+ params: { screen: "Settings" },
+ });
+ }
}}
onTabSelectionRejected={({
nativeEvent,
- }: NativeSyntheticEvent<TabSelectionRejectedEvent>) => {
- setProvenance(nativeEvent.provenance);
- }}
+ }: NativeSyntheticEvent<TabSelectionRejectedEvent>) =>
+ setProvenance(nativeEvent.provenance)
+ }
onTabSelected={({ nativeEvent }: NativeSyntheticEvent<TabSelectedEvent>) => {
- const tab = nativeEvent.selectedScreenKey;
- if (tab !== "threads" && tab !== "pullRequests") return;
setProvenance(nativeEvent.provenance);
- if (nativeEvent.actionOrigin === "programmatic-js" || tab === selectedTab) return;
+ if (nativeEvent.actionOrigin === "programmatic-js") return;
+ const tab = workspaceTabForNativeSlot(primaryTabs, nativeEvent.selectedScreenKey);
+ // UIKit sends reselects here even when preventNativeSelection is enabled.
+ if (tab === "settings") {
+ navigation.navigate("SettingsSheet", {
+ screen: "SettingsContent",
+ params: { screen: "Settings" },
+ });
+ return;
+ }
+ if (!tab) return;
Keyboard.dismiss();
props.onSelect();
workspace.dispatch({ type: "select", tab });
}}
>
- {(["threads", "pullRequests"] as const).map((tab: WorkspaceTab) => (
- <Tabs.Screen
- key={tab}
- screenKey={tab}
- title={tab === "threads" ? "Threads" : "Pulls"}
- tabBarItemAccessibilityLabel={tab === "threads" ? "Threads" : "Pull requests"}
- ios={{
- icon:
- tab === "threads"
- ? { type: "sfSymbol", name: "text.bubble" }
- : { type: "templateSource", templateSource: PULL_REQUEST_ICON },
- selectedIcon:
- tab === "threads" ? { type: "sfSymbol", name: "text.bubble.fill" } : undefined,
- overrideScrollViewContentInsetAdjustmentBehavior: false,
- }}
- >
- <RetainedWorkspaceTab tab={tab} active={selectedTab === tab}>
- {props.children}
- </RetainedWorkspaceTab>
- </Tabs.Screen>
- ))}
- {phoneBar ? (
- <Tabs.Screen
- key={COMPOSE_TAB}
- screenKey={COMPOSE_TAB}
- title="New chat"
- preventNativeSelection
- ios={{
- role: "search",
- // iOS 27 detaches a search tab only while it may activate search.
- automaticallyActivatesSearch: true,
- icon: { type: "sfSymbol", name: "square.and.pencil" },
- }}
- >
- <View />
- </Tabs.Screen>
- ) : null}
+ {NATIVE_WORKSPACE_TAB_SLOTS.map((slot, index) => {
+ const settings = slot === "settings";
+ const tab = settings ? (overflow ?? selectedTab) : primaryTabs[index];
+ if (!tab) return null;
+ return (
+ <Tabs.Screen
+ // Stable slot controllers keep UIKit's stacks attached when a section moves into Settings.
+ key={slot}
+ screenKey={slot}
+ title=""
+ tabBarItemAccessibilityLabel={settings ? "Settings" : WORKSPACE_TAB_LABELS[tab]}
+ preventNativeSelection={settings}
+ ios={{
+ icon: settings
+ ? { type: "sfSymbol", name: "gearshape" }
+ : tab === "pullRequests"
+ ? { type: "templateSource", templateSource: PULL_REQUEST_ICON }
+ : { type: "sfSymbol", name: NAVIGATION_TAB_ICONS[tab] },
+ selectedIcon:
+ !settings && tab === "threads"
+ ? { type: "sfSymbol", name: "text.bubble.fill" }
+ : undefined,
+ overrideScrollViewContentInsetAdjustmentBehavior: false,
+ }}
+ >
+ <RetainedWorkspaceTab
+ tab={tab}
+ active={settings ? selectedSlot === -1 : selectedSlot === index}
+ >
+ {props.children}
+ </RetainedWorkspaceTab>
+ </Tabs.Screen>
+ );
+ })}
</Tabs.Host>
+ {(deviceType === "pad" || compactTabs) && !props.hidden ? (
+ <View
+ pointerEvents="box-none"
+ style={{
+ position: "absolute",
+ left: 0,
+ bottom: 0,
+ width: layout.listPaneWidth ?? width,
+ height: 128,
+ }}
+ >
+ <WorkspaceSidebarTabs
+ compact={compactSidebarTabs}
+ reserveComposeSpace={compactSidebarTabs}
+ onNewTask={
+ compactSidebarTabs && !workspace.settingsOpen && selectedTab === "threads"
+ ? startNewTask
+ : undefined
+ }
+ />
+ </View>
+ ) : null}
</View>
);
}
diff --git a/apps/mobile/src/features/workspace/WorkspaceNoTabs.tsx b/apps/mobile/src/features/workspace/WorkspaceNoTabs.tsx
new file mode 100644
index 00000000000..f217cbf86b9
--- /dev/null
+++ b/apps/mobile/src/features/workspace/WorkspaceNoTabs.tsx
@@ -0,0 +1,23 @@
+import { useNavigation } from "@react-navigation/native";
+import { View } from "react-native";
+import { EmptyState } from "../../components/ui/EmptyState";
+
+export function WorkspaceNoTabs() {
+ const navigation = useNavigation();
+ return (
+ <View className="flex-1 items-center justify-center bg-screen">
+ <EmptyState
+ title="All sections are hidden"
+ detail="Show a section to add it back to navigation."
+ actionLabel="Edit navigation tabs"
+ variant="plain"
+ onAction={() =>
+ navigation.navigate("SettingsSheet", {
+ screen: "SettingsContent",
+ params: { screen: "SettingsNavigation", initial: false },
+ })
+ }
+ />
+ </View>
+ );
+}
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
index 240396d0469..1173a08e867 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
@@ -1,3 +1,7 @@
+import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
+import { useEnabledNavigationTabs } from "./navigation-tabs";
+import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
+import { WorkspaceExtraTab } from "./WorkspaceExtraTab";
import { useMemo } from "react";
import { View } from "react-native";
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
@@ -16,11 +20,12 @@ import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
import type { WorkspaceTab } from "./workspace-tabs-state";
-const TABS: readonly WorkspaceTab[] = ["threads", "pullRequests"];
+const TABS: readonly WorkspaceTab[] = NAVIGATION_TAB_ORDER;
export function WorkspaceRootScreen() {
const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
const workspace = useWorkspaceTabs()!;
+ const enabled = useEnabledNavigationTabs();
const insets = useSafeAreaInsets();
const { fabClearance } = useAndroidControlSizing();
const context = useMemo(
@@ -33,6 +38,7 @@ export function WorkspaceRootScreen() {
const tab = workspace.state.selectedTab;
if (layout.usesSplitView) {
+ if (enabled.length === 0) return <View className="flex-1 bg-screen" />;
return (
<WorkspaceTabPanes
tabs={TABS}
@@ -40,6 +46,8 @@ export function WorkspaceRootScreen() {
renderTab={(tab) =>
tab === "threads" ? (
<HomeRouteScreen />
+ ) : tab !== "pullRequests" ? (
+ <WorkspaceExtraTab tab={tab} />
) : (
<>
<NativeStackScreenOptions options={{ headerShown: false }} />
@@ -63,22 +71,28 @@ export function WorkspaceRootScreen() {
<View className="flex-1 bg-header">
<NativeStackScreenOptions options={{ headerShown: false }} />
<SafeAreaInsetsContext value={{ ...insets, bottom: 0 }}>
- <WorkspaceTabPanes
- tabs={TABS}
- selected={tab}
- renderTab={(tab) =>
- tab === "threads" ? (
- <HomeRouteScreen />
- ) : (
- <PullRequestFilterMenuProvider>
- <PullRequestToolbar />
- <ScreenContent>
- <PullRequestsScreen />
- </ScreenContent>
- </PullRequestFilterMenuProvider>
- )
- }
- />
+ {enabled.length === 0 ? (
+ <WorkspaceNoTabs />
+ ) : (
+ <WorkspaceTabPanes
+ tabs={TABS}
+ selected={tab}
+ renderTab={(tab) =>
+ tab === "threads" ? (
+ <HomeRouteScreen />
+ ) : tab !== "pullRequests" ? (
+ <WorkspaceExtraTab tab={tab} />
+ ) : (
+ <PullRequestFilterMenuProvider>
+ <PullRequestToolbar />
+ <ScreenContent>
+ <PullRequestsScreen />
+ </ScreenContent>
+ </PullRequestFilterMenuProvider>
+ )
+ }
+ />
+ )}
</SafeAreaInsetsContext>
<AndroidWorkspaceNavigation onNewThread={startNewTask} />
</View>
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
index c28ef1397a8..2e226f80014 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
@@ -1,3 +1,7 @@
+import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
+import { WORKSPACE_TAB_LABELS, useEnabledNavigationTabs } from "./navigation-tabs";
+import { WorkspaceExtraTab } from "./WorkspaceExtraTab";
+import { WorkspaceSectionToolbar } from "./WorkspaceSectionToolbar";
import { useNavigation } from "@react-navigation/native";
import { use, useCallback, useMemo } from "react";
import { Platform, View, useWindowDimensions } from "react-native";
@@ -5,10 +9,12 @@ import { useKeyboardState } from "react-native-keyboard-controller";
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
import { CompactBrandTitle } from "../../components/CompactBrandTitle";
-import { isDuoDevice } from "../../lib/device-type";
import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
import { NativeStackScreenOptions } from "../../native/StackHeader";
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
+import { isDuoDevice } from "../../lib/device-type";
+import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
+import { useWorkspaceSurface } from "./useWorkspaceSurface";
import {
useDeviceType,
useDuoBottomBarInset,
@@ -26,25 +32,34 @@ import {
useWorkspaceTabs,
} from "./WorkspaceTabsContext";
import { WorkspaceToolbar } from "./WorkspaceToolbar";
-import { WORKSPACE_DOCK, WORKSPACE_TOOLBAR, workspaceToolbarHeight } from "./workspace-tabs-state";
+import {
+ WORKSPACE_DOCK,
+ workspaceSearchBottomClearance,
+ workspaceDockBottomClearance,
+ workspaceToolbarHeight,
+} from "./workspace-tabs-state";
import { WorkspaceSidebarTabs } from "./WorkspaceSidebarTabs";
-import { useSidebarWorkspaceTabs, useSystemWorkspaceTabBar } from "./useSystemWorkspaceTabBar";
+import {
+ useCompactWorkspaceTabs,
+ useSidebarWorkspaceTabs,
+ useSystemWorkspaceTabBar,
+} from "./useSystemWorkspaceTabBar";
-const TAB_TITLES = {
- threads: "Threads",
- pullRequests: "Pull requests",
-};
+const TAB_TITLES = WORKSPACE_TAB_LABELS;
function WorkspaceRootTitle(props: {
readonly maxWidth: number;
readonly onOpenEnvironments: () => void;
}) {
const { state } = useWorkspaceTabs()!;
+ const enabled = useEnabledNavigationTabs();
return (
<View style={{ width: props.maxWidth, minHeight: 32, justifyContent: "center" }}>
<WorkspaceConnectionTitle
brand={
- <CompactBrandTitle accessibilityLabel={`T3 Code, ${TAB_TITLES[state.selectedTab]}`} />
+ <CompactBrandTitle
+ accessibilityLabel={`T3 Code, ${enabled.length ? TAB_TITLES[state.selectedTab] : "Navigation"}`}
+ />
}
maxWidth={props.maxWidth}
onPress={props.onOpenEnvironments}
@@ -61,9 +76,12 @@ function WorkspaceRootContent() {
const columnMetrics = useNativeColumnLayoutMetrics();
const nativeMetrics = useNativeLayoutMetrics();
const deviceType = useDeviceType();
+ const surface = useWorkspaceSurface();
const systemTabBar = useSystemWorkspaceTabBar();
+ const compactTabs = useCompactWorkspaceTabs();
+ const enabled = useEnabledNavigationTabs();
const sidebarTabs = useSidebarWorkspaceTabs();
- const sidebarPicker = sidebarTabs === "picker";
+ const sidebarPicker = sidebarTabs === "picker" || (deviceType === "pad" && layout.usesSplitView);
const sidebarNavigation =
primaryColumn !== null &&
(layout.usesSplitView ||
@@ -75,6 +93,7 @@ function WorkspaceRootContent() {
const keyboardHeight = useKeyboardState((keyboard) => keyboard.height);
const workspace = useWorkspaceTabs()!;
const { state } = workspace;
+ const solidHeader = deviceType === "duo-folded" || state.selectedTab === "usage";
const renderHeaderTitle = useCallback(
() => (
<WorkspaceRootTitle
@@ -92,35 +111,58 @@ function WorkspaceRootContent() {
const tab = state.tabs[state.selectedTab];
const bottomClearance =
Platform.OS === "ios" && isDuoDevice(deviceType)
- ? Math.max(bottomBarInset ?? Math.max(insets.bottom, 12), keyboardHeight + 8) +
- WORKSPACE_TOOLBAR.height +
- 16
- : Platform.OS === "ios"
- ? Math.max(insets.bottom, keyboardHeight) +
- (systemTabBar || sidebarTabs || tab.searchMode !== "resting"
- ? sidebarPicker
- ? 80
- : 16
- : WORKSPACE_DOCK.height + WORKSPACE_DOCK.bottomGap + 16)
- : keyboardHeight > 0 && tab.searchMode !== "resting"
- ? keyboardHeight + 64
- : Math.max(insets.bottom, 12) + workspaceToolbarHeight(tab.searchMode) + 16;
+ ? workspaceSearchBottomClearance({
+ bottomInset: insets.bottom,
+ bottomBarInset,
+ keyboardHeight,
+ })
+ : compactTabs || deviceType === "pad"
+ ? workspaceDockBottomClearance({ bottomInset: insets.bottom, keyboardHeight })
+ : Platform.OS === "ios"
+ ? Math.max(insets.bottom, keyboardHeight) +
+ (systemTabBar || sidebarTabs || tab.searchMode !== "resting"
+ ? sidebarPicker
+ ? 80
+ : 16
+ : WORKSPACE_DOCK.height + WORKSPACE_DOCK.bottomGap + 16)
+ : keyboardHeight > 0 && tab.searchMode !== "resting"
+ ? keyboardHeight + 64
+ : Math.max(insets.bottom, 12) + workspaceToolbarHeight(tab.searchMode) + 16;
const context = useMemo(() => ({ ...workspace, bottomClearance }), [workspace, bottomClearance]);
return (
<WorkspaceTabsContext value={context}>
<View
- className={sidebarPicker ? "flex-1 bg-drawer" : "flex-1 bg-screen"}
+ className={`flex-1 ${sidebarPicker ? "bg-drawer" : surface.className}`}
style={sidebarPicker ? { paddingTop: insets.top } : undefined}
>
{Platform.OS === "ios" ? (
<NativeStackScreenOptions
- optionsVersion={[state.selectedTab, state.selectionRevision, width, sidebarNavigation]}
+ optionsVersion={[
+ state.selectedTab,
+ state.selectionRevision,
+ width,
+ sidebarNavigation,
+ enabled.length,
+ ]}
options={{
- title: TAB_TITLES[state.selectedTab],
+ title: enabled.length ? TAB_TITLES[state.selectedTab] : "Navigation",
headerShown: true,
+ headerTransparent: solidHeader ? false : NATIVE_LIQUID_GLASS_SUPPORTED,
+ headerStyle: solidHeader
+ ? { backgroundColor: surface.backgroundColor }
+ : NATIVE_LIQUID_GLASS_SUPPORTED
+ ? { backgroundColor: "transparent" }
+ : undefined,
+ contentStyle: solidHeader ? { backgroundColor: surface.backgroundColor } : undefined,
+ ...(state.selectedTab !== "usage" || enabled.length === 0
+ ? { headerRight: undefined }
+ : {}),
+ ...(enabled.length === 0
+ ? { headerSearchBarOptions: undefined, unstable_headerRightItems: () => [] }
+ : {}),
unstable_headerLeftItems: () => [],
- headerTitle: renderHeaderTitle,
+ headerTitle: state.selectedTab === "usage" ? undefined : renderHeaderTitle,
}}
/>
) : (
@@ -128,14 +170,18 @@ function WorkspaceRootContent() {
title="T3 Code"
titleContent={renderHeaderTitle()}
actions={[
- {
- accessibilityLabel:
- state.selectedTab === "threads" ? "Search threads" : "Search pull requests",
- icon: "magnifyingglass",
- onPress: () => {
- dispatchHardwareKeyboardCommand("focusSearch");
- },
- },
+ ...(state.selectedTab === "threads" || state.selectedTab === "pullRequests"
+ ? [
+ {
+ accessibilityLabel:
+ state.selectedTab === "threads" ? "Search threads" : "Search pull requests",
+ icon: "magnifyingglass" as const,
+ onPress: () => {
+ dispatchHardwareKeyboardCommand("focusSearch");
+ },
+ },
+ ]
+ : []),
{
accessibilityLabel: "Settings",
icon: "gearshape",
@@ -148,11 +194,33 @@ function WorkspaceRootContent() {
]}
/>
)}
- <SafeAreaInsetsContext value={sidebarPicker ? { ...insets, top: 0 } : insets}>
- {state.selectedTab === "threads" ? <HomeRouteScreen /> : <PullRequestsScreen />}
+ <SafeAreaInsetsContext
+ value={
+ sidebarPicker ? { ...insets, top: 0 } : compactTabs ? { ...insets, bottom: 0 } : insets
+ }
+ >
+ {enabled.length === 0 ? (
+ <WorkspaceNoTabs />
+ ) : state.selectedTab === "threads" ? (
+ <HomeRouteScreen />
+ ) : state.selectedTab === "pullRequests" ? (
+ <PullRequestsScreen />
+ ) : (
+ <WorkspaceExtraTab tab={state.selectedTab} />
+ )}
</SafeAreaInsetsContext>
- {sidebarPicker ? <WorkspaceSidebarTabs /> : null}
- <WorkspaceToolbar sidebar={sidebarNavigation} onNewTask={startNewTask} />
+ {deviceType !== "pad" && deviceType !== "phone" && sidebarPicker ? (
+ <WorkspaceSidebarTabs />
+ ) : null}
+ {enabled.length === 0 ? null : state.selectedTab === "threads" ||
+ state.selectedTab === "pullRequests" ? (
+ <WorkspaceToolbar sidebar={sidebarNavigation} onNewTask={startNewTask} />
+ ) : (
+ <WorkspaceSectionToolbar
+ onNewTask={startNewTask}
+ showCompose={state.selectedTab !== "usage"}
+ />
+ )}
</View>
</WorkspaceTabsContext>
);
diff --git a/apps/mobile/src/features/workspace/WorkspaceSectionToolbar.tsx b/apps/mobile/src/features/workspace/WorkspaceSectionToolbar.tsx
new file mode 100644
index 00000000000..cf105d8ad82
--- /dev/null
+++ b/apps/mobile/src/features/workspace/WorkspaceSectionToolbar.tsx
@@ -0,0 +1,91 @@
+import { useNavigation } from "@react-navigation/native";
+import { selectedNavigationTab, visibleNavigationTabs } from "./navigation-tab-order";
+import { Toolbar } from "../../components/ui/Toolbar";
+import { useControlTheme } from "../../components/ui/useControlTheme";
+import { useDeviceType } from "../../native/native-layout-metrics";
+import {
+ NAVIGATION_TAB_ICONS,
+ WORKSPACE_TAB_LABELS,
+ useNavigationTabOrder,
+ useHiddenNavigationTabs,
+} from "./navigation-tabs";
+import { useWorkspaceTabs } from "./WorkspaceTabsContext";
+import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
+import { useCompactWorkspaceTabs, useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar";
+
+const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
+
+export function WorkspaceTabToolbarButtons() {
+ const order = useNavigationTabOrder();
+ const hidden = useHiddenNavigationTabs();
+ const workspace = useWorkspaceTabs()!;
+ const selectTab = useSelectWorkspaceTab();
+ const navigation = useNavigation();
+ const selected = selectedNavigationTab(
+ order,
+ workspace.state.selectedTab,
+ workspace.settingsOpen,
+ hidden,
+ );
+ const selectedTint = useControlTheme().colors["--color-primary"];
+ return (
+ <>
+ {visibleNavigationTabs(order, hidden).map((tab) => (
+ <Toolbar.Button
+ key={tab}
+ identifier={`workspace-tab-${tab}`}
+ accessibilityLabel={WORKSPACE_TAB_LABELS[tab]}
+ icon={
+ tab === "pullRequests"
+ ? { type: "image", source: PULL_REQUEST_ICON, tinted: true }
+ : NAVIGATION_TAB_ICONS[tab]
+ }
+ tintColor={selected === tab ? selectedTint : undefined}
+ onPress={() => selectTab(tab)}
+ />
+ ))}
+ <Toolbar.Button
+ identifier="workspace-tab-settings"
+ accessibilityLabel="Settings"
+ icon="gearshape"
+ tintColor={selected === "settings" ? selectedTint : undefined}
+ onPress={() =>
+ navigation.navigate("SettingsSheet", {
+ screen: "SettingsContent",
+ params: { screen: "Settings" },
+ })
+ }
+ />
+ </>
+ );
+}
+
+export function WorkspaceSectionToolbar({
+ onNewTask,
+ showCompose = true,
+}: {
+ readonly onNewTask: () => void;
+ readonly showCompose?: boolean;
+}) {
+ const sidebarTabs = useSidebarWorkspaceTabs();
+ const compactTabs = useCompactWorkspaceTabs();
+ const deviceType = useDeviceType();
+ return (
+ <>
+ {showCompose && sidebarTabs !== "picker" && deviceType !== "duo-unfolded" && !compactTabs ? (
+ <Toolbar placement="right">
+ <Toolbar.Button
+ accessibilityLabel="New chat"
+ icon="square.and.pencil"
+ onPress={onNewTask}
+ />
+ </Toolbar>
+ ) : null}
+ {sidebarTabs === "toolbar" ? (
+ <Toolbar placement="bottom">
+ <WorkspaceTabToolbarButtons />
+ </Toolbar>
+ ) : null}
+ </>
+ );
+}
diff --git a/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.ios.tsx
index 476f6a386bf..4b260b0cc46 100644
--- a/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.ios.tsx
@@ -1,33 +1,78 @@
+import { useNavigation } from "@react-navigation/native";
+import { selectedNavigationTab, visibleNavigationTabs } from "./navigation-tab-order";
import { requireNativeView } from "expo";
import type { NativeSyntheticEvent, ViewProps } from "react-native";
-import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useControlTheme } from "../../components/ui/useControlTheme";
+import { useNavigationTabOrder, useHiddenNavigationTabs } from "./navigation-tabs";
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
const NativeSidebarTabBar = requireNativeView<
ViewProps & {
- selectedIndex: number;
+ tabs: readonly string[];
+ selectedTab: string;
selectedColor: string;
appearance: string;
- onSelectionChange: (event: NativeSyntheticEvent<{ index: number }>) => void;
+ showsCompose: boolean;
+ compact?: boolean;
+ onSelectionChange: (event: NativeSyntheticEvent<{ tab: string }>) => void;
+ onCompose: () => void;
}
>("T3NativeControls", "SidebarTabBar");
-export function WorkspaceSidebarTabs() {
+export function WorkspaceSidebarTabs(props: {
+ readonly onNewTask?: () => void;
+ readonly compact?: boolean;
+ readonly reserveComposeSpace?: boolean;
+}) {
const workspace = useWorkspaceTabs()!;
+ const order = useNavigationTabOrder();
+ const hidden = useHiddenNavigationTabs();
+ const tabs = [...visibleNavigationTabs(order, hidden), "settings" as const];
+ const navigation = useNavigation();
const selectTab = useSelectWorkspaceTab();
- const insets = useSafeAreaInsets();
const { colors, colorScheme } = useControlTheme();
+ // UIKit loses accessible names when updating nil-titled items in place.
+ const tabBarKey = tabs.join(":");
return (
<NativeSidebarTabBar
- selectedIndex={workspace.state.selectedTab === "threads" ? 0 : 1}
+ key={tabBarKey}
+ tabs={tabs}
+ selectedTab={selectedNavigationTab(
+ order,
+ workspace.state.selectedTab,
+ workspace.settingsOpen,
+ hidden,
+ )}
selectedColor={colors["--color-primary"]}
appearance={colorScheme}
- onSelectionChange={({ nativeEvent }) =>
- selectTab(nativeEvent.index === 0 ? "threads" : "pullRequests")
- }
- style={{ position: "absolute", bottom: 0, left: 0, right: 0, height: 64 + insets.bottom }}
+ showsCompose={Boolean(props.onNewTask)}
+ compact={props.compact}
+ onCompose={() => props.onNewTask?.()}
+ onSelectionChange={({ nativeEvent }) => {
+ const tab = tabs.find((candidate) => candidate === nativeEvent.tab);
+ if (tab === "settings")
+ navigation.navigate("SettingsSheet", {
+ screen: "SettingsContent",
+ params: { screen: "Settings" },
+ });
+ else if (tab) selectTab(tab);
+ }}
+ // Keep the host stable while UIKit updates the bars' intrinsic size and safe area together.
+ style={{
+ position: "absolute",
+ bottom: 0,
+ left: props.compact ? 8 : 0,
+ // Keep the tab icons in place when Compose disappears on other destinations.
+ right:
+ (props.compact ? 12 : 0) +
+ ((props.reserveComposeSpace ?? props.compact) && !props.onNewTask
+ ? props.compact
+ ? 64
+ : 76
+ : 0),
+ height: 128,
+ }}
/>
);
}
diff --git a/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.tsx b/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.tsx
index 480084f5da2..a55966a2676 100644
--- a/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceSidebarTabs.tsx
@@ -1,3 +1,7 @@
-export function WorkspaceSidebarTabs() {
+export function WorkspaceSidebarTabs(_props: {
+ readonly onNewTask?: () => void;
+ readonly compact?: boolean;
+ readonly reserveComposeSpace?: boolean;
+}) {
return null;
}
diff --git a/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx b/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
index 863701444d0..f8e23235d3d 100644
--- a/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
@@ -1,3 +1,5 @@
+import { resolveSelectedNavigationTab } from "./navigation-tab-order";
+import { useNavigationTabOrder, useHiddenNavigationTabs } from "./navigation-tabs";
import {
createContext,
use,
@@ -22,6 +24,7 @@ export const WorkspaceTabsContext = createContext<{
readonly dispatch: Dispatch<WorkspaceTabsAction>;
readonly isTabActive: (tab: WorkspaceTab) => boolean;
readonly bottomClearance: number;
+ readonly settingsOpen: boolean;
readonly getScrollOffset: (tab: WorkspaceTab) => number;
readonly recordScrollOffset: (tab: WorkspaceTab, offset: number) => void;
} | null>(null);
@@ -30,14 +33,21 @@ export function useWorkspaceTabs() {
return use(WorkspaceTabsContext);
}
-export function WorkspaceTabsProvider(props: { readonly children: ReactNode }) {
+export function WorkspaceTabsProvider(props: {
+ readonly children: ReactNode;
+ readonly settingsOpen?: boolean;
+}) {
const [state, dispatch] = useReducer(workspaceTabsReducer, undefined, initialWorkspaceTabsState);
+ const order = useNavigationTabOrder();
+ const hidden = useHiddenNavigationTabs();
+ const selected = resolveSelectedNavigationTab(order, hidden, state.selectedTab);
+ if (selected && selected !== state.selectedTab) dispatch({ type: "select", tab: selected });
const activeTab = useRef(state.selectedTab);
useLayoutEffect(() => {
activeTab.current = state.selectedTab;
}, [state.selectedTab]);
const isTabActive = useCallback((tab: WorkspaceTab) => activeTab.current === tab, []);
- const scrollOffsets = useRef({ threads: 0, pullRequests: 0 });
+ const scrollOffsets = useRef({ threads: 0, pullRequests: 0, usage: 0 });
const getScrollOffset = useCallback((tab: WorkspaceTab) => scrollOffsets.current[tab], []);
const recordScrollOffset = useCallback((tab: WorkspaceTab, offset: number) => {
scrollOffsets.current[tab] = offset;
@@ -48,10 +58,11 @@ export function WorkspaceTabsProvider(props: { readonly children: ReactNode }) {
dispatch,
isTabActive,
bottomClearance: 0,
+ settingsOpen: props.settingsOpen ?? false,
getScrollOffset,
recordScrollOffset,
}),
- [state, isTabActive, getScrollOffset, recordScrollOffset],
+ [state, isTabActive, getScrollOffset, recordScrollOffset, props.settingsOpen],
);
return <WorkspaceTabsContext value={context}>{props.children}</WorkspaceTabsContext>;
}
diff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
index b9cb4c59f30..c45f7d30117 100644
--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
@@ -1,6 +1,6 @@
import { useActiveNewTask } from "../../state/active-new-task";
import { Toolbar } from "../../components/ui/Toolbar";
-import { useFocusEffect, useNavigation } from "@react-navigation/native";
+import { useFocusEffect } from "@react-navigation/native";
import { use, useCallback, useEffect, useRef, type ReactNode } from "react";
import { Platform, Pressable, type TextInputInstance } from "react-native";
import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller";
@@ -20,12 +20,8 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WorkspaceSearchField } from "./WorkspaceSearchField";
import { WORKSPACE_TOOLBAR } from "./workspace-tabs-state";
-import { useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar";
-import { useSelectWorkspaceTab } from "./useSelectWorkspaceTab";
-import { useMobileNavigationTheme } from "../../lib/useMobileNavigationTheme";
-
-// Tabler's git-pull-request geometry, shared with the UIKit tab bar.
-const PULL_REQUEST_ICON = require("../../../assets/icons/pull-request.png");
+import { useCompactWorkspaceTabs, useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar";
+import { WorkspaceTabToolbarButtons } from "./WorkspaceSectionToolbar";
/**
* Rises once the keyboard reaches its content. UIKit also reports keyboards without height, with a
@@ -61,11 +57,9 @@ export function WorkspaceToolbar(props: {
}) {
const workspace = useWorkspaceTabs()!;
const activeNewTask = useActiveNewTask();
- const navigation = useNavigation();
const deviceType = useDeviceType();
const sidebarTabs = useSidebarWorkspaceTabs();
- const selectTab = useSelectWorkspaceTab();
- const selectedTint = useMobileNavigationTheme().colors.primary;
+ const compactTabs = useCompactWorkspaceTabs();
// On the Duo, compose belongs to the threads tab, in the detail column's bar when unfolded.
const nativeToolbarCompose =
Platform.OS === "ios" &&
@@ -168,16 +162,17 @@ export function WorkspaceToolbar(props: {
/>
{/* UIKit lays trailing items out from the edge inward. */}
<Toolbar placement="right">
- <Toolbar.Button
- accessibilityLabel="Settings"
- icon="gearshape"
- onPress={() =>
- navigation.navigate("SettingsSheet", {
- screen: "SettingsContent",
- params: { screen: "Settings" },
- })
- }
- />
+ {selectedTab !== "threads" ||
+ isDuoDevice(deviceType) ||
+ deviceType === "pad" ||
+ sidebarTabs === "picker" ||
+ compactTabs ? null : (
+ <Toolbar.Button
+ accessibilityLabel="New chat"
+ icon="square.and.pencil"
+ onPress={props.onNewTask}
+ />
+ )}
{NATIVE_LIQUID_GLASS_SUPPORTED ? null : (
<Toolbar.Button
accessibilityLabel={
@@ -189,24 +184,7 @@ export function WorkspaceToolbar(props: {
)}
</Toolbar>
<Toolbar placement="bottom">
- {sidebarTabs === "toolbar" ? (
- <Toolbar.Button
- identifier="workspace-tab-threads"
- accessibilityLabel="Threads"
- icon={selectedTab === "threads" ? "text.bubble.fill" : "text.bubble"}
- tintColor={selectedTab === "threads" ? selectedTint : undefined}
- onPress={() => selectTab("threads")}
- />
- ) : null}
- {sidebarTabs === "toolbar" ? (
- <Toolbar.Button
- identifier="workspace-tab-pull-requests"
- accessibilityLabel="Pull requests"
- icon={{ type: "image", source: PULL_REQUEST_ICON, tinted: true }}
- tintColor={selectedTab === "pullRequests" ? selectedTint : undefined}
- onPress={() => selectTab("pullRequests")}
- />
- ) : null}
+ {sidebarTabs === "toolbar" ? <WorkspaceTabToolbarButtons /> : null}
{nativeToolbarCompose ? <Toolbar.Spacer flexible /> : null}
{nativeToolbarCompose ? (
<Toolbar.Button
diff --git a/apps/mobile/src/features/workspace/navigation-tab-order.test.ts b/apps/mobile/src/features/workspace/navigation-tab-order.test.ts
new file mode 100644
index 00000000000..71ea901ed3b
--- /dev/null
+++ b/apps/mobile/src/features/workspace/navigation-tab-order.test.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from "vite-plus/test";
+import {
+ NAVIGATION_TAB_ORDER,
+ navigationCustomizationAvailable,
+ moveNavigationTab,
+ overflowNavigationTabs,
+ enabledNavigationTabs,
+ toggleNavigationTabVisibility,
+ resolveSelectedNavigationTab,
+ resolveNavigationTabOrder,
+ selectedNavigationTab,
+ visibleNavigationTabs,
+} from "./navigation-tab-order";
+
+describe("navigation tab order", () => {
+ it("enables customization only above four registered sections, excluding Settings", () => {
+ expect(navigationCustomizationAvailable()).toBe(false);
+ expect(navigationCustomizationAvailable(3)).toBe(false);
+ expect(navigationCustomizationAvailable(4)).toBe(false);
+ expect(navigationCustomizationAvailable(5)).toBe(true);
+ expect(navigationCustomizationAvailable(6)).toBe(true);
+ });
+
+ it("fills missing sections and drops removed placeholders, duplicates, and Settings", () => {
+ expect(
+ resolveNavigationTabOrder(["usage", "home", "issues", "settings", "usage", null]),
+ ).toEqual(["usage", "threads", "pullRequests"]);
+ expect(resolveNavigationTabOrder()).toEqual(NAVIGATION_TAB_ORDER);
+ });
+
+ it("moves a section without changing the relative order of the others", () => {
+ for (const tab of NAVIGATION_TAB_ORDER) {
+ for (let position = 0; position < NAVIGATION_TAB_ORDER.length; position++) {
+ const order = moveNavigationTab(NAVIGATION_TAB_ORDER, tab, position);
+ expect(order[position]).toBe(tab);
+ expect(order.filter((other) => other !== tab)).toEqual(
+ NAVIGATION_TAB_ORDER.filter((other) => other !== tab),
+ );
+ }
+ }
+ });
+
+ it("shows every real section without overflow and keeps Settings selected during editing", () => {
+ expect(visibleNavigationTabs()).toEqual(NAVIGATION_TAB_ORDER);
+ expect(overflowNavigationTabs()).toEqual([]);
+ expect(selectedNavigationTab(undefined, "threads", true)).toBe("settings");
+ expect(selectedNavigationTab(undefined, "usage", false)).toBe("usage");
+ expect(selectedNavigationTab(undefined, "usage", false, [], 2)).toBe("settings");
+ });
+
+ it("removes hidden sections from navigation and restores their saved positions", () => {
+ const order = moveNavigationTab(undefined, "usage", 0);
+ const hidden = toggleNavigationTabVisibility([], "usage");
+ expect(enabledNavigationTabs(order, hidden)).toEqual(["threads", "pullRequests"]);
+ expect(toggleNavigationTabVisibility(hidden, "usage")).toEqual([]);
+ expect(visibleNavigationTabs(order, [], 5)).toEqual(order);
+ expect(enabledNavigationTabs(undefined, ["home", "issues", "settings"])).toEqual(
+ NAVIGATION_TAB_ORDER,
+ );
+ });
+
+ it("falls back when the selected section is hidden, including when all are hidden", () => {
+ expect(resolveSelectedNavigationTab(undefined, ["threads"], "threads")).toBe("pullRequests");
+ expect(resolveSelectedNavigationTab(undefined, ["threads"], "usage")).toBe("usage");
+ expect(
+ resolveSelectedNavigationTab(undefined, NAVIGATION_TAB_ORDER, "threads"),
+ ).toBeUndefined();
+ });
+});
diff --git a/apps/mobile/src/features/workspace/navigation-tab-order.ts b/apps/mobile/src/features/workspace/navigation-tab-order.ts
new file mode 100644
index 00000000000..85e3e1c6f29
--- /dev/null
+++ b/apps/mobile/src/features/workspace/navigation-tab-order.ts
@@ -0,0 +1,87 @@
+export const NAVIGATION_TAB_ORDER = ["threads", "pullRequests", "usage"] as const;
+export type NavigationTab = (typeof NAVIGATION_TAB_ORDER)[number];
+
+export function navigationCustomizationAvailable(
+ registeredSections: number = NAVIGATION_TAB_ORDER.length,
+) {
+ return registeredSections > 4;
+}
+
+export const NAVIGATION_TAB_LABELS: Readonly<Record<NavigationTab, string>> = {
+ threads: "Threads",
+ pullRequests: "Pulls",
+ usage: "Usage",
+};
+
+function isNavigationTab(value: unknown): value is NavigationTab {
+ return NAVIGATION_TAB_ORDER.some((tab) => tab === value);
+}
+
+/** Complete older preferences without losing their order or retaining removed sections. */
+export function resolveNavigationTabOrder(saved?: readonly unknown[]): readonly NavigationTab[] {
+ if (!saved?.length) return NAVIGATION_TAB_ORDER;
+ return [...new Set([...saved.filter(isNavigationTab), ...NAVIGATION_TAB_ORDER])];
+}
+
+export function moveNavigationTab(
+ saved: readonly unknown[] | undefined,
+ tab: NavigationTab,
+ position: number,
+): readonly NavigationTab[] {
+ const order = [...resolveNavigationTabOrder(saved)];
+ const from = order.indexOf(tab);
+ const to = Math.max(0, Math.min(order.length - 1, position));
+ order.splice(from, 1);
+ order.splice(to, 0, tab);
+ return order;
+}
+
+export function resolveHiddenNavigationTabs(saved?: readonly unknown[]): readonly NavigationTab[] {
+ return [...new Set(saved?.filter(isNavigationTab) ?? [])];
+}
+
+export function toggleNavigationTabVisibility(
+ saved: readonly unknown[] | undefined,
+ tab: NavigationTab,
+) {
+ const hidden = resolveHiddenNavigationTabs(saved);
+ return hidden.includes(tab) ? hidden.filter((candidate) => candidate !== tab) : [...hidden, tab];
+}
+
+export function enabledNavigationTabs(saved?: readonly unknown[], hidden?: readonly unknown[]) {
+ const excluded = resolveHiddenNavigationTabs(hidden);
+ return resolveNavigationTabOrder(saved).filter((tab) => !excluded.includes(tab));
+}
+
+export function visibleNavigationTabs(
+ saved?: readonly unknown[],
+ hidden?: readonly unknown[],
+ capacity = 4,
+) {
+ return enabledNavigationTabs(saved, hidden).slice(0, capacity);
+}
+
+export function overflowNavigationTabs(saved?: readonly unknown[], hidden?: readonly unknown[]) {
+ return enabledNavigationTabs(saved, hidden).slice(4);
+}
+
+export function selectedNavigationTab(
+ saved: readonly unknown[] | undefined,
+ selected: NavigationTab,
+ settingsOpen: boolean,
+ hidden?: readonly unknown[],
+ capacity = 4,
+): NavigationTab | "settings" {
+ return settingsOpen || !visibleNavigationTabs(saved, hidden, capacity).includes(selected)
+ ? "settings"
+ : selected;
+}
+
+export function resolveSelectedNavigationTab(
+ saved: readonly unknown[] | undefined,
+ hidden: readonly unknown[] | undefined,
+ selected: NavigationTab,
+) {
+ const enabled = enabledNavigationTabs(saved, hidden);
+ return enabled.includes(selected) ? selected : enabled[0];
+}
diff --git a/apps/mobile/src/features/workspace/navigation-tabs.ts b/apps/mobile/src/features/workspace/navigation-tabs.ts
new file mode 100644
index 00000000000..719a40d8410
--- /dev/null
+++ b/apps/mobile/src/features/workspace/navigation-tabs.ts
@@ -0,0 +1,51 @@
+import { useAtomValue } from "@effect/atom-react";
+import { AsyncResult } from "effect/reactivity";
+import { useMemo } from "react";
+import { Platform } from "react-native";
+import {
+ NAVIGATION_TAB_LABELS,
+ navigationCustomizationAvailable,
+ resolveHiddenNavigationTabs,
+ enabledNavigationTabs,
+ type NavigationTab,
+} from "./navigation-tab-order";
+import type { AppSymbolName } from "../../components/ui/AppSymbol";
+import { mobilePreferencesAtom } from "../../state/preferences";
+import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
+import { resolveWorkspaceTabOrder } from "./workspace-tabs-state";
+
+export const WORKSPACE_TAB_LABELS = {
+ ...NAVIGATION_TAB_LABELS,
+ ...(Platform.OS === "ios" ? { threads: "Chats", pullRequests: "PRs" } : {}),
+};
+
+export const NAVIGATION_TAB_ICONS = {
+ threads: "text.bubble",
+ pullRequests: PullRequestGlyph.pullRequest,
+ usage: "chart.bar.xaxis",
+} as const satisfies Readonly<Record<NavigationTab, AppSymbolName>>;
+
+export function useNavigationTabOrder() {
+ const preferences = useAtomValue(mobilePreferencesAtom);
+ const saved = AsyncResult.isSuccess(preferences)
+ ? preferences.value.navigationTabOrder
+ : undefined;
+ return useMemo(() => resolveWorkspaceTabOrder(saved), [saved]);
+}
+
+export function useHiddenNavigationTabs() {
+ const preferences = useAtomValue(mobilePreferencesAtom);
+ const saved = AsyncResult.isSuccess(preferences)
+ ? preferences.value.hiddenNavigationTabs
+ : undefined;
+ return useMemo(
+ () => (navigationCustomizationAvailable() ? resolveHiddenNavigationTabs(saved) : []),
+ [saved],
+ );
+}
+
+export function useEnabledNavigationTabs() {
+ const order = useNavigationTabOrder();
+ const hidden = useHiddenNavigationTabs();
+ return useMemo(() => enabledNavigationTabs(order, hidden), [order, hidden]);
+}
diff --git a/apps/mobile/src/features/workspace/useSelectWorkspaceTab.ts b/apps/mobile/src/features/workspace/useSelectWorkspaceTab.ts
index dcfc35d32e2..6c31cee8738 100644
--- a/apps/mobile/src/features/workspace/useSelectWorkspaceTab.ts
+++ b/apps/mobile/src/features/workspace/useSelectWorkspaceTab.ts
@@ -1,6 +1,7 @@
import { StackActions, useNavigation } from "@react-navigation/native";
import { useCallback } from "react";
-import { Keyboard } from "react-native";
+import { Keyboard, Platform } from "react-native";
+import { resetAndroidWorkspace } from "../../lib/android-workspace-navigation";
import { useWorkspaceTabs } from "./WorkspaceTabsContext";
import type { WorkspaceTab } from "./workspace-tabs-state";
@@ -8,15 +9,14 @@ import type { WorkspaceTab } from "./workspace-tabs-state";
export function useSelectWorkspaceTab() {
const workspace = useWorkspaceTabs()!;
const navigation = useNavigation();
- const selectedTab = workspace.state.selectedTab;
const { dispatch } = workspace;
return useCallback(
(tab: WorkspaceTab) => {
- if (tab === selectedTab) return;
Keyboard.dismiss();
- if (navigation.getState()?.index) navigation.dispatch(StackActions.popToTop());
+ if (Platform.OS === "android") resetAndroidWorkspace(navigation);
+ else navigation.dispatch(StackActions.popTo("Home"));
dispatch({ type: "select", tab });
},
- [dispatch, navigation, selectedTab],
+ [dispatch, navigation],
);
}
diff --git a/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts b/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
index 56ea918ede0..461b2ddae06 100644
--- a/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
+++ b/apps/mobile/src/features/workspace/useSystemWorkspaceTabBar.ts
@@ -1,20 +1,47 @@
+import { isDuoDevice } from "../../lib/device-type";
import { Platform } from "react-native";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
+import { useWorkspaceTabs } from "./WorkspaceTabsContext";
+import { workspaceUsesColumns } from "./workspace-tabs-state";
+
+function useWorkspacePage() {
+ const workspace = useWorkspaceTabs();
+ return (
+ workspace !== null &&
+ (workspace.settingsOpen || !workspaceUsesColumns(workspace.state.selectedTab))
+ );
+}
/** Where an iOS split window shows the workspace tabs instead of UIKit's tab bar. */
export function useSidebarWorkspaceTabs(): "picker" | "toolbar" | null {
const { layout } = useAdaptiveWorkspaceLayout();
const deviceType = useDeviceType();
const metrics = useNativeLayoutMetrics();
- if (Platform.OS !== "ios" || !layout.usesSplitView) return null;
- if (deviceType === "pad") return "picker";
- // The Duo's side rail carries UIKit's tabs. Unfolded in portrait it has no
- // rail, so the tabs sit in the thread list's own toolbar.
+ const page = useWorkspacePage();
+ if (Platform.OS !== "ios" || !layout.usesSplitView || page) return null;
+ if (deviceType === "pad") return null;
+ // Portrait Duo has no system rail; keep its tabs in the sidebar like iPad.
+ if (deviceType === "duo-unfolded" && (metrics?.verticalBarEdge ?? "none") === "none")
+ return "picker";
return (metrics?.verticalBarEdge ?? "none") === "none" ? "toolbar" : null;
}
+export function useCompactWorkspaceTabs() {
+ const { layout } = useAdaptiveWorkspaceLayout();
+ const deviceType = useDeviceType();
+ // The compact glass picker reserves the trailing edge for a separate compose button.
+ return (
+ Platform.OS === "ios" &&
+ deviceType !== "pad" &&
+ !layout.usesSplitView &&
+ !isDuoDevice(deviceType)
+ );
+}
+
export function useSystemWorkspaceTabBar() {
+ const deviceType = useDeviceType();
const sidebarTabs = useSidebarWorkspaceTabs();
- return Platform.OS === "ios" && sidebarTabs === null;
+ const compactTabs = useCompactWorkspaceTabs();
+ return Platform.OS === "ios" && deviceType !== "pad" && sidebarTabs === null && !compactTabs;
}
diff --git a/apps/mobile/src/features/workspace/useWorkspaceSurface.ts b/apps/mobile/src/features/workspace/useWorkspaceSurface.ts
new file mode 100644
index 00000000000..6b9c664ecf8
--- /dev/null
+++ b/apps/mobile/src/features/workspace/useWorkspaceSurface.ts
@@ -0,0 +1,11 @@
+import { useControlTheme } from "../../components/ui/useControlTheme";
+import { useDeviceType } from "../../native/native-layout-metrics";
+
+export function useWorkspaceSurface() {
+ const cover = useDeviceType() === "duo-folded";
+ const { colors } = useControlTheme();
+ return {
+ className: cover ? "bg-drawer" : "bg-screen",
+ backgroundColor: colors[cover ? "--color-drawer" : "--color-screen"],
+ };
+}
diff --git a/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts b/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
index 22f488faf70..197d4ba27a0 100644
--- a/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
+++ b/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
@@ -1,7 +1,73 @@
import { describe, expect, it } from "vite-plus/test";
-import { initialWorkspaceTabsState, workspaceTabsReducer } from "./workspace-tabs-state";
+import {
+ initialWorkspaceTabsState,
+ workspaceTabsReducer,
+ workspaceTabForNativeSlot,
+ resolveWorkspaceTabOrder,
+ workspaceSearchBottomClearance,
+ workspaceDockBottomClearance,
+ workspaceUsesColumns,
+} from "./workspace-tabs-state";
+
+describe("compact list clearance", () => {
+ it.each([
+ { bottomInset: 34, keyboardHeight: 300, clearance: 380 },
+ { bottomInset: 34, keyboardHeight: 0, clearance: 114 },
+ { bottomInset: 34, keyboardHeight: 20, clearance: 114 },
+ ])("keeps the last result above the keyboard and dock: %j", ({ clearance, ...input }) => {
+ expect(workspaceDockBottomClearance(input)).toBe(clearance);
+ });
+});
+
+describe("Duo list clearance", () => {
+ it.each([18, 60])(
+ "scrolls the last row above search with a %s-point native bar inset",
+ (bottomBarInset) => {
+ const clearance = workspaceSearchBottomClearance({
+ bottomInset: 34,
+ bottomBarInset,
+ keyboardHeight: 0,
+ });
+ expect(clearance).toBe(bottomBarInset + 48 + 16);
+ },
+ );
+
+ it("keeps the last row above search when the keyboard lifts the field", () => {
+ expect(
+ workspaceSearchBottomClearance({ bottomInset: 34, bottomBarInset: 18, keyboardHeight: 300 }),
+ ).toBe(300 + 8 + 48 + 16);
+ });
+
+ it("falls back to the field's safe-area spacing before native bar metrics arrive", () => {
+ expect(workspaceSearchBottomClearance({ bottomInset: 34, keyboardHeight: 0 })).toBe(
+ 34 + 48 + 16,
+ );
+ expect(workspaceSearchBottomClearance({ bottomInset: 0, keyboardHeight: 0 })).toBe(
+ 12 + 48 + 16,
+ );
+ });
+});
describe("workspace root navigation", () => {
+ it("keeps Usage and Settings out of the list/detail layout", () => {
+ expect(workspaceUsesColumns("usage")).toBe(false);
+ expect(workspaceUsesColumns("threads", "SettingsSheet")).toBe(false);
+ expect(workspaceUsesColumns("pullRequests", "SettingsSheet")).toBe(false);
+ });
+
+ it("restores columns for chat and pull request lists and their details", () => {
+ expect(workspaceUsesColumns("threads")).toBe(true);
+ expect(workspaceUsesColumns("threads", "Thread")).toBe(true);
+ expect(workspaceUsesColumns("pullRequests", "PullRequest")).toBe(true);
+ });
+
+ it("keeps the registered defaults while customization is unavailable", () => {
+ expect(resolveWorkspaceTabOrder(undefined)).toEqual(["threads", "pullRequests", "usage"]);
+ expect(resolveWorkspaceTabOrder(["home", "usage", "issues", "threads"])).toEqual(
+ resolveWorkspaceTabOrder(undefined),
+ );
+ });
+
it("retains separate queries and positions across tabs, and cancels only the current search", () => {
let state = initialWorkspaceTabsState();
state = workspaceTabsReducer(state, { type: "scroll", tab: "threads", offset: 640 });
@@ -64,4 +130,25 @@ describe("workspace root navigation", () => {
expect(state.tabs.pullRequests.searchMode).toBe("resting");
expect(workspaceTabsReducer(state, { type: "select", tab: "pullRequests" })).toBe(state);
});
+ it("returns from Usage without losing list state", () => {
+ let state = workspaceTabsReducer(initialWorkspaceTabsState(), {
+ type: "query",
+ query: "retained",
+ tab: "threads",
+ });
+ for (const tab of ["usage"] as const) {
+ state = workspaceTabsReducer(state, { type: "select", tab });
+ expect(state.selectedTab).toBe(tab);
+ expect(workspaceTabsReducer(state, { type: "search" })).toBe(state);
+ }
+ state = workspaceTabsReducer(state, { type: "select", tab: "threads" });
+ expect(state.tabs.threads.query).toBe("retained");
+ });
+ it("opens Settings on native reselection instead of selecting its overflow section", () => {
+ const order = ["threads", "pullRequests", "usage"] as const;
+ expect(workspaceTabForNativeSlot(order, "settings")).toBe("settings");
+ expect(workspaceTabForNativeSlot(order, "first")).toBe("threads");
+ expect(workspaceTabForNativeSlot(order, "third")).toBe("usage");
+ expect(workspaceTabForNativeSlot(order, "removed")).toBeNull();
+ });
});
diff --git a/apps/mobile/src/features/workspace/workspace-tabs-state.ts b/apps/mobile/src/features/workspace/workspace-tabs-state.ts
index 810742b08cb..52bafb42a70 100644
--- a/apps/mobile/src/features/workspace/workspace-tabs-state.ts
+++ b/apps/mobile/src/features/workspace/workspace-tabs-state.ts
@@ -1,6 +1,23 @@
-export type WorkspaceTab = "threads" | "pullRequests";
+import {
+ NAVIGATION_TAB_ORDER,
+ navigationCustomizationAvailable,
+ resolveNavigationTabOrder,
+ type NavigationTab,
+} from "./navigation-tab-order";
+
+export function resolveWorkspaceTabOrder(saved: readonly unknown[] | undefined) {
+ return navigationCustomizationAvailable()
+ ? resolveNavigationTabOrder(saved)
+ : NAVIGATION_TAB_ORDER;
+}
+
+export type WorkspaceTab = NavigationTab;
export type WorkspaceSearchMode = "resting" | "active" | "expanded";
+export function workspaceUsesColumns(tab: WorkspaceTab, detailRoute?: string) {
+ return (tab === "threads" || tab === "pullRequests") && detailRoute !== "SettingsSheet";
+}
+
export interface WorkspaceTabState {
readonly query: string;
readonly searchMode: WorkspaceSearchMode;
@@ -22,7 +39,11 @@ export function initialWorkspaceTabsState(): WorkspaceTabsState {
return {
selectedTab: "threads",
selectionRevision: 0,
- tabs: { threads: emptyTab(), pullRequests: emptyTab() },
+ tabs: {
+ threads: emptyTab(),
+ pullRequests: emptyTab(),
+ usage: emptyTab(),
+ },
};
}
@@ -47,6 +68,7 @@ export function workspaceTabsReducer(
selectionRevision: state.selectionRevision + 1,
};
const tab = action.tab ?? state.selectedTab;
+ if (tab !== "threads" && tab !== "pullRequests") return state;
const current = state.tabs[tab];
let next: WorkspaceTabState;
switch (action.type) {
@@ -84,8 +106,43 @@ export function workspaceTabsReducer(
export const WORKSPACE_TOOLBAR = { height: 48, expandedGap: 10, edge: 16, gap: 8 };
export const WORKSPACE_DOCK = { height: 48, tabsWidth: 176, gap: 12, bottomGap: 6 };
+export function workspaceDockBottomClearance(input: {
+ readonly bottomInset: number;
+ readonly keyboardHeight: number;
+}) {
+ return 64 + Math.max(input.bottomInset, input.keyboardHeight) + 16;
+}
+
+export function workspaceSearchBottomClearance(input: {
+ readonly bottomInset: number;
+ readonly bottomBarInset?: number;
+ readonly keyboardHeight: number;
+}) {
+ const bottom = input.bottomBarInset ?? Math.max(input.bottomInset, 12);
+ // AboveKeyboard lifts the field to an 8-point gap above the keyboard.
+ return (
+ Math.max(bottom, input.keyboardHeight > 0 ? input.keyboardHeight + 8 : 0) +
+ WORKSPACE_TOOLBAR.height +
+ 16
+ );
+}
+
export function workspaceToolbarHeight(mode: WorkspaceSearchMode): number {
return mode === "expanded"
? WORKSPACE_TOOLBAR.height * 2 + WORKSPACE_TOOLBAR.expandedGap
: WORKSPACE_TOOLBAR.height;
}
+
+export const NATIVE_WORKSPACE_TAB_SLOTS = [
+ "first",
+ "second",
+ "third",
+ "fourth",
+ "settings",
+] as const;
+
+export function workspaceTabForNativeSlot(order: readonly WorkspaceTab[], slot: string) {
+ if (slot === "settings") return "settings";
+ const index = NATIVE_WORKSPACE_TAB_SLOTS.findIndex((candidate) => candidate === slot);
+ return order[index] ?? null;
+}
diff --git a/apps/mobile/src/lib/storage.test.ts b/apps/mobile/src/lib/storage.test.ts
index e5dc872abeb..5d973742e42 100644
--- a/apps/mobile/src/lib/storage.test.ts
+++ b/apps/mobile/src/lib/storage.test.ts
@@ -131,6 +131,34 @@ describe("mobile connection storage", () => {
});
});
+ it("persists tab order locally and retains it when another preference changes", async () => {
+ const navigationTabOrder = ["usage", "threads", "pullRequests"];
+ const hiddenNavigationTabs = ["issues", "home"];
+ await savePreferencesPatch({ navigationTabOrder, hiddenNavigationTabs });
+ await savePreferencesPatch({ baseFontSize: 19 });
+ await expect(loadPreferences()).resolves.toEqual({
+ navigationTabOrder,
+ hiddenNavigationTabs,
+ baseFontSize: 19,
+ });
+ });
+
+ it("ignores invalid tab-order entries without dropping other saved preferences", async () => {
+ mocks.setPreferencesJson(
+ JSON.stringify({
+ navigationTabOrder: ["usage", null, 4, "threads"],
+ hiddenNavigationTabs: ["home", null],
+ baseFontSize: 18,
+ }),
+ 1,
+ );
+ await expect(loadPreferences()).resolves.toEqual({
+ navigationTabOrder: ["usage", "threads"],
+ hiddenNavigationTabs: ["home"],
+ baseFontSize: 18,
+ });
+ });
+
it("loads legacy preferences when SQLite is unavailable", async () => {
mocks.setDatabaseFailures(true, true);
await mocks.setItemAsync("t3code.preferences", JSON.stringify({ baseFontSize: 17 }));
diff --git a/apps/mobile/src/native/NativeColumnContent.ios.tsx b/apps/mobile/src/native/NativeColumnContent.ios.tsx
index 8a8fa0f599c..30350b51171 100644
--- a/apps/mobile/src/native/NativeColumnContent.ios.tsx
+++ b/apps/mobile/src/native/NativeColumnContent.ios.tsx
@@ -1,6 +1,6 @@
import { HeaderHeightContext } from "@react-navigation/elements";
import { useState, type ReactNode } from "react";
-import { View } from "react-native";
+import { View, type ColorValue } from "react-native";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import { NativeColumnLayoutMetricsContext } from "./native-layout-metrics";
import type { NativeLayoutMetrics } from "../lib/reserved-regions";
@@ -10,10 +10,16 @@ export function NativeColumnContent(props: {
readonly children: ReactNode;
readonly primary?: boolean;
readonly insetHorizontally?: boolean;
+ readonly backgroundColor?: ColorValue;
}) {
const [metrics, setMetrics] = useState<NativeLayoutMetrics | null>(null);
return (
- <View className={props.primary ? "flex-1 bg-drawer" : "flex-1 bg-screen"}>
+ <View
+ className={props.primary ? "flex-1 bg-drawer" : "flex-1 bg-screen"}
+ style={
+ props.backgroundColor === undefined ? undefined : { backgroundColor: props.backgroundColor }
+ }
+ >
<SafeAreaProvider style={{ flex: 1 }}>
<SafeAreaView
edges={props.insetHorizontally === false ? [] : ["left", "right"]}
diff --git a/apps/mobile/src/native/V5StackHeader.ios.tsx b/apps/mobile/src/native/V5StackHeader.ios.tsx
index 479ad3dce1a..b4f1c1c9a03 100644
--- a/apps/mobile/src/native/V5StackHeader.ios.tsx
+++ b/apps/mobile/src/native/V5StackHeader.ios.tsx
@@ -218,15 +218,22 @@ export function V5StackHeader(props: {
bottom.length = 0;
}
if (props.onCompose) {
- if (trailing.length)
- trailing.push({ type: "spacer", id: "compose-group", sizing: "fixed", width: 8 });
- trailing.push({
+ const compose: HeaderItem = {
type: "item",
id: "workspace-compose",
title: "New task",
icon: { type: "sfSymbol", name: "square.and.pencil" },
onPress: props.onCompose,
- });
+ };
+ if (deviceType === "duo-unfolded") {
+ if (leading.length)
+ leading.unshift({ type: "spacer", id: "compose-group", sizing: "fixed", width: 8 });
+ leading.unshift(compose);
+ } else {
+ if (trailing.length)
+ trailing.push({ type: "spacer", id: "compose-group", sizing: "fixed", width: 8 });
+ trailing.push(compose);
+ }
}
const left = options.headerLeft?.(itemProps);
const right = options.headerRight?.(itemProps);
diff --git a/apps/mobile/src/native/createV5StackNavigator.ios.tsx b/apps/mobile/src/native/createV5StackNavigator.ios.tsx
index 194a6e7f7e5..9b25c1ed109 100644
--- a/apps/mobile/src/native/createV5StackNavigator.ios.tsx
+++ b/apps/mobile/src/native/createV5StackNavigator.ios.tsx
@@ -237,6 +237,9 @@ export function V5CardStackView(
}
/>
<NativeColumnContent
+ backgroundColor={
+ StyleSheet.flatten(descriptor.options.contentStyle)?.backgroundColor
+ }
insetHorizontally={
(descriptor.options as AppNativeStackNavigationOptions)
.nativeContentInsetHorizontally
diff --git a/apps/mobile/src/persistence/mobile-preferences.ts b/apps/mobile/src/persistence/mobile-preferences.ts
index 7acdd47e4e6..a260a489d4c 100644
--- a/apps/mobile/src/persistence/mobile-preferences.ts
+++ b/apps/mobile/src/persistence/mobile-preferences.ts
@@ -51,6 +51,8 @@ const isThreadListFilters = Schema.is(ThreadListFilters);
const isPullRequestListPreferences = Schema.is(PullRequestListPreferences);
export interface Preferences {
+ readonly navigationTabOrder?: readonly string[];
+ readonly hiddenNavigationTabs?: readonly string[];
readonly pullRequestHideTestFiles?: boolean;
readonly pullRequestMergeMethod?: PullRequestMergeMethod;
readonly liveActivitiesEnabled?: boolean;
@@ -126,6 +128,8 @@ export class MobilePreferencesStore extends Context.Service<
function sanitizePreferences(parsed: Preferences): Preferences {
const preferences: {
+ navigationTabOrder?: readonly string[];
+ hiddenNavigationTabs?: readonly string[];
pullRequestHideTestFiles?: boolean;
pullRequestMergeMethod?: PullRequestMergeMethod;
liveActivitiesEnabled?: boolean;
@@ -157,6 +161,18 @@ function sanitizePreferences(parsed: Preferences): Preferences {
pullRequestListFilters?: PullRequestListPreferences;
} = {};
+ if (Array.isArray(parsed.hiddenNavigationTabs)) {
+ preferences.hiddenNavigationTabs = parsed.hiddenNavigationTabs.filter(
+ (tab): tab is string => typeof tab === "string",
+ );
+ }
+
+ if (Array.isArray(parsed.navigationTabOrder)) {
+ preferences.navigationTabOrder = parsed.navigationTabOrder.filter(
+ (tab): tab is string => typeof tab === "string",
+ );
+ }
+
if (typeof parsed.pullRequestHideTestFiles === "boolean") {
preferences.pullRequestHideTestFiles = parsed.pullRequestHideTestFiles;
}
diff --git a/docs/user/usage.md b/docs/user/usage.md
index e77b3ca2e1a..e41e60ca73d 100644
--- a/docs/user/usage.md
+++ b/docs/user/usage.md
@@ -4,6 +4,8 @@ Open **Usage** from the sidebar or the command palette, or press `mod+u` on web
desktop when the terminal is not focused. Customize `usage.open` in
**Settings → Keybindings**.
+On mobile, choose **Usage** in the workspace navigation.
+
## Understand your usage
**Usage** combines Codex, Claude Code, Grok Build, OpenCode, Antigravity, Pi, Muse Code, and Cursor history