Skip to content

Commit 53ae488

Browse files
committed
fix(mobile): scale Android menu row height with text
1 parent 680b37c commit 53ae488

3 files changed

Lines changed: 62 additions & 50 deletions

File tree

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

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
import { Box, Column, DropdownMenu, Row, Host, RNHostView, Text } from "@expo/ui/jetpack-compose";
12
import {
2-
Box,
3-
Column,
4-
DropdownMenu,
5-
Row,
6-
Surface,
7-
Host,
8-
RNHostView,
9-
Text,
10-
} from "@expo/ui/jetpack-compose";
11-
import { defaultMinSize, padding, size, weight, width } from "@expo/ui/jetpack-compose/modifiers";
3+
clickable,
4+
defaultMinSize,
5+
padding,
6+
size,
7+
weight,
8+
width,
9+
} from "@expo/ui/jetpack-compose/modifiers";
1210
import { View } from "react-native";
1311

1412
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
@@ -52,7 +50,7 @@ function MenuItem(props: {
5250
}) {
5351
const { action } = props;
5452
const { appearance, themeVariables: colors } = useAppearancePreferences();
55-
const { scale, buttonSize, menuWidth } = useAndroidControlSizing();
53+
const { scale, menuItemHeight, menuWidth } = useAndroidControlSizing();
5654
const body = resolveScaledTextRole("body", appearance.baseFontSize);
5755
const caption = resolveScaledTextRole("caption", appearance.baseFontSize);
5856
const disabled = Boolean(action.attributes?.disabled);
@@ -65,43 +63,43 @@ function MenuItem(props: {
6563
: null;
6664

6765
return (
68-
<Surface color="transparent" enabled={!disabled} onClick={props.onPress}>
69-
<Row
70-
verticalAlignment="center"
71-
horizontalArrangement={{ spacedBy: 12 * scale }}
72-
modifiers={[
73-
width(menuWidth),
74-
defaultMinSize({ minHeight: buttonSize }),
75-
padding(16 * scale, 8 * scale, 16 * scale, 8 * scale),
76-
]}
77-
>
78-
{action.image && isAppSymbolName(action.image) ? (
79-
<MenuIcon name={action.image} disabled={disabled} destructive={destructive} />
80-
) : null}
81-
<Column modifiers={[weight(1)]}>
82-
<Text
83-
style={body}
84-
color={
85-
colors[
86-
disabled
87-
? "--color-foreground-muted"
88-
: destructive
89-
? "--color-danger-foreground"
90-
: "--color-foreground"
91-
]
92-
}
93-
>
94-
{action.title}
66+
// Clickable Surface enforces 48dp even when its content requests a smaller row.
67+
<Row
68+
verticalAlignment="center"
69+
horizontalArrangement={{ spacedBy: 12 * scale }}
70+
modifiers={[
71+
width(menuWidth),
72+
defaultMinSize({ minHeight: menuItemHeight }),
73+
...(disabled ? [] : [clickable(props.onPress)]),
74+
padding(16 * scale, 8 * scale, 16 * scale, 8 * scale),
75+
]}
76+
>
77+
{action.image && isAppSymbolName(action.image) ? (
78+
<MenuIcon name={action.image} disabled={disabled} destructive={destructive} />
79+
) : null}
80+
<Column modifiers={[weight(1)]}>
81+
<Text
82+
style={body}
83+
color={
84+
colors[
85+
disabled
86+
? "--color-foreground-muted"
87+
: destructive
88+
? "--color-danger-foreground"
89+
: "--color-foreground"
90+
]
91+
}
92+
>
93+
{action.title}
94+
</Text>
95+
{action.subtitle ? (
96+
<Text style={caption} color={colors["--color-foreground-muted"]}>
97+
{action.subtitle}
9598
</Text>
96-
{action.subtitle ? (
97-
<Text style={caption} color={colors["--color-foreground-muted"]}>
98-
{action.subtitle}
99-
</Text>
100-
) : null}
101-
</Column>
102-
{trailingIcon ? <MenuIcon name={trailingIcon} disabled={disabled} /> : null}
103-
</Row>
104-
</Surface>
99+
) : null}
100+
</Column>
101+
{trailingIcon ? <MenuIcon name={trailingIcon} disabled={disabled} /> : null}
102+
</Row>
105103
);
106104
}
107105

‎apps/mobile/src/lib/androidControlSizing.test.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,23 @@ describe("Android control sizing", () => {
1414
buttonSize: 48,
1515
fabSize: 56,
1616
menuWidth: 250,
17+
menuItemHeight: 48,
1718
fabClearance: 148,
1819
});
19-
expect(small).toMatchObject({ iconSize: 18, buttonSize: 48, fabSize: 48, menuWidth: 188 });
20-
expect(large).toMatchObject({ iconSize: 30, buttonSize: 60, fabSize: 70, menuWidth: 313 });
20+
expect(small).toMatchObject({
21+
iconSize: 18,
22+
buttonSize: 48,
23+
fabSize: 48,
24+
menuWidth: 188,
25+
menuItemHeight: 36,
26+
});
27+
expect(large).toMatchObject({
28+
iconSize: 30,
29+
buttonSize: 60,
30+
fabSize: 70,
31+
menuWidth: 313,
32+
menuItemHeight: 60,
33+
});
2134
});
2235

2336
it("keeps buttons tappable and both floating actions clear of the list at every text size", () => {

‎apps/mobile/src/lib/androidControlSizing.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DEFAULT_BASE_FONT_SIZE, normalizeBaseFontSize } from "./appearancePreferences";
22

3-
/** Android controls follow the app's text size while retaining a 48dp touch target. */
3+
/** Android controls follow the app's text size; standalone buttons retain a 48dp touch target. */
44
export function resolveAndroidControlSizing(baseFontSize: number) {
55
const scale = normalizeBaseFontSize(baseFontSize) / DEFAULT_BASE_FONT_SIZE;
66
const iconSize = Math.round(24 * scale);
@@ -14,6 +14,7 @@ export function resolveAndroidControlSizing(baseFontSize: number) {
1414
fabSize,
1515
largeFabSize: Math.round(96 * scale),
1616
menuWidth: Math.round(250 * scale),
17+
menuItemHeight: Math.round(48 * scale),
1718
// Two floating actions, their gap, and the space below the lower action.
1819
fabClearance: fabSize * 2 + 36,
1920
};

0 commit comments

Comments
 (0)