Skip to content

Commit eb1db29

Browse files
fix(mobile): the Android split slides as one strip, so sidebar and detail pane always fill the width (#26328)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 7ccd02c commit eb1db29

6 files changed

Lines changed: 204 additions & 40 deletions

File tree

‎apps/mobile/src/components/ui/SegmentedControl.shared.tsx‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { useState } from "react";
22
import { I18nManager, Platform, Pressable, View } from "react-native";
3-
import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated";
3+
import Animated, {
4+
useAnimatedStyle,
5+
useDerivedValue,
6+
useReducedMotion,
7+
withTiming,
8+
} from "react-native-reanimated";
49

510
import { segmentedControlColors } from "./segmentedControlColors";
611
import { AppText } from "./AppText";
@@ -18,10 +23,14 @@ export function SegmentedControl<Value extends string | number>(
1823
const reduceMotion = useReducedMotion();
1924
const selectedIndex = props.options.findIndex((option) => option.value === props.selected);
2025
const segmentWidth = props.options.length ? Math.max(0, width - 6) / props.options.length : 0;
21-
const selectionOffset = selectedIndex * segmentWidth * (I18nManager.isRTL ? -1 : 1);
26+
const direction = I18nManager.isRTL ? -1 : 1;
27+
// The index animates, not the offset, so a resize moves the selection without sliding it.
28+
const selectedPosition = useDerivedValue(() =>
29+
withTiming(selectedIndex, { duration: reduceMotion ? 0 : 160 }),
30+
);
2231
const selectionStyle = useAnimatedStyle(() => ({
2332
width: segmentWidth,
24-
transform: [{ translateX: withTiming(selectionOffset, { duration: reduceMotion ? 0 : 160 }) }],
33+
transform: [{ translateX: selectedPosition.value * segmentWidth * direction }],
2534
}));
2635
const { trackColor, selectedColor, selectedTextColor, mutedColor } = segmentedControlColors(
2736
colors,

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 161 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area
88
import { AdaptiveWorkspaceContext, useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
99
import { threadSelectionDeferral } from "./deferred-navigation";
1010
import { uuidv4 } from "../../lib/uuid";
11+
import { useToolbarLayout } from "../../components/ui/useToolbarLayout";
1112
import { EnvironmentId, ThreadId, type SidebarProjectGroupingMode } from "@t3tools/contracts";
1213
import { useAtomValue } from "@effect/atom-react";
1314
import { NavigationContext, NavigationRouteContext, useNavigation } from "@react-navigation/native";
@@ -29,7 +30,11 @@ import {
2930
useWindowDimensions,
3031
View,
3132
} from "react-native";
32-
import { KeyboardController, useKeyboardContext } from "react-native-keyboard-controller";
33+
import {
34+
KeyboardController,
35+
useKeyboardContext,
36+
useKeyboardState,
37+
} from "react-native-keyboard-controller";
3338
import Animated, {
3439
runOnJS,
3540
useAnimatedStyle,
@@ -312,15 +317,17 @@ function AdaptiveWorkspaceLayoutContent(
312317
!sidebarFloats &&
313318
(composerEditing || composerKeyboardActive);
314319
const keyboardProgress = useKeyboardContext().reanimated.progress;
320+
// From the moment the keyboard starts showing until it has fully hidden. The detail pane keeps
321+
// the sidebar's room for that whole span, so on the way back the sidebar pushes the wide pane
322+
// aside instead of arriving beside one that already shrank.
323+
const keyboardOnScreen = useKeyboardState((state) => state.isVisible);
315324
const shouldRenderNavigationRail =
316325
Platform.OS === "android" && baseLayout.usesSplitView && !floatingTabsEnabled;
317326
const enabledTabs = useEnabledNavigationTabs();
318327
const { scale, fabSize } = useAndroidControlSizing();
319328
const floatingTabs = floatingTabsMetrics(enabledTabs.length + 1, scale, fabSize);
320-
const navigationRailWidth =
321-
shouldRenderNavigationRail && (showPrimarySidebar || workspacePage)
322-
? ANDROID_WORKSPACE_RAIL_WIDTH
323-
: 0;
329+
// The rail stays whether or not the sidebar shows; only the list pane comes and goes.
330+
const navigationRailWidth = shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0;
324331
const [hinge, setHinge] = useState<VerticalHinge | null>(null);
325332
const [windowHinge, setWindowHinge] = useState<VerticalHinge | null>(null);
326333
const handleHingeChange = (next: VerticalHinge | null, nextWindow: VerticalHinge | null) => {
@@ -655,9 +662,58 @@ function AdaptiveWorkspaceLayoutContent(
655662
: 0;
656663
// Android's split content is a rounded card: keep it off the screen edge like the list card.
657664
const contentEndGap = Platform.OS === "android" && layout.usesSplitView ? 4 : 0;
658-
const contentTargetWidth = layout.usesSplitView
659-
? Math.max(0, panes.contentPaneWidth - inspectorColumnTargetWidth - contentEndGap)
660-
: null;
665+
// Android's split is one strip: a sidebar slot of fixed width, then the detail pane. The
666+
// sidebar never resizes; both slide by one offset, so together they always fill the width.
667+
// The pane spans the sidebar's room too unless the sidebar has finished arriving: a sidebar on
668+
// its way in pushes the wide pane past the edge, and one leaving uncovers it.
669+
const stripSidebar =
670+
Platform.OS === "android" &&
671+
layout.usesSplitView &&
672+
layout.listPaneWidth !== null &&
673+
!workspacePage &&
674+
!sidebarFloats;
675+
const sidebarSlotWidth = (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0);
676+
const sidebarTargetOpen = keyboardHoldsSidebar ? sidebarRestsOpen : panes.primarySidebarVisible;
677+
const [sidebarMotion, setSidebarMotion] = useState({
678+
strip: stripSidebar,
679+
settledOpen: sidebarTargetOpen,
680+
});
681+
if (sidebarMotion.strip !== stripSidebar) {
682+
// Entering or leaving the strip (a workspace page, a fold) snaps the sidebar into place.
683+
setSidebarMotion({ strip: stripSidebar, settledOpen: sidebarTargetOpen });
684+
} else if (sidebarMotion.settledOpen && !sidebarTargetOpen) {
685+
setSidebarMotion({ strip: stripSidebar, settledOpen: false });
686+
}
687+
const sidebarSettledOpen =
688+
sidebarMotion.strip === stripSidebar ? sidebarMotion.settledOpen : sidebarTargetOpen;
689+
const markSidebarSettled = (open: boolean) =>
690+
setSidebarMotion((current) =>
691+
current.settledOpen === open ? current : { ...current, settledOpen: open },
692+
);
693+
// The keyboard covers the sidebar's share from the moment it starts showing until it is gone.
694+
const contentSpansSidebar =
695+
stripSidebar &&
696+
(!sidebarSettledOpen || !sidebarTargetOpen || (keyboardHoldsSidebar && keyboardOnScreen));
697+
const contentTargetWidth = !layout.usesSplitView
698+
? null
699+
: Math.max(
700+
0,
701+
(contentSpansSidebar ? width : panes.contentPaneWidth) -
702+
inspectorColumnTargetWidth -
703+
contentEndGap,
704+
);
705+
// A workspace page (Usage) lays out at this width even while hidden behind another tab, so
706+
// opening it widens nothing it measured.
707+
const workspacePageWidth = !layout.usesSplitView
708+
? null
709+
: workspacePage
710+
? contentTargetWidth
711+
: Math.max(
712+
0,
713+
viewportWidth -
714+
(shouldRenderNavigationRail ? ANDROID_WORKSPACE_RAIL_WIDTH : 0) -
715+
contentEndGap,
716+
);
661717
const [listPaneSizing, setListPaneSizing] = useState({
662718
viewportWidth,
663719
workspacePage,
@@ -773,7 +829,10 @@ function AdaptiveWorkspaceLayoutContent(
773829
// The content beside it already took its final width when the page closed.
774830
renderedSidebarWidth.set(
775831
withTiming(targetWidth, snap ? { duration: 0 } : WORKSPACE_PANE_TIMING, (finished) => {
776-
if (finished && Platform.OS === "android") runOnJS(settleListPane)(listPaneRevision);
832+
if (finished && Platform.OS === "android") {
833+
runOnJS(settleListPane)(listPaneRevision);
834+
runOnJS(markSidebarSettled)(targetWidth > 0);
835+
}
777836
}),
778837
);
779838
}, [
@@ -789,6 +848,7 @@ function AdaptiveWorkspaceLayoutContent(
789848
renderedSidebarWidth,
790849
renderedRailWidth,
791850
settleListPane,
851+
markSidebarSettled,
792852
listPaneRevision,
793853
workspacePage,
794854
]);
@@ -819,24 +879,45 @@ function AdaptiveWorkspaceLayoutContent(
819879
// Showing or hiding the sidebar clips a fixed-width list. A hinge resize instead tracks the
820880
// animated edge, so the header actions slide with it rather than jumping or being covered.
821881
const listPaneGap = layout.listPaneGap ?? 0;
882+
const keyboardSidebarRest = sidebarRestsOpen
883+
? (layout.listPaneWidth ?? 0) + (layout.listPaneGap ?? 0)
884+
: 0;
822885
const drawnSidebarWidth = useDerivedValue(
823886
() => renderedSidebarWidth.value * (keyboardHold.value ? 1 - keyboardProgress.value : 1),
824887
);
825888
const listPaneAnimatedStyle = useAnimatedStyle(() => ({
826889
width: Math.min(
827890
listPaneCeiling,
828-
Math.max(listPaneFloor, drawnSidebarWidth.value - listPaneGap),
891+
Math.max(
892+
listPaneFloor,
893+
(stripSidebar ? sidebarSlotWidth : drawnSidebarWidth.value) - listPaneGap,
894+
),
829895
),
830-
// Following the keyboard, the list rides the sidebar's edge like the content beside it,
831-
// instead of being uncovered in place.
832-
transform: [{ translateX: drawnSidebarWidth.value - renderedSidebarWidth.value }],
833896
}));
897+
// How far the strip has slid: 0 with the sidebar shown, minus its width with it gone.
898+
const stripOffset = useDerivedValue(() =>
899+
stripSidebar ? drawnSidebarWidth.value - sidebarSlotWidth : 0,
900+
);
834901
const sidebarAnimatedStyle = useAnimatedStyle(() => ({
835902
// Fading a UIKit glass ancestor can leave remounted header effects missing.
836903
opacity:
837-
Platform.OS === "ios" || floatingTabsEnabled ? 1 : Math.min(1, drawnSidebarWidth.value / 80),
838-
width: drawnSidebarWidth.value,
904+
stripSidebar || Platform.OS === "ios" || floatingTabsEnabled
905+
? 1
906+
: Math.min(1, drawnSidebarWidth.value / 80),
907+
width: stripSidebar ? sidebarSlotWidth : drawnSidebarWidth.value,
908+
flexShrink: stripSidebar ? 0 : 1,
909+
transform: [{ translateX: stripOffset.value }],
839910
}));
911+
// The content keeps the width React laid it out at and rides the sidebar's edge, so a keyboard
912+
// transition relays nothing out per frame, the way UIKit animates the iOS split view.
913+
// Until React commits the wider layout, the detail card continues past its right edge, so the
914+
// strip the narrower column leaves shows the card instead of the row behind it.
915+
const contentOverhangStyle = useAnimatedStyle(() => ({
916+
opacity: keyboardHold.value && keyboardProgress.value > 0 ? 1 : 0,
917+
}));
918+
const threadHeader = useToolbarLayout(false, composerKeyboardActive);
919+
const threadHeaderHeight =
920+
threadHeader.paddingTop + threadHeader.height + threadHeader.paddingBottom;
840921

841922
// Clip the navigator at its settled width so native headers and markdown reflow only once per pane toggle.
842923
const renderedInspectorWidth = useSharedValue(inspectorColumnTargetWidth);
@@ -851,13 +932,33 @@ function AdaptiveWorkspaceLayoutContent(
851932
);
852933
// Android can resize the native row before React removes its split panes on a fold.
853934
const androidSplit = Platform.OS === "android" && layout.usesSplitView;
854-
const androidContentSlotStyle = useAnimatedStyle(() => ({
855-
width: androidSplit ? renderedContentWidth.value : ("100%" as const),
856-
}));
935+
// In the strip the column itself slides with the sidebar: Android only delivers touches inside a
936+
// parent's bounds, so content may not slide out of its column.
937+
const androidContentSlotStyle = useAnimatedStyle(() =>
938+
!androidSplit
939+
? { width: "100%" as const }
940+
: stripSidebar
941+
? {
942+
// Wide enough for the pane at either width; the margin gives the sidebar's share
943+
// back to the row, so a column after it stays put while the strip slides.
944+
width: Math.max(
945+
0,
946+
viewportWidth - renderedRailWidth.value - renderedInspectorWidth.value,
947+
),
948+
marginRight: -sidebarSlotWidth,
949+
transform: [{ translateX: stripOffset.value }],
950+
}
951+
: { width: renderedContentWidth.value },
952+
);
857953
// While the sidebar animates, clip the settled navigator instead of reflowing its text every frame.
954+
// In the strip it lifts entirely: the content outgrows its column, and a cap that follows
955+
// React's width would clip the wider layout for the frame it lands.
858956
const androidNavigatorLimit = useAnimatedStyle(() => ({
859-
maxWidth:
860-
androidSplit && contentTargetWidth !== null && renderedContentWidth.value < contentTargetWidth
957+
maxWidth: stripSidebar
958+
? viewportWidth
959+
: androidSplit &&
960+
contentTargetWidth !== null &&
961+
renderedContentWidth.value < contentTargetWidth
861962
? contentTargetWidth
862963
: ("100%" as const),
863964
}));
@@ -902,8 +1003,10 @@ function AdaptiveWorkspaceLayoutContent(
9021003
nativeInspectorColumnWidth(viewportWidth, width / viewportWidth) / viewportWidth,
9031004
),
9041005
composerKeyboardActive,
1006+
keyboardHoldsSidebar,
9051007
setComposerEditing,
9061008
sidebarByOrientation,
1009+
workspacePageWidth,
9071010
};
9081011

9091012
const inspectorSheet = (
@@ -1009,18 +1112,15 @@ function AdaptiveWorkspaceLayoutContent(
10091112
<Animated.View
10101113
collapsable={false}
10111114
style={[
1012-
// While the keyboard moves the sidebar, the content tracks its edge every frame so
1013-
// the two land together; a settled width would jump when React commits mid-slide.
1014-
keyboardHoldsSidebar
1015-
? { flex: 1, marginRight: contentEndGap }
1016-
: contentTargetWidth !== null
1017-
? {
1018-
flex: 1,
1019-
width: contentTargetWidth,
1020-
alignSelf: contentAnchor.end ? "flex-end" : "flex-start",
1021-
marginRight: contentAnchor.end ? contentEndGap : 0,
1022-
}
1023-
: { flex: 1 },
1115+
contentTargetWidth !== null
1116+
? {
1117+
flex: 1,
1118+
width: contentTargetWidth,
1119+
// The strip's column is wider than the pane; the pane sits at its start.
1120+
alignSelf: contentAnchor.end && !stripSidebar ? "flex-end" : "flex-start",
1121+
marginRight: contentAnchor.end && !stripSidebar ? contentEndGap : 0,
1122+
}
1123+
: { flex: 1 },
10241124
Platform.OS === "android" ? androidNavigatorLimit : undefined,
10251125
]}
10261126
>
@@ -1068,6 +1168,35 @@ function AdaptiveWorkspaceLayoutContent(
10681168
</WorkspaceSettledContentWidthContext>
10691169
</WorkspaceContentWidthContext>
10701170
</Animated.View>
1171+
{keyboardHoldsSidebar && contentTargetWidth !== null ? (
1172+
<>
1173+
<Animated.View
1174+
pointerEvents="none"
1175+
className="absolute top-0 bg-header"
1176+
style={[
1177+
{
1178+
left: contentTargetWidth,
1179+
width: keyboardSidebarRest + contentEndGap,
1180+
height: threadHeaderHeight,
1181+
},
1182+
contentOverhangStyle,
1183+
]}
1184+
/>
1185+
<Animated.View
1186+
pointerEvents="none"
1187+
className="absolute bottom-0 rounded-tr-[28px] bg-thread-canvas"
1188+
style={[
1189+
{
1190+
// Starts under the card's rounded corner so the two read as one card.
1191+
left: contentTargetWidth - 28,
1192+
width: keyboardSidebarRest + 28,
1193+
top: threadHeaderHeight,
1194+
},
1195+
contentOverhangStyle,
1196+
]}
1197+
/>
1198+
</>
1199+
) : null}
10711200
</Animated.View>
10721201
{sidebarFloats ? (
10731202
<Animated.View

‎apps/mobile/src/features/layout/adaptive-workspace-context.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ interface AdaptiveWorkspaceContextValue {
5858
* (the unfolded Duo). The native split switches between them as a rotation starts.
5959
*/
6060
readonly sidebarByOrientation: { readonly landscape: boolean; readonly portrait: boolean } | null;
61+
/** Android split: the composer's keyboard slides the sidebar, from focus until it lets go. */
62+
readonly keyboardHoldsSidebar?: boolean;
63+
/** Android split: the width a workspace page (Usage) opens at; null without columns. */
64+
readonly workspacePageWidth?: number | null;
6165
/** The thread composer reports its focus so the layout can make room for typing. */
6266
readonly setComposerEditing: (editing: boolean) => void;
6367
}

‎apps/mobile/src/features/usage/UsageRouteScreen.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
3737
import { SegmentedControl } from "../../components/ui/SegmentedControl";
3838
import { useReduceMotionEnabled } from "../../lib/appState";
3939
import { AppText as Text } from "../../components/ui/AppText";
40+
import { useWorkspaceSettledContentWidth } from "../layout/workspace-content-width";
4041
import { ProviderIcon } from "../../components/ProviderIcon";
4142
import { cn } from "../../lib/cn";
4243
import { SettingsScreen } from "../settings/components/SettingsScreen";
@@ -97,7 +98,9 @@ function UsageScreen(props: {
9798
}
9899
const { view } = selection;
99100
const setView = (view: UsageView) => setSelection({ params: props.tabParam, view });
100-
const [width, setWidth] = useState(0);
101+
const [measuredWidth, setWidth] = useState(0);
102+
// A workspace pane knows its width in the render that resizes it; measuring lags a frame.
103+
const width = useWorkspaceSettledContentWidth() ?? measuredWidth;
101104
const wide = width >= WIDE_WIDTH;
102105
const [windowSelection, setWindowSelection] = useState(() => ({
103106
days: 30,

‎apps/mobile/src/features/workspace/AndroidWorkspaceNavigation.android.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function AndroidWorkspaceNavigation(props: {
8181
const toolbar = useToolbarLayout();
8282
const connectionState = useWorkspaceConnectionState();
8383
const keyboardVisible = useSoftKeyboardShowing();
84-
const { layout } = useAdaptiveWorkspaceLayout();
84+
const { layout, keyboardHoldsSidebar } = useAdaptiveWorkspaceLayout();
8585
const { themeAppearance, themeVariables: colors } = useAppearancePreferences();
8686
const { scale, fabSize } = useAndroidControlSizing();
8787
const window = useWindowDimensions();
@@ -102,7 +102,8 @@ export function AndroidWorkspaceNavigation(props: {
102102
(props.paneWidth ?? window.width) -
103103
(Math.max(insets.left, FLOATING_TABS.edge) - FLOATING_TABS.edge);
104104
const metrics = floatingTabsMetrics(tabs.length, scale, fabSize, barWidth, props.fillWidth);
105-
if (!rail && keyboardVisible) return null;
105+
// The composer's keyboard slides the sidebar away with the bar on it; other keyboards don't.
106+
if (!rail && keyboardVisible && !keyboardHoldsSidebar) return null;
106107

107108
return (
108109
<View

0 commit comments

Comments
 (0)