Skip to content

Commit 5e966bc

Browse files
authored
fix(mobile): keep One UI navigation and Compose on one row (#29203)
1 parent edc37c9 commit 5e966bc

10 files changed

Lines changed: 52 additions & 74 deletions

‎apps/mobile/src/components/ScrollComposeButton.android.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ import { resolveScaledTextRole } from "../lib/appearancePreferences";
1717
export function ScrollComposeButton(props: {
1818
readonly expanded: boolean;
1919
readonly onPress: () => void;
20+
readonly size?: number;
2021
readonly className?: string;
2122
readonly style?: StyleProp<ViewStyle>;
2223
}) {
2324
const { appearance, themeVariables: colors } = useAppearancePreferences();
2425
const typography = resolveScaledTextRole("footnote", appearance.baseFontSize);
25-
const { iconSize, fabSize } = useAndroidControlSizing();
26+
const { iconSize, fabSize: scaledFabSize } = useAndroidControlSizing();
27+
const fabSize = props.size ?? scaledFabSize;
2628
const nativeSize = Math.max(56, fabSize);
2729
const scale = fabSize / nativeSize;
2830
const nativeIconSize = Math.round(iconSize / scale);

‎apps/mobile/src/features/home/AndroidHomeFab.android.tsx‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type NativeSyntheticEvent,
77
} from "react-native";
88
import { useSafeAreaInsets } from "react-native-safe-area-context";
9-
import { NewThreadButton } from "../../components/NewThreadButton";
9+
import { ScrollComposeButton } from "../../components/ScrollComposeButton.android";
1010
import {
1111
androidHomeFabPosition,
1212
type AndroidHomeFabLayout as SharedAndroidHomeFabLayout,
@@ -15,9 +15,9 @@ import { useWorkspaceState } from "../../state/workspace";
1515
import { FabScrollContext } from "./FabScrollContext";
1616
import { updateFabScroll } from "./fab-scroll";
1717
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
18-
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
1918
import { WorkspaceTabsContext, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
2019
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
20+
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
2121
import {
2222
useAppearancePreferences,
2323
useAndroidFloatingTabs,
@@ -32,19 +32,16 @@ export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidH
3232
const { state } = useWorkspaceState();
3333
const [expanded, setExpanded] = useState(true);
3434
const { scale, fabSize } = useAndroidControlSizing();
35-
const tabs = useEnabledNavigationTabs();
36-
const floating = floatingTabsMetrics(
37-
tabs.length + 1,
38-
scale,
39-
fabSize,
40-
props.paneWidth ?? layoutWidth ?? undefined,
41-
);
35+
const enabledTabs = useEnabledNavigationTabs();
36+
const barWidth =
37+
layoutWidth === null
38+
? undefined
39+
: layoutWidth - (Math.max(insets.left, FLOATING_TABS.edge) - FLOATING_TABS.edge);
40+
const size = floatingTabsEnabled
41+
? floatingTabsMetrics(enabledTabs.length + 1, scale, fabSize, barWidth).height
42+
: fabSize;
4243
const workspace = useWorkspaceTabs();
43-
const bottomClearance =
44-
insets.bottom +
45-
FLOATING_TABS.bottom +
46-
FLOATING_TABS.edge +
47-
Math.max(floating.height, floating.fabOffset + fabSize);
44+
const bottomClearance = insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + size;
4845
const context = floatingTabsEnabled && workspace ? { ...workspace, bottomClearance } : workspace;
4946
const scrollState = useRef({ anchor: 0, expanded: true });
5047
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
@@ -69,17 +66,17 @@ export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidH
6966
(!props.sidebar || floatingTabsEnabled) &&
7067
state.hasConnections &&
7168
layoutWidth !== null ? (
72-
<NewThreadButton
69+
<ScrollComposeButton
7370
key={`${appearance.baseFontSize}:${fontScale}:${layoutWidth}`}
74-
extended
71+
size={size}
7572
expanded={floatingTabsEnabled ? false : expanded}
7673
onPress={props.onStartNewTask}
7774
className="absolute"
7875
style={
7976
floatingTabsEnabled
8077
? {
8178
right: FLOATING_TABS.edge,
82-
bottom: insets.bottom + FLOATING_TABS.bottom + floating.fabOffset,
79+
bottom: insets.bottom + FLOATING_TABS.bottom,
8380
}
8481
: androidHomeFabPosition(insets.bottom, props.sidebar)
8582
}

‎apps/mobile/src/features/home/AndroidHomeFab.shared.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export function AndroidHomeFabLayout(props: {
55
readonly children: ReactNode;
66
readonly sidebar?: boolean;
77
readonly disabled?: boolean;
8-
readonly paneWidth?: number;
98
}) {
109
return <>{props.children}</>;
1110
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,6 @@ function AdaptiveWorkspaceLayoutContent(
935935
<AndroidHomeFabLayout
936936
sidebar
937937
disabled={workspacePage}
938-
paneWidth={layout.listPaneWidth}
939938
onStartNewTask={handleStartNewTask}
940939
>
941940
<ThreadNavigationSidebar

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import type { LayoutChangeEvent, TextInputInstance } from "react-native";
2323
import { Platform, StyleSheet, TextInput, View } from "react-native";
2424
import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
2525
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
26-
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
27-
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
26+
import { FLOATING_TABS } from "../workspace/floating-workspace-tabs";
2827
import { useSafeAreaInsets } from "react-native-safe-area-context";
2928
import type { SearchBarCommands } from "react-native-screens";
3029

@@ -152,9 +151,7 @@ function ThreadNavigationSidebarPane(
152151
const drawerColor = materialTheme["--color-drawer"];
153152

154153
const insets = useSafeAreaInsets();
155-
const { fabClearance, scale, fabSize } = useAndroidControlSizing();
156-
const enabledTabs = useEnabledNavigationTabs();
157-
const floatingTabs = floatingTabsMetrics(enabledTabs.length + 1, scale, fabSize, props.width);
154+
const { fabClearance, fabSize } = useAndroidControlSizing();
158155
const projects = useProjects();
159156
const threads = useNavigationThreadShells();
160157
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
@@ -826,9 +823,7 @@ function ThreadNavigationSidebarPane(
826823
paddingBottom:
827824
Platform.OS === "android"
828825
? floatingTabsEnabled
829-
? FLOATING_TABS.bottom +
830-
FLOATING_TABS.edge +
831-
Math.max(floatingTabs.height, floatingTabs.fabOffset + fabSize)
826+
? FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
832827
: Math.max(insets.bottom, 16) + fabClearance - insets.bottom
833828
: 16 + insets.bottom,
834829
paddingTop: Platform.OS === "android" ? 6 : topListInset,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export function AndroidWorkspaceNavigation(props: {
9797
);
9898
// FloatingWorkspaceTabs starts the bar at the left inset, so a cutout narrows the room.
9999
const barWidth =
100-
props.paneWidth ??
101-
window.width - (Math.max(insets.left, FLOATING_TABS.edge) - FLOATING_TABS.edge);
100+
(props.paneWidth ?? window.width) -
101+
(Math.max(insets.left, FLOATING_TABS.edge) - FLOATING_TABS.edge);
102102
const metrics = floatingTabsMetrics(tabs.length, scale, fabSize, barWidth, props.fillWidth);
103103
if (!rail && keyboardVisible) return null;
104104

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
55
import { type ReactNode } from "react";
66
import { useSafeAreaInsets } from "react-native-safe-area-context";
77
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
8-
import { FLOATING_TABS, floatingTabsMetrics } from "./floating-workspace-tabs";
8+
import { FLOATING_TABS } from "./floating-workspace-tabs";
99
import { View } from "react-native";
1010
import { ScreenContent } from "../../components/ui/ScreenContent";
1111
import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
@@ -22,10 +22,9 @@ export function AndroidWorkspaceSidebar(props: {
2222
const workspace = useWorkspaceTabs()!;
2323
const enabled = useEnabledNavigationTabs();
2424
const insets = useSafeAreaInsets();
25-
const { scale, fabSize } = useAndroidControlSizing();
26-
const floating = floatingTabsMetrics(enabled.length + 1, scale, fabSize);
25+
const { fabSize } = useAndroidControlSizing();
2726
const bottomClearance = floatingTabsEnabled
28-
? insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + floating.height
27+
? insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
2928
: 16;
3029
const context = { ...workspace, bottomClearance };
3130
if (enabled.length === 0) return <WorkspaceNoTabs />;

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
33
import { useEnabledNavigationTabs } from "./navigation-tabs";
44
import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
55
import { WorkspaceExtraTab } from "./WorkspaceExtraTab";
6-
import { useWindowDimensions, View } from "react-native";
6+
import { View } from "react-native";
77
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
88
import { NativeStackScreenOptions } from "../../native/StackHeader";
99
import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
@@ -15,7 +15,7 @@ import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
1515
import { PullRequestToolbar } from "../pull-requests/PullRequestToolbar.android";
1616
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
1717
import { AndroidWorkspaceNavigation, FloatingWorkspaceTabs } from "./AndroidWorkspaceNavigation";
18-
import { FLOATING_TABS, floatingTabsMetrics } from "./floating-workspace-tabs";
18+
import { FLOATING_TABS } from "./floating-workspace-tabs";
1919
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
2020
import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
2121
import type { WorkspaceTab } from "./workspace-tabs-state";
@@ -28,21 +28,13 @@ export function WorkspaceRootScreen() {
2828
const workspace = useWorkspaceTabs()!;
2929
const enabled = useEnabledNavigationTabs();
3030
const insets = useSafeAreaInsets();
31-
const { fabClearance, scale, fabSize } = useAndroidControlSizing();
32-
const window = useWindowDimensions();
33-
const floating = floatingTabsMetrics(enabled.length + 1, scale, fabSize, window.width);
31+
const { fabClearance, fabSize } = useAndroidControlSizing();
3432
const context = {
3533
...workspace,
3634
bottomClearance: layout.usesSplitView
3735
? workspace.bottomClearance
3836
: floatingTabsEnabled
39-
? insets.bottom +
40-
FLOATING_TABS.bottom +
41-
FLOATING_TABS.edge +
42-
Math.max(
43-
floating.height,
44-
workspace.state.selectedTab === "threads" ? floating.fabOffset + fabSize : 0,
45-
)
37+
? insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
4638
: workspace.state.selectedTab === "threads"
4739
? fabClearance + 16
4840
: 16,

‎apps/mobile/src/features/workspace/floating-workspace-tabs.test.ts‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@ it.each([
2020
);
2121

2222
it.each([
23-
[475, 1, 56],
24-
[411, 1, 56],
25-
[475, 1.25, 70],
23+
[475, 1, 56, 4, 56],
24+
[411, 1, 56, 4, 56],
25+
[475, 1.25, 70, 4, 70],
26+
[320, 11 / 16, 48, 4, 48],
27+
[320, 1, 56, 4, 55.2],
28+
[320, 22 / 16, 77, 4, 55.2],
29+
[300, 22 / 16, 77, 4, 51.2],
30+
[411, 22 / 16, 77, 4, 73.4],
31+
[320, 22 / 16, 77, 2, 77],
2632
] as const)(
27-
"fills a %sdp cover row at scale %s with a %sdp compose button",
28-
(width, scale, fabSize) => {
29-
const metrics = floatingTabsMetrics(4, scale, fabSize, width, true);
30-
expect(metrics.sharesRow).toBe(true);
31-
expect(metrics.pill + 2 * 16 + 12 + fabSize).toBe(width);
32-
expect(metrics.height).toBe(fabSize);
33+
"fills a %sdp row at scale %s beside a %sdp compose button",
34+
(width, scale, fabSize, count, height) => {
35+
const metrics = floatingTabsMetrics(count, scale, fabSize, width, true);
36+
expect(metrics.pill + 2 * 16 + 12 + metrics.height).toBeCloseTo(width);
37+
expect(metrics.height).toBeCloseTo(height);
38+
expect(metrics.pill / count).toBeGreaterThanOrEqual(metrics.height - 0.001);
3339
},
3440
);
35-
36-
it("stacks compose above a full-width pill when a cover row is too narrow", () => {
37-
const metrics = floatingTabsMetrics(4, 1, 56, 300, true);
38-
expect(metrics.sharesRow).toBe(false);
39-
expect(metrics.pill).toBe(268);
40-
expect(metrics.fabOffset).toBe(68);
41-
});

‎apps/mobile/src/features/workspace/floating-workspace-tabs.ts‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@ export function floatingTabsMetrics(
99
fillWidth = false,
1010
) {
1111
const unit = Math.max(1, scale);
12-
const height = fabSize;
13-
const beside = 2 * FLOATING_TABS.edge + FLOATING_TABS.gap + fabSize;
14-
const row = beside + count * 60 * unit;
15-
const sharesRow = paneWidth === undefined || paneWidth >= row;
16-
const room =
12+
const spacing = 2 * FLOATING_TABS.edge + FLOATING_TABS.gap;
13+
// Share width evenly when space is tight, retaining Android's 48dp touch target.
14+
const height =
1715
paneWidth === undefined
18-
? count * 60 * unit
19-
: sharesRow
20-
? paneWidth - beside
21-
: paneWidth - 2 * FLOATING_TABS.edge;
16+
? fabSize
17+
: Math.max(48, Math.min(fabSize, (paneWidth - spacing) / (count + 1)));
18+
const beside = spacing + height;
19+
const room = paneWidth === undefined ? count * 60 * unit : paneWidth - beside;
2220
return {
2321
// Reserve the compose slot even while its button is hidden.
2422
pill: Math.max(0, fillWidth ? room : Math.min(count * 72 * unit, room)),
2523
height,
26-
row,
27-
sharesRow,
28-
fabOffset: sharesRow ? (height - fabSize) / 2 : height + FLOATING_TABS.gap,
24+
row: beside + count * 60 * unit,
2925
};
3026
}

0 commit comments

Comments
 (0)