Skip to content
TypeScript

fix(mobile): sidebar toggle works on iPad and iPhone Duo (#20406)

Max Weinbachf8ec357f96a9
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index 931f8551825..338c795f0cc 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -38,6 +38,7 @@ import {
deriveLayout,
type VerticalHinge,
deriveWorkspacePaneLayout,
+ isPrimarySidebarPinned,
type FileInspectorPaneLayout,
type Layout,
type WorkspaceAuxiliaryPaneRole,
@@ -245,7 +246,6 @@ function AdaptiveWorkspaceLayoutContent(
const navigation = useNavigation();
const activeRoleOwner = useRef<symbol | null>(null);
const [primarySidebarPreferredVisible, setPrimarySidebarPreferredVisible] = useState(true);
- const showPrimarySidebar = pathname === "/" || primarySidebarPreferredVisible;
const [supplementaryPanePreferredVisible, setSupplementaryPanePreferredVisible] = useState(true);
const [supplementaryPanePreferredWidth, setSupplementaryPanePreferredWidth] = useState<
number | null
@@ -261,6 +261,12 @@ function AdaptiveWorkspaceLayoutContent(
() => deriveLayout({ width: viewportWidth, height, nativeMetrics }),
[height, viewportWidth, nativeMetrics],
);
+ const primarySidebarPinned = isPrimarySidebarPinned({
+ pathname,
+ nativeWorkspace,
+ usesSplitView: baseLayout.usesSplitView,
+ });
+ const showPrimarySidebar = primarySidebarPinned || primarySidebarPreferredVisible;
const shouldRenderNavigationRail = Platform.OS === "android" && baseLayout.usesSplitView;
const navigationRailWidth =
shouldRenderNavigationRail && showPrimarySidebar
@@ -378,7 +384,7 @@ function AdaptiveWorkspaceLayoutContent(
};
}, []);
const togglePrimarySidebar = useCallback(() => {
- if (pathname === "/") {
+ if (primarySidebarPinned) {
return;
}
if (!panes.primarySidebarVisible && panes.primarySidebarSuppressedByAuxiliary) {
@@ -387,7 +393,11 @@ function AdaptiveWorkspaceLayoutContent(
return;
}
setPrimarySidebarPreferredVisible((current) => !current);
- }, [panes.primarySidebarSuppressedByAuxiliary, panes.primarySidebarVisible, pathname]);
+ }, [
+ panes.primarySidebarSuppressedByAuxiliary,
+ panes.primarySidebarVisible,
+ primarySidebarPinned,
+ ]);
const revealPrimarySidebar = useCallback(() => {
if (panes.primarySidebarSuppressedByAuxiliary) {
setFileInspectorPreferredVisible(false);
@@ -399,8 +409,8 @@ function AdaptiveWorkspaceLayoutContent(
return true;
}, [togglePrimarySidebar]);
const sidebarCommands = useMemo(
- () => (pathname === "/" ? [] : (["toggleSidebar"] as const)),
- [pathname],
+ () => (primarySidebarPinned ? [] : (["toggleSidebar"] as const)),
+ [primarySidebarPinned],
);
useHardwareKeyboardCommand(sidebarCommands, handleToggleSidebarCommand);
const showAuxiliaryPane = useCallback((role: WorkspaceAuxiliaryPaneRole) => {
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index e6e453e7800..d6819517deb 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -23,11 +23,10 @@ import { use, useCallback, useEffect, useMemo, useRef, useState, type ComponentP
import { View } from "react-native";
import { Split, type SplitHostCommands } from "react-native-screens";
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
-import { isDuoDevice } from "../../lib/device-type";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { WorkspaceTabsProvider } from "../workspace/WorkspaceTabsContext";
import { WorkspaceNativeTabs } from "../workspace/WorkspaceNativeTabs.ios";
-import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
+import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
import { WorkspaceEmptyDetail } from "./WorkspaceEmptyDetail";
@@ -43,7 +42,6 @@ import {
} from "../../native/NativeWorkspaceColumns";
import { V5StackHeader } from "../../native/V5StackHeader.ios";
import type { AppNativeStackNavigationOptions } from "../../native/StackHeader";
-import { dispatchHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
import {
nativeWorkspacePopAction,
projectWorkspaceStack,
@@ -125,7 +123,6 @@ function WorkspaceColumns(
props: ViewProps & { readonly primary: Route; readonly detail: Route[] },
) {
const { layout, panes, togglePrimarySidebar, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
- const deviceType = useDeviceType();
const inspector = use(NativeWorkspaceInspectorContext);
const hostRef = useRef<SplitHostCommands>(null);
const activeDetailKey = props.detail.at(-1)?.key;
@@ -185,7 +182,9 @@ function WorkspaceColumns(
preferredSplitBehavior="tile"
topColumnForCollapsing={compactColumn}
preferredDisplayMode={
- panes.primarySidebarVisible || !activeDetailKey ? "oneBesideSecondary" : "secondaryOnly"
+ panes.primarySidebarVisible || (!layout.usesSplitView && !activeDetailKey)
+ ? "oneBesideSecondary"
+ : "secondaryOnly"
}
displayModeButtonVisibility="never"
presentsWithGesture
@@ -222,21 +221,6 @@ function WorkspaceColumns(
options={{
headerShown: true,
title: "",
- unstable_headerRightItems: () =>
- isDuoDevice(deviceType) && layout.usesSplitView && !panes.primarySidebarVisible
- ? [
- {
- type: "button",
- axisBehavior: "verticalPreferred",
- accessibilityLabel: "Search threads",
- label: "Search threads",
- icon: { type: "sfSymbol", name: "magnifyingglass" },
- onPress: () => {
- dispatchHardwareKeyboardCommand("focusSearch");
- },
- },
- ]
- : [],
unstable_headerLeftItems: () => [
{
type: "button",
diff --git a/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx b/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx
index 2001396a64f..366c2640b4c 100644
--- a/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx
+++ b/apps/mobile/src/features/threads/useThreadHeaderOptions.tsx
@@ -6,7 +6,6 @@ import { useDeviceType } from "../../native/native-layout-metrics";
import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";
-import { dispatchHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
import {
ThreadGitControls,
useThreadGitCenterHeaderItems,
@@ -105,21 +104,6 @@ export function useThreadHeaderOptions(props: {
() => [
...threadCenterHeaderItems,
{ type: "spacing", spacing: 8 },
- ...(layout.usesSplitView && !panes.primarySidebarVisible
- ? [
- withNativeGlassHeaderItem({
- type: "button" as const,
- axisBehavior: "verticalPreferred",
- identifier: "thread-right-search",
- label: "Search threads",
- accessibilityLabel: "Search threads",
- icon: { name: "magnifyingglass", type: "sfSymbol" as const },
- onPress: () => {
- dispatchHardwareKeyboardCommand("focusSearch");
- },
- }),
- ]
- : []),
withNativeGlassHeaderItem({
type: "button" as const,
axisBehavior: "verticalPreferred",
@@ -130,7 +114,7 @@ export function useThreadHeaderOptions(props: {
onPress: () => navigation.navigate("NewTaskSheet", { screen: "NewTask" }),
}),
],
- [navigation, threadCenterHeaderItems, layout.usesSplitView, panes.primarySidebarVisible],
+ [navigation, threadCenterHeaderItems],
);
const options: AppNativeStackNavigationOptions = {
diff --git a/apps/mobile/src/lib/layout.test.ts b/apps/mobile/src/lib/layout.test.ts
index b67e1bca54f..52415e79974 100644
--- a/apps/mobile/src/lib/layout.test.ts
+++ b/apps/mobile/src/lib/layout.test.ts
@@ -9,6 +9,7 @@ import {
deriveThreadFeedInitialContentInset,
deriveThreadWorkLogSizing,
deriveWorkspacePaneLayout,
+ isPrimarySidebarPinned,
SPLIT_LAYOUT_MIN_HEIGHT,
SPLIT_LAYOUT_MIN_WIDTH,
} from "./layout";
@@ -161,6 +162,36 @@ describe("deriveLayout", () => {
});
});
+describe("isPrimarySidebarPinned", () => {
+ it("lets native split columns collapse the sidebar on the workspace root", () => {
+ expect(
+ isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: true, usesSplitView: true }),
+ ).toBe(false);
+ });
+
+ it("keeps compact native roots pinned so search cannot hide the sidebar for a later split", () => {
+ expect(
+ isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: true, usesSplitView: false }),
+ ).toBe(true);
+ });
+
+ it("keeps the JS split layout pinned on the workspace root", () => {
+ expect(
+ isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: false, usesSplitView: true }),
+ ).toBe(true);
+ });
+
+ it("never pins outside the workspace root", () => {
+ expect(
+ isPrimarySidebarPinned({
+ pathname: "/threads/a/b",
+ nativeWorkspace: false,
+ usesSplitView: true,
+ }),
+ ).toBe(false);
+ });
+});
+
describe("deriveWorkspacePaneLayout", () => {
it("keeps the auxiliary pane out of a standard iPad detail column", () => {
const layout = deriveLayout({ width: 1_194, height: 834 });
diff --git a/apps/mobile/src/lib/layout.ts b/apps/mobile/src/lib/layout.ts
index 46995759f22..2fd4acc32e3 100644
--- a/apps/mobile/src/lib/layout.ts
+++ b/apps/mobile/src/lib/layout.ts
@@ -158,6 +158,20 @@ export function alignListPaneToHinge(input: {
return { ...layout, listPaneWidth, listPaneGap: hinge.width };
}
+/**
+ * Whether the workspace root must keep the primary sidebar open. Native split
+ * columns keep a sidebar toggle in the empty detail header, so only they may
+ * collapse it there. Compact layouts stay pinned so a reveal request (such as
+ * focusing search) cannot flip the saved preference for a later split view.
+ */
+export function isPrimarySidebarPinned(input: {
+ readonly pathname: string;
+ readonly nativeWorkspace: boolean;
+ readonly usesSplitView: boolean;
+}): boolean {
+ return input.pathname === "/" && !(input.nativeWorkspace && input.usesSplitView);
+}
+
export function deriveWorkspacePaneLayout(input: {
readonly layout: Layout;
readonly viewportWidth: number;