diff --git a/apps/mobile/src/components/ui/AppBar.tsx b/apps/mobile/src/components/ui/AppBar.tsx index 5efe5f19d6d7f..b8635c3109ed4 100644 --- a/apps/mobile/src/components/ui/AppBar.tsx +++ b/apps/mobile/src/components/ui/AppBar.tsx @@ -12,7 +12,7 @@ import { NativeStackScreenOptions, useScreenOptionsWriter } from "../../native/S import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns"; import { useDeviceType } from "../../native/native-layout-metrics"; import { isDuoDevice } from "../../lib/device-type"; -import { useAdaptiveWorkspaceLayout } from "../../features/layout/AdaptiveWorkspaceLayout"; +import { useAdaptiveWorkspaceLayout } from "../../features/layout/adaptive-workspace-context"; import { useSidebarToggle } from "../../features/layout/useSidebarToggle"; import { InspectorCloseContext } from "../../features/layout/inspector-bar-store"; import { diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx index 8216a08c31f85..03cb506f2e8c5 100644 --- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx +++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx @@ -116,10 +116,15 @@ import { workspaceTabColumns, workspaceTabNavigationState, } from "./workspace/workspace-tab-navigation"; -import { workspaceTabOf, type WorkspaceTab } from "./workspace/workspace-tabs-state"; +import { + workspaceTabOf, + workspaceUsesColumns, + type WorkspaceTab, +} from "./workspace/workspace-tabs-state"; import { workspaceRoutesOf } from "./workspace-overlay-routes"; import { SettingsWorkspaceLayout } from "../settings/SettingsWorkspaceLayout"; import { WorkspaceThreadSidebar } from "./workspace/WorkspaceThreadSidebar"; +import { WorkspaceSettingsSidebar } from "../settings/WorkspaceSettingsSidebar"; export { useAdaptiveWorkspaceLayout, useWorkspacePaneState }; @@ -268,11 +273,9 @@ function AdaptiveWorkspaceLayoutContent( const { width: viewportWidth, height } = nativeMetrics ?? windowDimensions; const pathname = props.pathname; const workspace = useWorkspaceTabs(); - // Settings and Usage occupy the workspace rather than a list/detail pair. + // Settings and Usage fill Android's workspace; the legacy iPad split keeps its sidebar for them. const androidSettingsOpen = useAndroidWorkspaceRoot()?.settingsOpen ?? false; const safeAreaInsets = useSafeAreaInsets(); - const workspacePage = - Platform.OS === "android" && (androidSettingsOpen || workspace?.state.selectedTab === "usage"); const navigation = useNavigation(); const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true); const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true); @@ -295,6 +298,18 @@ function AdaptiveWorkspaceLayoutContent( () => deriveLayout({ width: viewportWidth, height, nativeMetrics, nativeWorkspace }), [height, viewportWidth, nativeMetrics, nativeWorkspace], ); + const workspacePage = + (Platform.OS === "android" && + (androidSettingsOpen || workspace?.state.selectedTab === "usage")) || + (Platform.OS === "ios" && + !nativeWorkspace && + workspace !== null && + !workspaceUsesColumns( + workspace.state.selectedTab, + workspace.settingsOpen, + false, + baseLayout.usesSplitView, + )); // The overlay sidebar closes when a page opens from it, and stays open on a list or on the // page a tab switch opened (`keepOpenFor`, set by that switch). const [overlaySidebar, setOverlaySidebar] = useState({ @@ -1038,8 +1053,13 @@ function AdaptiveWorkspaceLayoutContent( /> )} > - {/* Without a sidebar route (iPadOS before 26) the columns draw the thread list. */} - {sidebar ?? } + {/* Without a sidebar route (iPadOS before 26) the columns draw the active tab's list. */} + {sidebar ?? + (Platform.OS === "ios" && workspace?.settingsOpen ? ( + + ) : ( + + ))} {/* Keep the pill under the content throughout the sidebar's clipping animation. */} diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx index bee61a67f924a..022ab1edf8f03 100644 --- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx +++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx @@ -554,7 +554,12 @@ 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, workspace.settingsOpen); + const workspacePage = !workspaceUsesColumns( + workspace.state.selectedTab, + workspace.settingsOpen, + props.nativeColumns, + layout.usesSplitView, + ); const baseDescriptor: Descriptor = { ...primaryDescriptor, navigation: props.descriptors[visibleRoute.key]!.navigation, @@ -698,8 +703,9 @@ function WorkspaceStackNavigator({ ); return ( - - + {/* Before iOS 26 NavigationContent's layout draws the sidebar outside its children. */} + + - - + + ); } diff --git a/apps/mobile/src/features/layout/workspace/WorkspaceNativeTabs.ios.tsx b/apps/mobile/src/features/layout/workspace/WorkspaceNativeTabs.ios.tsx index aacb24094d354..3b246a9aca246 100644 --- a/apps/mobile/src/features/layout/workspace/WorkspaceNativeTabs.ios.tsx +++ b/apps/mobile/src/features/layout/workspace/WorkspaceNativeTabs.ios.tsx @@ -5,6 +5,7 @@ import { useEnabledNavigationTabs, } from "./navigation-tabs"; import { + use, useEffect, useLayoutEffect, useRef, @@ -25,6 +26,7 @@ import { } from "./workspace-tabs-state"; import { NativeWorkspaceTabActivityContext, + NativeWorkspaceModeContext, WorkspaceColumnMetricsContext, WorkspaceSlotOptionsContext, } from "../../../native/v5-workspace-context"; @@ -157,6 +159,7 @@ export function WorkspaceNativeTabs(props: { const selectTab = useSelectWorkspaceTab(); const [provenance, setProvenance] = useState(0); const systemTabBar = useSystemWorkspaceTabBar(); + const nativeColumns = use(NativeWorkspaceModeContext); const deviceType = useDeviceType(); const compactTabs = useCompactWorkspaceTabs(); const { layout } = useAdaptiveWorkspaceLayout(); @@ -165,7 +168,12 @@ export function WorkspaceNativeTabs(props: { const hiddenWithSidebar = deviceType === "pad" && layout.usesSplitView && - workspaceUsesColumns(workspace.state.selectedTab, workspace.settingsOpen) && + workspaceUsesColumns( + workspace.state.selectedTab, + workspace.settingsOpen, + nativeColumns, + layout.usesSplitView, + ) && !panes.primarySidebarVisible; const floatingTabs = useFloatingWorkspaceTabs(); const { width } = useWindowDimensions(); @@ -274,9 +282,18 @@ export function WorkspaceNativeTabs(props: { {(deviceType === "pad" || compactTabs || (layout.variant === "medium" && - !workspaceUsesColumns(selectedTab, workspace.settingsOpen))) && + !workspaceUsesColumns( + selectedTab, + workspace.settingsOpen, + nativeColumns, + layout.usesSplitView, + ))) && !props.hidden && !props.tabsInSidebarColumn && + // The legacy iPad sidebar now owns the tabs so they hide with it. + // + // 旧版 iPad 的标签栏由侧栏承载,从而与侧栏一起隐藏。 + !(deviceType === "pad" && !nativeColumns && layout.usesSplitView) && !hiddenWithSidebar ? ( {props.children} + {deviceType === "pad" && workspace !== null ? : null} ); } diff --git a/apps/mobile/src/features/layout/workspace/workspace-tabs-state.test.ts b/apps/mobile/src/features/layout/workspace/workspace-tabs-state.test.ts index 5a13614de5c62..a8b206e3eba78 100644 --- a/apps/mobile/src/features/layout/workspace/workspace-tabs-state.test.ts +++ b/apps/mobile/src/features/layout/workspace/workspace-tabs-state.test.ts @@ -55,11 +55,16 @@ describe("Duo list clearance", () => { }); describe("workspace root navigation", () => { - it("pairs Settings, chats and pull requests with a detail column, and keeps Usage one page", () => { + it("pairs Settings, chats, pull requests and issues with a detail column, and keeps Usage one page", () => { expect(workspaceUsesColumns("usage")).toBe(false); expect(workspaceUsesColumns("usage", true)).toBe(true); expect(workspaceUsesColumns("threads")).toBe(true); expect(workspaceUsesColumns("pullRequests")).toBe(true); + expect(workspaceUsesColumns("issues")).toBe(true); + // Before iOS 26 the split keeps its sidebar, which holds the tabs; a narrow window does not. + expect(workspaceUsesColumns("usage", false, false)).toBe(true); + expect(workspaceUsesColumns("usage", false, false, false)).toBe(false); + expect(workspaceUsesColumns("threads", true, false, false)).toBe(false); }); it("keeps the registered defaults while customization is unavailable", () => { diff --git a/apps/mobile/src/features/layout/workspace/workspace-tabs-state.ts b/apps/mobile/src/features/layout/workspace/workspace-tabs-state.ts index 2d3ad36a14523..b2f0626112c2e 100644 --- a/apps/mobile/src/features/layout/workspace/workspace-tabs-state.ts +++ b/apps/mobile/src/features/layout/workspace/workspace-tabs-state.ts @@ -16,9 +16,21 @@ export type WorkspaceTab = NavigationTab; export type WorkspaceSearchTab = WorkspaceTab | "settings"; export type WorkspaceSearchMode = "resting" | "active" | "expanded"; -/** Settings, Chats, pull requests and issues pair a list with a detail column; Usage is one page. */ -export function workspaceUsesColumns(tab: WorkspaceTab, settingsOpen = false) { - return settingsOpen || tab !== "usage"; +/** + * Settings, Chats, pull requests and issues pair a list with a detail column; Usage is one page. The + * pre-iOS 26 split previously hid the sidebar on Usage, taking its tabs with it. + * + * 旧版 iPad 的 Usage 侧栏曾随页面切换消失,导致标签栏丢失。 + */ +export function workspaceUsesColumns( + tab: WorkspaceTab, + settingsOpen = false, + nativeColumns = true, + splitView = true, +) { + return settingsOpen + ? nativeColumns || splitView + : (!nativeColumns && splitView) || tab !== "usage"; } export interface WorkspaceTabState { diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx index 2a0edba8a3cea..fb0a798094329 100644 --- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx @@ -16,7 +16,7 @@ import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScroll import { EmptyState } from "../../components/ui/EmptyState"; import { useAuth, useUser } from "@clerk/expo"; import { useNavigation, useNavigationState } from "@react-navigation/native"; -import { use, type ComponentProps } from "react"; +import { use, type ComponentProps, type ReactNode } from "react"; import { Platform, View } from "react-native"; import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics"; import { deriveProjectGroupLabel } from "@t3tools/client-runtime/state/project-grouping"; @@ -66,13 +66,14 @@ function useSettingsListPlacement() { return { sidebar, selected }; } -function SettingsListContent() { +export function SettingsListContent() { return hasCloudPublicConfig() ? : ; } export function SettingsListScreen(props: { readonly sidebar: boolean; readonly selected: string | null; + readonly children?: ReactNode; }) { const gt = useGT(); const workspace = useWorkspaceTabs(); @@ -95,7 +96,7 @@ export function SettingsListScreen(props: { : undefined } > - + {props.children ?? } diff --git a/apps/mobile/src/features/settings/WorkspaceSettingsSidebar.test.tsx b/apps/mobile/src/features/settings/WorkspaceSettingsSidebar.test.tsx new file mode 100644 index 0000000000000..697d4cabc65db --- /dev/null +++ b/apps/mobile/src/features/settings/WorkspaceSettingsSidebar.test.tsx @@ -0,0 +1,143 @@ +import { act, type ContextType, type ReactNode } from "react"; +import { createRoot } from "react-dom/client"; +import { describe, expect, it, vi } from "vite-plus/test"; +import { + NavigationContainerRefContext, + NavigationContext, + type NavigationState, +} from "@react-navigation/native"; + +vi.mock("@react-navigation/native", async () => { + // Resolve native's own core so the test exercises its real navigation-context fallback. + const { createRequire } = await import("node:module"); + const require = createRequire(import.meta.url); + const core = createRequire(require.resolve("@react-navigation/native")).resolve( + "@react-navigation/core", + ); + const actual = await import(core); + return { + ...actual, + useNavigationState: (select: (state: NavigationState) => unknown) => + select(actual.useNavigation().getState()), + }; +}); +vi.mock("react-native", () => ({ + Platform: { + OS: "ios", + select: (values: { ios?: unknown; default?: unknown }) => values.ios ?? values.default, + }, + I18nManager: { isRTL: false }, + Linking: {}, +})); +vi.mock("../../components/ui/ListRow", () => ({ + ListRow: ({ label, onPress }: { label: string; onPress: () => void }) => ( + + ), +})); +vi.mock("../../components/ui/ListRowLayout", () => ({ ListRowLayout: () => null })); +vi.mock("../../components/ui/RowPressable", () => ({ RowPressable: () => null })); +vi.mock("./components/SettingsSection", async () => { + const { createContext } = await import("react"); + return { SettingsSidebarContext: createContext(null) }; +}); +vi.mock("./SettingsRouteScreen", async () => { + const { SettingsRow } = await import("./components/SettingsRow"); + return { + SettingsListScreen: ({ children }: { children: ReactNode }) => children, + SettingsListContent: () => ( + + ), + }; +}); +vi.mock("../layout/workspace/WorkspaceSidebarColumn", async () => { + const { NavigationContainerRefContext, NavigationContext } = + await import("@react-navigation/native"); + return { + WorkspaceSidebarColumn: ({ children }: { children: ReactNode }) => { + const standalone = { + getState: () => ({ + key: "standalone", + routes: [{ key: "standalone-route", name: "Standalone" }], + index: 0, + }), + getParent: () => undefined, + dispatch: () => {}, + }; + return ( + } + > + {children} + + ); + }, + }; +}); + +import { WorkspaceSettingsSidebar } from "./WorkspaceSettingsSidebar"; + +describe("legacy Settings sidebar navigation", () => { + it.each([false, true])( + "opens General in the workspace with a screen navigation context of %s", + (screenContext) => { + const state = { + key: "workspace", + type: "stack", + stale: false, + index: 2, + routeNames: ["Home", "Settings", "SettingsEnvironments", "SettingsOrganization"], + routes: [ + { key: "home", name: "Home" }, + { key: "settings", name: "Settings" }, + { key: "environments", name: "SettingsEnvironments" }, + ], + }; + const dispatch = vi.fn(); + const navigation = { + getState: () => state, + getRootState: () => state, + getParent: () => undefined, + addListener: () => () => {}, + dispatch, + }; + const container = document.createElement("div"); + const root = createRoot(container); + try { + act(() => + root.render( + } + > + ) + : undefined + } + > + + + , + ), + ); + act(() => container.querySelector("button")!.click()); + expect(dispatch).toHaveBeenCalledWith( + expect.objectContaining({ + type: "RESET", + target: "workspace", + payload: expect.objectContaining({ + routeNames: state.routeNames, + routes: [ + state.routes[0], + state.routes[1], + { name: "SettingsOrganization", params: undefined }, + ], + }), + }), + ); + } finally { + act(() => root.unmount()); + } + }, + ); +}); diff --git a/apps/mobile/src/features/settings/WorkspaceSettingsSidebar.tsx b/apps/mobile/src/features/settings/WorkspaceSettingsSidebar.tsx new file mode 100644 index 0000000000000..b796496df5f03 --- /dev/null +++ b/apps/mobile/src/features/settings/WorkspaceSettingsSidebar.tsx @@ -0,0 +1,33 @@ +import { use } from "react"; +import { + NavigationContainerRefContext, + NavigationContext, + NavigationRouteContext, + useNavigationState, +} from "@react-navigation/native"; + +import { WorkspaceSidebarColumn } from "../layout/workspace/WorkspaceSidebarColumn"; +import { SettingsListContent, SettingsListScreen } from "./SettingsRouteScreen"; + +export function WorkspaceSettingsSidebar(props: { readonly width: number }) { + const navigation = use(NavigationContext); + const container = use(NavigationContainerRefContext); + const state = useNavigationState((state) => state); + const index = state.routes.findIndex((route) => route.name === "Settings"); + const route = state.routes[index]; + if (!route) return null; + return ( + + + {/* The sidebar column is a separate navigator; rows must act on the workspace's. */} + + + + + + + + + + ); +} diff --git a/apps/mobile/src/features/settings/components/SettingsScreen.tsx b/apps/mobile/src/features/settings/components/SettingsScreen.tsx index 240ac009bdc5a..16778e1fe1e73 100644 --- a/apps/mobile/src/features/settings/components/SettingsScreen.tsx +++ b/apps/mobile/src/features/settings/components/SettingsScreen.tsx @@ -45,8 +45,10 @@ export function SettingsScreen( search={props.search} trailing={props.trailing} menus={props.menus} - onBack={workspaceRoot ? undefined : back} - guardBack={props.guardBack} + // The column's first page also blocks system Back, which would reveal a second list. + onBack={workspaceRoot || back.columnRoot ? undefined : back.onBack} + onBackToList={!workspaceRoot && back.columnRoot ? back.onBack : undefined} + guardBack={props.guardBack || back.columnRoot} hideBottomBorder /> diff --git a/apps/mobile/src/features/settings/useSettingsPageBack.ts b/apps/mobile/src/features/settings/useSettingsPageBack.ts index 6ce9091834102..47735b618399a 100644 --- a/apps/mobile/src/features/settings/useSettingsPageBack.ts +++ b/apps/mobile/src/features/settings/useSettingsPageBack.ts @@ -6,8 +6,8 @@ import { useHardwareBack } from "../../lib/backHandler"; import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context"; /** - * The page's Back action, or undefined for the first page beside the Settings list on wide - * Android: that page roots the detail column, so Back leaves Settings rather than emptying it. + * The page's Back action. The first page beside the Settings list in a split roots the detail + * column (`columnRoot`): Back there leaves Settings rather than emptying the column. */ export function useSettingsPageBack() { const navigation = useNavigation(); @@ -15,11 +15,10 @@ export function useSettingsPageBack() { const { layout } = useAdaptiveWorkspaceLayout(); const routes = navigation.getState()?.routes ?? []; const below = routes[routes.findIndex((candidate) => candidate.key === route.key) - 1]; - const columnRoot = - Platform.OS === "android" && layout.usesSplitView && below?.name === "Settings"; - useHardwareBack(columnRoot, () => { + const columnRoot = layout.usesSplitView && below?.name === "Settings"; + useHardwareBack(Platform.OS === "android" && columnRoot, () => { resetAndroidWorkspace(navigation); return true; }); - return columnRoot ? undefined : () => navigation.goBack(); + return { columnRoot, onBack: () => navigation.goBack() }; } diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index f973d0c2fdf77..db8d62548647f 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -60,6 +60,8 @@ import { usePendingTaskListActions } from "../home/usePendingTaskListActions"; import { useThreadListActions } from "../home/useThreadListActions"; import { useFabScroll } from "../home/FabScrollContext"; import { WorkspaceListHeader } from "../layout/workspace/WorkspaceListHeader"; +import { useDeviceType } from "../../native/native-layout-metrics"; +import { workspaceDockBottomClearance } from "../layout/workspace/workspace-tabs-state"; import { WorkspaceSidebarColumn } from "../layout/workspace/WorkspaceSidebarColumn"; import { ThreadListV2PendingRow, @@ -124,6 +126,7 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) { const gt = useGT(); const messages = useMessages(); const floatingTabsEnabled = useAndroidFloatingTabs(); + const deviceType = useDeviceType(); const { themeVariables: materialTheme } = useAppearancePreferences(); const drawerColor = materialTheme["--color-drawer"]; @@ -631,7 +634,13 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) { contentContainerStyle={[ styles.threadListContent, { - paddingBottom: Math.max(insets.bottom, 16) + 16, + paddingBottom: + deviceType === "pad" + ? workspaceDockBottomClearance({ + bottomInset: insets.bottom, + keyboardHeight: 0, + }) + : Math.max(insets.bottom, 16) + 16, paddingTop: 6, }, ]} diff --git a/apps/mobile/vite.config.ts b/apps/mobile/vite.config.ts index 05261f9cb1848..ef915e97b7bcb 100644 --- a/apps/mobile/vite.config.ts +++ b/apps/mobile/vite.config.ts @@ -4,6 +4,7 @@ import { defineConfig, normalizePath } from "vite-plus"; import "vite-plus/test/config"; const reactTests = [ + "src/features/settings/WorkspaceSettingsSidebar.test.tsx", "src/features/threads/ThreadGuestShareSheet.test.tsx", "src/features/threads/useSubmitAfterNativeImages.test.tsx", "src/features/threads/git/GitBranchesSheet.test.tsx",