Skip to content
TypeScript

fix(mobile): keep iPad workspace columns aligned while resizing (#24182)

Alexc14cda15b972
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index ffcab2aa310..5ef3fd3bf28 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -230,8 +230,8 @@ function AdaptiveWorkspaceLayoutContent(
// re-renders on any layout state change, and the inspector registration then loops: each
// re-register re-renders its screen, which hands over a new inspector renderer.
const baseLayout = useMemo(
- () => deriveLayout({ width: viewportWidth, height, nativeMetrics }),
- [height, viewportWidth, nativeMetrics],
+ () => deriveLayout({ width: viewportWidth, height, nativeMetrics, nativeWorkspace }),
+ [height, viewportWidth, nativeMetrics, nativeWorkspace],
);
const primarySidebarPinned = isPrimarySidebarPinned({
pathname,
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index 6af2cda6dca..7e4a4057f21 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -256,6 +256,7 @@ function WorkspaceColumns(
ref={hostRef}
testID="adaptive-workspace-layout"
preferredSplitBehavior="tile"
+ primaryBackgroundStyle={deviceType === "pad" ? "none" : "default"}
topColumnForCollapsing={compactColumn}
onCollapse={() => {
collapsed.current = true;
diff --git a/apps/mobile/src/lib/layout.test.ts b/apps/mobile/src/lib/layout.test.ts
index 0552d550391..8babd468199 100644
--- a/apps/mobile/src/lib/layout.test.ts
+++ b/apps/mobile/src/lib/layout.test.ts
@@ -49,6 +49,41 @@ describe("deriveThreadFeedInitialContentInset", () => {
});
});
+describe("native workspace sizing", () => {
+ it("keeps the detail mounted in a narrow iPad window while UIKit still has two columns", () => {
+ const nativeMetrics = {
+ width: 715,
+ height: 1013.5,
+ hasHinge: false,
+ horizontalSizeClass: "regular" as const,
+ verticalBarEdge: "none" as const,
+ safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
+ reservedRegions: [],
+ };
+ expect(deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true })).toMatchObject({
+ usesSplitView: true,
+ listPaneWidth: 280,
+ });
+ });
+
+ it.each([
+ { width: 600, horizontalSizeClass: "regular" as const, split: true },
+ { width: 599, horizontalSizeClass: "regular" as const, split: false },
+ { width: 715, horizontalSizeClass: "compact" as const, split: false },
+ ])("respects UIKit collapse and native column minimums: %j", ({ split, ...size }) => {
+ const nativeMetrics = {
+ ...size,
+ height: 800,
+ verticalBarEdge: "none" as const,
+ safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
+ reservedRegions: [],
+ };
+ expect(
+ deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true }).usesSplitView,
+ ).toBe(split);
+ });
+});
+
describe("isPrimarySidebarPinned", () => {
// regression: #20406 sidebar toggle works on iPad and iPhone Duo
it("keeps compact native roots pinned so search cannot hide the sidebar for a later split", () => {
diff --git a/apps/mobile/src/lib/layout.ts b/apps/mobile/src/lib/layout.ts
index 111bb2b40fc..5cff4509a51 100644
--- a/apps/mobile/src/lib/layout.ts
+++ b/apps/mobile/src/lib/layout.ts
@@ -90,12 +90,13 @@ export function deriveLayout(input: {
readonly width: number;
readonly height: number;
readonly nativeMetrics?: NativeLayoutMetrics | null;
+ readonly nativeWorkspace?: boolean;
}): Layout {
const { width, height } = input;
const metrics = input.nativeMetrics;
const usableWidth = width - (metrics?.safeArea.left ?? 0) - (metrics?.safeArea.right ?? 0);
- // UIKit's size class supports the shorter Duo inner display. Geometry remains
- // a floor so a narrow multitasking window cannot squeeze both columns.
+ // UIKit retains split columns below the generic tablet breakpoint. Native
+ // columns follow its size class while reserving room for both column minimums.
// Unfolded in portrait, the inner display reports neither a side bar nor a
// fold, only its hinge.
const hasDuoGeometry =
@@ -103,11 +104,12 @@ export function deriveLayout(input: {
(metrics.hasHinge === true ||
metrics.verticalBarEdge !== "none" ||
metrics.reservedRegions.some((region) => region.kind === "division"));
- const wideEnoughForSplit = hasDuoGeometry
- ? metrics.horizontalSizeClass === "regular" &&
- usableWidth >= SPLIT_SIDEBAR_MIN_WIDTH + 320 &&
- height >= 400
- : width >= SPLIT_LAYOUT_MIN_WIDTH && height >= SPLIT_LAYOUT_MIN_HEIGHT;
+ const wideEnoughForSplit =
+ metrics && (input.nativeWorkspace || hasDuoGeometry)
+ ? metrics.horizontalSizeClass === "regular" &&
+ usableWidth >= SPLIT_SIDEBAR_MIN_WIDTH + 320 &&
+ (input.nativeWorkspace || height >= 400)
+ : width >= SPLIT_LAYOUT_MIN_WIDTH && height >= SPLIT_LAYOUT_MIN_HEIGHT;
if (!wideEnoughForSplit) {
return {