Skip to content
TypeScript

fix(mobile): the Android split slides as one strip, so sidebar and detail pane always fill the width (#26328)

Julius Marmingeeb1db29e54f8
diff --git a/apps/mobile/src/components/ui/SegmentedControl.shared.tsx b/apps/mobile/src/components/ui/SegmentedControl.shared.tsx
index 9eac685a8ca..d24e3747d48 100644
--- a/apps/mobile/src/components/ui/SegmentedControl.shared.tsx
+++ b/apps/mobile/src/components/ui/SegmentedControl.shared.tsx
@@ -1,6 +1,11 @@
import { useState } from "react";
import { I18nManager, Platform, Pressable, View } from "react-native";
-import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated";
+import Animated, {
+ useAnimatedStyle,
+ useDerivedValue,
+ useReducedMotion,
+ withTiming,
+} from "react-native-reanimated";
import { segmentedControlColors } from "./segmentedControlColors";
import { AppText } from "./AppText";
@@ -18,10 +23,14 @@ export function SegmentedControl<Value extends string | number>(
const reduceMotion = useReducedMotion();
const selectedIndex = props.options.findIndex((option) => option.value === props.selected);
const segmentWidth = props.options.length ? Math.max(0, width - 6) / props.options.length : 0;
- const selectionOffset = selectedIndex * segmentWidth * (I18nManager.isRTL ? -1 : 1);
+ const direction = I18nManager.isRTL ? -1 : 1;
+ // The index animates, not the offset, so a resize moves the selection without sliding it.
+ const selectedPosition = useDerivedValue(() =>
+ withTiming(selectedIndex, { duration: reduceMotion ? 0 : 160 }),
+ );
const selectionStyle = useAnimatedStyle(() => ({
width: segmentWidth,
- transform: [{ translateX: withTiming(selectionOffset, { duration: reduceMotion ? 0 : 160 }) }],
+ transform: [{ translateX: selectedPosition.value * segmentWidth * direction }],
}));
const { trackColor, selectedColor, selectedTextColor, mutedColor } = segmentedControlColors(
colors,
diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
index 5cdbcfe7fbf..ed71919e736 100644
--- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
+++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx
@@ -8,6 +8,7 @@ import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area
import { AdaptiveWorkspaceContext, useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
import { threadSelectionDeferral } from "./deferred-navigation";
import { uuidv4 } from "../../lib/uuid";
+import { useToolbarLayout } from "../../components/ui/useToolbarLayout";
import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
@@ -29,7 +30,11 @@ import {
useWindowDimensions,
View,
} from "react-native";
-import { KeyboardController, useKeyboardContext } from "react-native-keyboard-controller";
+import {
+ KeyboardController,
+ useKeyboardContext,
+ useKeyboardState,
+} from "react-native-keyboard-controller";
import Animated, {
runOnJS,
useAnimatedStyle,
@@ -312,15 +317,17 @@ function AdaptiveWorkspaceLayoutContent(
!sidebarFloats &&
(composerEditing || composerKeyboardActive);
const keyboardProgress = useKeyboardContext().reanimated.progress;
+ // From the moment the keyboard starts showing until it has fully hidden. The detail pane keeps
+ // the sidebar's room for that whole span, so on the way back the sidebar pushes the wide pane
+ // aside instead of arriving beside one that already shrank.
+ const keyboardOnScreen = useKeyboardState((state) => state.isVisible);
const shouldRenderNavigationRail =
Platform.OS === "android" && baseLayout.usesSplitView && !floatingTabsEnabled;
const enabledTabs = useEnabledNavigationTabs();
const { scale, fabSize } = useAndroidControlSizing();
const floatingTabs = floatingTabsMetrics(enabledTabs.length + 1, scale, fabSize);
- const navigationRailWidth =
- shouldRenderNavigationRail && (showPrimarySidebar || workspacePage)
- ? ANDROID_WORKSPACE_RAIL_WIDTH
- : 0;
+ // The rail stays whether or not the sidebar shows; only the list pane comes and goes.
+ const navigationRailWidth = shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0;
const [hinge, setHinge] = useState<VerticalHinge | null>(null);
const [windowHinge, setWindowHinge] = useState<VerticalHinge | null>(null);
const handleHingeChange = (next: VerticalHinge | null, nextWindow: VerticalHinge | null) => {
@@ -655,9 +662,58 @@ function AdaptiveWorkspaceLayoutContent(
: 0;
// Android's split content is a rounded card: keep it off the screen edge like the list card.
const contentEndGap = Platform.OS === "android" && layout.usesSplitView ? 4 : 0;
- const contentTargetWidth = layout.usesSplitView
- ? Math.max(0, panes.contentPaneWidth - inspectorColumnTargetWidth - contentEndGap)
- : null;
+ // Android's split is one strip: a sidebar slot of fixed width, then the detail pane. The
+ // sidebar never resizes; both slide by one offset, so together they always fill the width.
+ // The pane spans the sidebar's room too unless the sidebar has finished arriving: a sidebar on
+ // its way in pushes the wide pane past the edge, and one leaving uncovers it.
+ const stripSidebar =
+ Platform.OS === "android" &&
+ layout.usesSplitView &&
+ layout.listPaneWidth !== null &&
+ !workspacePage &&
+ !sidebarFloats;
+ const sidebarSlotWidth = (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0);
+ const sidebarTargetOpen = keyboardHoldsSidebar ? sidebarRestsOpen : panes.primarySidebarVisible;
+ const [sidebarMotion, setSidebarMotion] = useState({
+ strip: stripSidebar,
+ settledOpen: sidebarTargetOpen,
+ });
+ if (sidebarMotion.strip !== stripSidebar) {
+ // Entering or leaving the strip (a workspace page, a fold) snaps the sidebar into place.
+ setSidebarMotion({ strip: stripSidebar, settledOpen: sidebarTargetOpen });
+ } else if (sidebarMotion.settledOpen && !sidebarTargetOpen) {
+ setSidebarMotion({ strip: stripSidebar, settledOpen: false });
+ }
+ const sidebarSettledOpen =
+ sidebarMotion.strip === stripSidebar ? sidebarMotion.settledOpen : sidebarTargetOpen;
+ const markSidebarSettled = (open: boolean) =>
+ setSidebarMotion((current) =>
+ current.settledOpen === open ? current : { ...current, settledOpen: open },
+ );
+ // The keyboard covers the sidebar's share from the moment it starts showing until it is gone.
+ const contentSpansSidebar =
+ stripSidebar &&
+ (!sidebarSettledOpen || !sidebarTargetOpen || (keyboardHoldsSidebar && keyboardOnScreen));
+ const contentTargetWidth = !layout.usesSplitView
+ ? null
+ : Math.max(
+ 0,
+ (contentSpansSidebar ? width : panes.contentPaneWidth) -
+ inspectorColumnTargetWidth -
+ contentEndGap,
+ );
+ // A workspace page (Usage) lays out at this width even while hidden behind another tab, so
+ // opening it widens nothing it measured.
+ const workspacePageWidth = !layout.usesSplitView
+ ? null
+ : workspacePage
+ ? contentTargetWidth
+ : Math.max(
+ 0,
+ viewportWidth -
+ (shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0) -
+ contentEndGap,
+ );
const [listPaneSizing, setListPaneSizing] = useState({
viewportWidth,
workspacePage,
@@ -773,7 +829,10 @@ function AdaptiveWorkspaceLayoutContent(
// The content beside it already took its final width when the page closed.
renderedSidebarWidth.set(
withTiming(targetWidth, snap ? { duration: 0 } : WORKSPACE_PANE_TIMING, (finished) => {
- if (finished && Platform.OS === "android") runOnJS(settleListPane)(listPaneRevision);
+ if (finished && Platform.OS === "android") {
+ runOnJS(settleListPane)(listPaneRevision);
+ runOnJS(markSidebarSettled)(targetWidth > 0);
+ }
}),
);
}, [
@@ -789,6 +848,7 @@ function AdaptiveWorkspaceLayoutContent(
renderedSidebarWidth,
renderedRailWidth,
settleListPane,
+ markSidebarSettled,
listPaneRevision,
workspacePage,
]);
@@ -819,24 +879,45 @@ function AdaptiveWorkspaceLayoutContent(
// Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
// animated edge, so the header actions slide with it rather than jumping or being covered.
const listPaneGap = layout.listPaneGap ?? 0;
+ const keyboardSidebarRest = sidebarRestsOpen
+ ? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
+ : 0;
const drawnSidebarWidth = useDerivedValue(
() => renderedSidebarWidth.value * (keyboardHold.value ? 1 - keyboardProgress.value : 1),
);
const listPaneAnimatedStyle = useAnimatedStyle(() => ({
width: Math.min(
listPaneCeiling,
- Math.max(listPaneFloor, drawnSidebarWidth.value - listPaneGap),
+ Math.max(
+ listPaneFloor,
+ (stripSidebar ? sidebarSlotWidth : drawnSidebarWidth.value) - listPaneGap,
+ ),
),
- // Following the keyboard, the list rides the sidebar's edge like the content beside it,
- // instead of being uncovered in place.
- transform: [{ translateX: drawnSidebarWidth.value - renderedSidebarWidth.value }],
}));
+ // How far the strip has slid: 0 with the sidebar shown, minus its width with it gone.
+ const stripOffset = useDerivedValue(() =>
+ stripSidebar ? drawnSidebarWidth.value - sidebarSlotWidth : 0,
+ );
const sidebarAnimatedStyle = useAnimatedStyle(() => ({
// Fading a UIKit glass ancestor can leave remounted header effects missing.
opacity:
- Platform.OS === "ios" || floatingTabsEnabled ? 1 : Math.min(1, drawnSidebarWidth.value / 80),
- width: drawnSidebarWidth.value,
+ stripSidebar || Platform.OS === "ios" || floatingTabsEnabled
+ ? 1
+ : Math.min(1, drawnSidebarWidth.value / 80),
+ width: stripSidebar ? sidebarSlotWidth : drawnSidebarWidth.value,
+ flexShrink: stripSidebar ? 0 : 1,
+ transform: [{ translateX: stripOffset.value }],
}));
+ // The content keeps the width React laid it out at and rides the sidebar's edge, so a keyboard
+ // transition relays nothing out per frame, the way UIKit animates the iOS split view.
+ // Until React commits the wider layout, the detail card continues past its right edge, so the
+ // strip the narrower column leaves shows the card instead of the row behind it.
+ const contentOverhangStyle = useAnimatedStyle(() => ({
+ opacity: keyboardHold.value && keyboardProgress.value > 0 ? 1 : 0,
+ }));
+ const threadHeader = useToolbarLayout(false, composerKeyboardActive);
+ const threadHeaderHeight =
+ threadHeader.paddingTop + threadHeader.height + threadHeader.paddingBottom;
// Clip the navigator at its settled width so native headers and markdown reflow only once per pane toggle.
const renderedInspectorWidth = useSharedValue(inspectorColumnTargetWidth);
@@ -851,13 +932,33 @@ function AdaptiveWorkspaceLayoutContent(
);
// Android can resize the native row before React removes its split panes on a fold.
const androidSplit = Platform.OS === "android" && layout.usesSplitView;
- const androidContentSlotStyle = useAnimatedStyle(() => ({
- width: androidSplit ? renderedContentWidth.value : ("100%" as const),
- }));
+ // In the strip the column itself slides with the sidebar: Android only delivers touches inside a
+ // parent's bounds, so content may not slide out of its column.
+ const androidContentSlotStyle = useAnimatedStyle(() =>
+ !androidSplit
+ ? { width: "100%" as const }
+ : stripSidebar
+ ? {
+ // Wide enough for the pane at either width; the margin gives the sidebar's share
+ // back to the row, so a column after it stays put while the strip slides.
+ width: Math.max(
+ 0,
+ viewportWidth - renderedRailWidth.value - renderedInspectorWidth.value,
+ ),
+ marginRight: -sidebarSlotWidth,
+ transform: [{ translateX: stripOffset.value }],
+ }
+ : { width: renderedContentWidth.value },
+ );
// While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
+ // In the strip it lifts entirely: the content outgrows its column, and a cap that follows
+ // React's width would clip the wider layout for the frame it lands.
const androidNavigatorLimit = useAnimatedStyle(() => ({
- maxWidth:
- androidSplit && contentTargetWidth !== null && renderedContentWidth.value < contentTargetWidth
+ maxWidth: stripSidebar
+ ? viewportWidth
+ : androidSplit &&
+ contentTargetWidth !== null &&
+ renderedContentWidth.value < contentTargetWidth
? contentTargetWidth
: ("100%" as const),
}));
@@ -902,8 +1003,10 @@ function AdaptiveWorkspaceLayoutContent(
nativeInspectorColumnWidth(viewportWidth, width / viewportWidth) / viewportWidth,
),
composerKeyboardActive,
+ keyboardHoldsSidebar,
setComposerEditing,
sidebarByOrientation,
+ workspacePageWidth,
};
const inspectorSheet = (
@@ -1009,18 +1112,15 @@ function AdaptiveWorkspaceLayoutContent(
<Animated.View
collapsable={false}
style={[
- // While the keyboard moves the sidebar, the content tracks its edge every frame so
- // the two land together; a settled width would jump when React commits mid-slide.
- keyboardHoldsSidebar
- ? { flex: 1, marginRight: contentEndGap }
- : contentTargetWidth !== null
- ? {
- flex: 1,
- width: contentTargetWidth,
- alignSelf: contentAnchor.end ? "flex-end" : "flex-start",
- marginRight: contentAnchor.end ? contentEndGap : 0,
- }
- : { flex: 1 },
+ contentTargetWidth !== null
+ ? {
+ flex: 1,
+ width: contentTargetWidth,
+ // The strip's column is wider than the pane; the pane sits at its start.
+ alignSelf: contentAnchor.end && !stripSidebar ? "flex-end" : "flex-start",
+ marginRight: contentAnchor.end && !stripSidebar ? contentEndGap : 0,
+ }
+ : { flex: 1 },
Platform.OS === "android" ? androidNavigatorLimit : undefined,
]}
>
@@ -1068,6 +1168,35 @@ function AdaptiveWorkspaceLayoutContent(
</WorkspaceSettledContentWidthContext>
</WorkspaceContentWidthContext>
</Animated.View>
+ {keyboardHoldsSidebar && contentTargetWidth !== null ? (
+ <>
+ <Animated.View
+ pointerEvents="none"
+ className="absolute top-0 bg-header"
+ style={[
+ {
+ left: contentTargetWidth,
+ width: keyboardSidebarRest + contentEndGap,
+ height: threadHeaderHeight,
+ },
+ contentOverhangStyle,
+ ]}
+ />
+ <Animated.View
+ pointerEvents="none"
+ className="absolute bottom-0 rounded-tr-[28px] bg-thread-canvas"
+ style={[
+ {
+ // Starts under the card's rounded corner so the two read as one card.
+ left: contentTargetWidth - 28,
+ width: keyboardSidebarRest + 28,
+ top: threadHeaderHeight,
+ },
+ contentOverhangStyle,
+ ]}
+ />
+ </>
+ ) : null}
</Animated.View>
{sidebarFloats ? (
<Animated.View
diff --git a/apps/mobile/src/features/layout/adaptive-workspace-context.ts b/apps/mobile/src/features/layout/adaptive-workspace-context.ts
index f917dab5064..10025141007 100644
--- a/apps/mobile/src/features/layout/adaptive-workspace-context.ts
+++ b/apps/mobile/src/features/layout/adaptive-workspace-context.ts
@@ -58,6 +58,10 @@ interface AdaptiveWorkspaceContextValue {
* (the unfolded Duo). The native split switches between them as a rotation starts.
*/
readonly sidebarByOrientation: { readonly landscape: boolean; readonly portrait: boolean } | null;
+ /** Android split: the composer's keyboard slides the sidebar, from focus until it lets go. */
+ readonly keyboardHoldsSidebar?: boolean;
+ /** Android split: the width a workspace page (Usage) opens at; null without columns. */
+ readonly workspacePageWidth?: number | null;
/** The thread composer reports its focus so the layout can make room for typing. */
readonly setComposerEditing: (editing: boolean) => void;
}
diff --git a/apps/mobile/src/features/usage/UsageRouteScreen.tsx b/apps/mobile/src/features/usage/UsageRouteScreen.tsx
index aa0f8045398..f21b46bc9ff 100644
--- a/apps/mobile/src/features/usage/UsageRouteScreen.tsx
+++ b/apps/mobile/src/features/usage/UsageRouteScreen.tsx
@@ -37,6 +37,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { SegmentedControl } from "../../components/ui/SegmentedControl";
import { useReduceMotionEnabled } from "../../lib/appState";
import { AppText as Text } from "../../components/ui/AppText";
+import { useWorkspaceSettledContentWidth } from "../layout/workspace-content-width";
import { ProviderIcon } from "../../components/ProviderIcon";
import { cn } from "../../lib/cn";
import { SettingsScreen } from "../settings/components/SettingsScreen";
@@ -97,7 +98,9 @@ function UsageScreen(props: {
}
const { view } = selection;
const setView = (view: UsageView) => setSelection({ params: props.tabParam, view });
- const [width, setWidth] = useState(0);
+ const [measuredWidth, setWidth] = useState(0);
+ // A workspace pane knows its width in the render that resizes it; measuring lags a frame.
+ const width = useWorkspaceSettledContentWidth() ?? measuredWidth;
const wide = width >= WIDE_WIDTH;
const [windowSelection, setWindowSelection] = useState(() => ({
days: 30,
diff --git a/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx b/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx
index 51720288def..292a5465060 100644
--- a/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx
+++ b/apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx
@@ -81,7 +81,7 @@ export function AndroidWorkspaceNavigation(props: {
const toolbar = useToolbarLayout();
const connectionState = useWorkspaceConnectionState();
const keyboardVisible = useSoftKeyboardShowing();
- const { layout } = useAdaptiveWorkspaceLayout();
+ const { layout, keyboardHoldsSidebar } = useAdaptiveWorkspaceLayout();
const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
const { scale, fabSize } = useAndroidControlSizing();
const window = useWindowDimensions();
@@ -102,7 +102,8 @@ export function AndroidWorkspaceNavigation(props: {
(props.paneWidth ?? window.width) -
(Math.max(insets.left, FLOATING_TABS.edge) - FLOATING_TABS.edge);
const metrics = floatingTabsMetrics(tabs.length, scale, fabSize, barWidth, props.fillWidth);
- if (!rail && keyboardVisible) return null;
+ // The composer's keyboard slides the sidebar away with the bar on it; other keyboards don't.
+ if (!rail && keyboardVisible && !keyboardHoldsSidebar) return null;
return (
<View
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
index f2503f41b46..ca27287dcf7 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx
@@ -3,6 +3,7 @@ import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
import { useEnabledNavigationTabs } from "./navigation-tabs";
import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
import { WorkspaceExtraTab } from "./WorkspaceExtraTab";
+import type { ReactNode } from "react";
import { View } from "react-native";
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -14,6 +15,7 @@ import { HomeRouteScreen } from "../home/HomeRouteScreen";
import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
import { PullRequestToolbar } from "../pull-requests/PullRequestToolbar.android";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
+import { WorkspaceSettledContentWidthContext } from "../layout/workspace-content-width";
import { AndroidWorkspaceNavigation, FloatingWorkspaceTabs } from "./AndroidWorkspaceNavigation";
import { FLOATING_TABS } from "./floating-workspace-tabs";
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
@@ -31,7 +33,7 @@ export function WorkspaceRootScreen() {
function WorkspaceRoot() {
const floatingTabsEnabled = useAndroidFloatingTabs();
- const { layout, startNewTask } = useAdaptiveWorkspaceLayout();
+ const { layout, startNewTask, workspacePageWidth } = useAdaptiveWorkspaceLayout();
const workspace = useWorkspaceTabs()!;
const enabled = useEnabledNavigationTabs();
const insets = useSafeAreaInsets();
@@ -80,7 +82,9 @@ function WorkspaceRoot() {
tab === "threads" ? (
<HomeRouteScreen />
) : tab !== "pullRequests" ? (
- <WorkspaceExtraTab tab={tab} />
+ <WorkspacePageFrame width={workspacePageWidth ?? null}>
+ <WorkspaceExtraTab tab={tab} />
+ </WorkspacePageFrame>
) : layout.usesSplitView ? (
<>
<NativeStackScreenOptions options={{ headerShown: false }} />
@@ -117,3 +121,17 @@ function WorkspaceRoot() {
</WorkspaceTabsContext>
);
}
+
+// Hidden, the page sits in the narrower pane beside the list; laying it out at the width it opens
+// at keeps measured bars and breakpoints from catching up a frame after it appears.
+function WorkspacePageFrame(props: {
+ readonly width: number | null;
+ readonly children: ReactNode;
+}) {
+ if (props.width === null) return props.children;
+ return (
+ <WorkspaceSettledContentWidthContext value={props.width}>
+ <View style={{ flex: 1, width: props.width }}>{props.children}</View>
+ </WorkspaceSettledContentWidthContext>
+ );
+}