Skip to content

Commit 4d4bbf9

Browse files
committed
fix(mobile): cap compose size to preserve navigation width
1 parent 6d291f9 commit 4d4bbf9

4 files changed

Lines changed: 40 additions & 20 deletions

File tree

‎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: 15 additions & 6 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,
@@ -16,7 +16,8 @@ import { FabScrollContext } from "./FabScrollContext";
1616
import { updateFabScroll } from "./fab-scroll";
1717
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
1818
import { WorkspaceTabsContext, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
19-
import { FLOATING_TABS } from "../workspace/floating-workspace-tabs";
19+
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
20+
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
2021
import {
2122
useAppearancePreferences,
2223
useAndroidFloatingTabs,
@@ -30,9 +31,17 @@ export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidH
3031
const [layoutWidth, setLayoutWidth] = useState<number | null>(null);
3132
const { state } = useWorkspaceState();
3233
const [expanded, setExpanded] = useState(true);
33-
const { fabSize } = useAndroidControlSizing();
34+
const { scale, fabSize } = useAndroidControlSizing();
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;
3443
const workspace = useWorkspaceTabs();
35-
const bottomClearance = insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize;
44+
const bottomClearance = insets.bottom + FLOATING_TABS.bottom + FLOATING_TABS.edge + size;
3645
const context = floatingTabsEnabled && workspace ? { ...workspace, bottomClearance } : workspace;
3746
const scrollState = useRef({ anchor: 0, expanded: true });
3847
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
@@ -57,9 +66,9 @@ export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidH
5766
(!props.sidebar || floatingTabsEnabled) &&
5867
state.hasConnections &&
5968
layoutWidth !== null ? (
60-
<NewThreadButton
69+
<ScrollComposeButton
6170
key={`${appearance.baseFontSize}:${fontScale}:${layoutWidth}`}
62-
extended
71+
size={size}
6372
expanded={floatingTabsEnabled ? false : expanded}
6473
onPress={props.onStartNewTask}
6574
className="absolute"

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

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

2222
it.each([
23-
[475, 1, 56],
24-
[411, 1, 56],
25-
[475, 1.25, 70],
26-
[320, 11 / 16, 48],
27-
[320, 1, 56],
28-
[320, 22 / 16, 77],
29-
[300, 22 / 16, 77],
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],
3032
] as const)(
3133
"fills a %sdp row at scale %s beside a %sdp compose button",
32-
(width, scale, fabSize) => {
33-
const metrics = floatingTabsMetrics(4, scale, fabSize, width, true);
34-
expect(metrics.pill + 2 * 16 + 12 + fabSize).toBe(width);
35-
expect(metrics.height).toBe(fabSize);
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);
3639
},
3740
);

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ export function floatingTabsMetrics(
99
fillWidth = false,
1010
) {
1111
const unit = Math.max(1, scale);
12-
const beside = 2 * FLOATING_TABS.edge + FLOATING_TABS.gap + fabSize;
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 =
15+
paneWidth === undefined
16+
? fabSize
17+
: Math.max(48, Math.min(fabSize, (paneWidth - spacing) / (count + 1)));
18+
const beside = spacing + height;
1319
const room = paneWidth === undefined ? count * 60 * unit : paneWidth - beside;
1420
return {
1521
// Reserve the compose slot even while its button is hidden.
1622
pill: Math.max(0, fillWidth ? room : Math.min(count * 72 * unit, room)),
17-
height: fabSize,
23+
height,
1824
row: beside + count * 60 * unit,
1925
};
2026
}

0 commit comments

Comments
 (0)