Skip to content

Commit 2dd7a97

Browse files
committed
fix(mobile): refine Android control scaling
1 parent df4f696 commit 2dd7a97

20 files changed

Lines changed: 95 additions & 97 deletions

‎apps/mobile/src/components/AndroidAnchoredMenu.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type AndroidAnchoredMenuProps = {
5555
* menus use the native popup for placement, animation and dismissal.
5656
*/
5757
export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
58-
const { scale, menuWidth } = useAndroidControlSizing();
58+
const { scale, menuWidth: desiredMenuWidth } = useAndroidControlSizing();
5959
const [anchor, setAnchor] = useState<AnchorSnapshot | null>(null);
6060
const [path, setPath] = useState<readonly MenuAction[]>([]);
6161
// Height of the modal's root view, in the modal's own coordinate space.
@@ -69,6 +69,10 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
6969
// are converted into this frame, so the menu lands correctly no matter
7070
// where the portal host sits (status bar, keyboard resize, etc.).
7171
const [overlay, setOverlay] = useState<OverlayFrame | null>(null);
72+
const menuWidth =
73+
overlay === null
74+
? desiredMenuWidth
75+
: Math.min(desiredMenuWidth, Math.max(0, overlay.width - 2 * SCREEN_MARGIN));
7276
const anchorRef = useRef<View>(null);
7377
const overlayRef = useRef<View>(null);
7478

@@ -199,6 +203,7 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
199203
{!placeable || local === null ? null : !anchor.keyboardWasVisible ? (
200204
<MaterialMenuPopup
201205
anchor={local}
206+
menuWidth={menuWidth}
202207
actions={levelActions}
203208
title={props.title}
204209
parent={parent}
@@ -227,14 +232,15 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
227232
active editor; the first item tap must act, not just
228233
dismiss the keyboard. */}
229234
<ScrollView
230-
contentContainerStyle={{ paddingVertical: 8 * scale }}
235+
contentContainerStyle={{ paddingVertical: 7 * scale }}
231236
bounces={false}
232237
keyboardShouldPersistTaps="always"
233238
showsVerticalScrollIndicator={false}
234239
>
235240
<MaterialMenuPopup
236241
inline
237242
anchor={local}
243+
menuWidth={menuWidth}
238244
actions={levelActions}
239245
title={props.title}
240246
parent={parent}

‎apps/mobile/src/components/AndroidScreenHeader.tsx‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { useState, type ReactNode } from "react";
22
import { View } from "react-native";
3-
import { useSafeAreaInsets } from "react-native-safe-area-context";
43

54
import type { AppSymbolName } from "./AppSymbol";
65
import { AppText as Text } from "./AppText";
76
import { cn } from "../lib/cn";
87
import { MaterialIconButton } from "./MaterialIconButton";
98
import { AndroidAnchoredMenu } from "./AndroidAnchoredMenu";
109
import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
11-
import { useMaterialToolbarHeight } from "./useMaterialToolbarHeight";
12-
import { useAndroidControlSizing } from "./useAndroidControlSizing";
10+
import { useMaterialToolbarLayout } from "./useMaterialToolbarLayout";
1311

1412
export interface AndroidHeaderAction {
1513
readonly accessibilityLabel: string;
@@ -39,11 +37,11 @@ export function AndroidScreenHeader(props: {
3937
readonly embedded?: boolean;
4038
readonly hideBottomBorder?: boolean;
4139
}) {
42-
const insets = useSafeAreaInsets();
4340
const titleTypography = useScaledTextRole("title");
4441
const subtitleTypography = useScaledTextRole("label");
45-
const materialToolbarHeight = useMaterialToolbarHeight();
46-
const { scale } = useAndroidControlSizing();
42+
const { height: materialToolbarHeight, ...headerPadding } = useMaterialToolbarLayout(
43+
props.embedded,
44+
);
4745
const [headerWidth, setHeaderWidth] = useState(0);
4846
const actions = props.actions ?? [];
4947
const directCount = actions.length > 2 ? (headerWidth >= 600 ? 3 : 1) : actions.length;
@@ -55,8 +53,7 @@ export function AndroidScreenHeader(props: {
5553
onLayout={(event) => setHeaderWidth(event.nativeEvent.layout.width)}
5654
className="border-b border-header-border bg-header px-2"
5755
style={{
58-
paddingTop: props.embedded ? 8 * scale : Math.max(insets.top, 12 * scale),
59-
paddingBottom: 8 * scale,
56+
...headerPadding,
6057
borderBottomWidth: props.hideBottomBorder ? 0 : undefined,
6158
}}
6259
>

‎apps/mobile/src/components/CompactBrandTitle.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function CompactBrandTitle(
3636
accessible
3737
role="heading"
3838
className="flex-row items-center gap-1.5"
39-
style={[{ marginLeft: titleOffset }, Platform.OS === "android" && { gap: 6 * scale }]}
39+
style={[{ marginLeft: titleOffset }, Platform.OS === "android" && { gap: 5.25 * scale }]}
4040
>
4141
<T3Wordmark colorClassName="accent-icon" height={Math.round(15 * scale)} />
4242
<Text
@@ -50,7 +50,7 @@ export function CompactBrandTitle(
5050
className="rounded-full bg-subtle px-1.5 py-0.5"
5151
style={
5252
Platform.OS === "android"
53-
? { paddingHorizontal: 6 * scale, paddingVertical: 2 * scale }
53+
? { paddingHorizontal: 5.25 * scale, paddingVertical: 1.75 * scale }
5454
: undefined
5555
}
5656
>

‎apps/mobile/src/components/ComposerToolbar.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ export function ComposerInlineControl(props: {
5858
{props.renderIcon ? (
5959
<View
6060
className="size-4 shrink-0 items-center justify-center"
61-
style={
62-
Platform.OS === "android" ? { width: smallIconSize, height: smallIconSize } : undefined
63-
}
61+
style={Platform.OS === "android" ? { width: 14 * scale, height: 14 * scale } : undefined}
6462
>
6563
{props.renderIcon(smallIconSize)}
6664
</View>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export function MaterialFloatingActionButton(props: {
7878
pointerEvents="none"
7979
className="absolute inset-y-0 justify-center"
8080
style={
81-
props.variant === "extended" && props.expanded !== false
82-
? { left: 16 }
83-
: { left: 0, right: 0, alignItems: "center" }
81+
props.variant === "extended" ? { left: 16 } : { left: 0, right: 0, alignItems: "center" }
8482
}
8583
>
8684
<SymbolView

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ function MenuIcon(props: {
4848
/** Native popup positioned at the original trigger, outside virtualized rows. */
4949
export function MaterialMenuPopup(props: MaterialMenuPopupProps) {
5050
const { appearance, themeAppearance, themeVariables: colors } = useAppearancePreferences();
51-
const { scale, menuWidth, menuItemHeight } = useAndroidControlSizing();
51+
const { scale, menuItemHeight } = useAndroidControlSizing();
5252
const body = resolveScaledTextRole("body", appearance.baseFontSize);
5353
const caption = resolveScaledTextRole("caption", appearance.baseFontSize);
5454
const foreground = colors["--color-foreground"];
5555
const muted = colors["--color-foreground-muted"];
5656
// A fixed native item height clips wrapped labels; a minimum lets each row grow.
57-
const itemModifiers = [width(menuWidth), defaultMinSize({ minHeight: menuItemHeight })];
57+
const itemModifiers = [width(props.menuWidth), defaultMinSize({ minHeight: menuItemHeight })];
5858
const items = (
5959
<>
6060
{props.parent ? (
@@ -63,15 +63,15 @@ export function MaterialMenuPopup(props: MaterialMenuPopupProps) {
6363
<MenuIcon name="arrow.left" />
6464
</DropdownMenuItem.LeadingIcon>
6565
<DropdownMenuItem.Text>
66-
<Text color={foreground} style={body}>
66+
<Text color={foreground} style={{ typography: "bodyLarge", ...body }}>
6767
{props.parent.title}
6868
</Text>
6969
</DropdownMenuItem.Text>
7070
</DropdownMenuItem>
7171
) : props.title ? (
7272
<Text
7373
color={muted}
74-
style={caption}
74+
style={{ typography: "bodySmall", ...caption }}
7575
modifiers={[padding(16 * scale, 8 * scale, 16 * scale, 8 * scale)]}
7676
>
7777
{props.title}
@@ -96,7 +96,7 @@ export function MaterialMenuPopup(props: MaterialMenuPopupProps) {
9696
<DropdownMenuItem.Text>
9797
<Column>
9898
<Text
99-
style={body}
99+
style={{ typography: "bodyLarge", ...body }}
100100
color={
101101
action.attributes?.disabled
102102
? muted
@@ -108,7 +108,7 @@ export function MaterialMenuPopup(props: MaterialMenuPopupProps) {
108108
{action.title}
109109
</Text>
110110
{action.subtitle ? (
111-
<Text color={muted} style={caption}>
111+
<Text color={muted} style={{ typography: "bodySmall", ...caption }}>
112112
{action.subtitle}
113113
</Text>
114114
) : null}
@@ -133,7 +133,7 @@ export function MaterialMenuPopup(props: MaterialMenuPopupProps) {
133133
colorScheme={themeAppearance}
134134
ignoreSafeAreaKeyboardInsets
135135
matchContents
136-
style={{ width: menuWidth }}
136+
style={{ width: props.menuWidth }}
137137
>
138138
<Column>{items}</Column>
139139
</Host>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { MenuAction } from "@react-native-menu/menu";
22

33
export interface MaterialMenuPopupProps {
4+
readonly menuWidth: number;
45
readonly anchor: {
56
readonly x: number;
67
readonly y: number;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function MaterialScrollComposeButton(props: {
2929
const nativeIconSize = Math.round(iconSize / scale);
3030
const [buttonWidth, setButtonWidth] = useState(nativeSize);
3131
const rememberWidth = useCallback(({ width }: { width: number }) => {
32-
setButtonWidth(width);
32+
setButtonWidth((previous) => Math.max(previous, width));
3333
}, []);
3434
return (
3535
<View

‎apps/mobile/src/components/MaterialSearchField.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ export function MaterialSearchField({
1919
readonly value: string;
2020
readonly onChangeText: (value: string) => void;
2121
}) {
22-
const { scale, buttonSize, mediumIconSize } = useAndroidControlSizing();
22+
const { scale, mediumIconSize } = useAndroidControlSizing();
2323
return (
2424
<View
2525
className="min-w-0 flex-1 flex-row items-center rounded-full border border-input-border bg-input"
26-
style={{ minHeight: buttonSize, gap: 8 * scale, paddingHorizontal: 12 * scale }}
26+
style={{
27+
minHeight: Math.max(48, 42 * scale),
28+
gap: 7 * scale,
29+
paddingHorizontal: 10.5 * scale,
30+
}}
2731
>
2832
<SymbolView
2933
name="magnifyingglass"
@@ -43,7 +47,7 @@ export function MaterialSearchField({
4347
cursorColorClassName="accent-focus"
4448
selectionHandleColorClassName="accent-focus"
4549
className="min-w-0 flex-1 font-sans text-base text-foreground"
46-
style={{ paddingVertical: 8 * scale }}
50+
style={{ paddingVertical: 7 * scale }}
4751
value={value}
4852
onChangeText={onChangeText}
4953
/>

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useRef, useState } from "react";
22
import { BackHandler, Keyboard, Pressable, TextInput, View } from "react-native";
3-
import { useSafeAreaInsets } from "react-native-safe-area-context";
3+
import { useMaterialToolbarLayout } from "./useMaterialToolbarLayout";
44
import { NativeStackScreenOptions } from "../native/StackHeader";
55
import { AndroidWorkspaceSidebarButton } from "../features/layout/workspace-sidebar-toolbar";
66
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
@@ -15,7 +15,7 @@ import { useAndroidControlSizing } from "./useAndroidControlSizing";
1515

1616
export function ScreenHeader(props: ScreenHeaderProps) {
1717
const { search } = props;
18-
const insets = useSafeAreaInsets();
18+
const { paddingTop, paddingBottom } = useMaterialToolbarLayout();
1919
const { scale, buttonSize, iconSize, smallIconSize } = useAndroidControlSizing();
2020
const { themeVariables } = useAppearancePreferences();
2121
const inputRef = useRef<TextInput>(null);
@@ -85,8 +85,8 @@ export function ScreenHeader(props: ScreenHeaderProps) {
8585
<View
8686
className="border-b border-header-border bg-header px-3"
8787
style={{
88-
paddingTop: Math.max(insets.top, 12 * scale),
89-
paddingBottom: 10 * scale,
88+
paddingTop,
89+
paddingBottom: 8.75 * scale,
9090
borderBottomWidth: 0,
9191
}}
9292
>
@@ -111,10 +111,10 @@ export function ScreenHeader(props: ScreenHeaderProps) {
111111
<View
112112
className="flex-1 flex-row items-center bg-input"
113113
style={{
114-
minHeight: Math.max(44, 44 * scale),
115-
gap: 10 * scale,
116-
borderRadius: 16 * scale,
117-
paddingHorizontal: 14 * scale,
114+
minHeight: Math.max(48, 38.5 * scale),
115+
gap: 8.75 * scale,
116+
borderRadius: 14 * scale,
117+
paddingHorizontal: 12.25 * scale,
118118
}}
119119
>
120120
<SymbolView
@@ -135,7 +135,7 @@ export function ScreenHeader(props: ScreenHeaderProps) {
135135
}
136136
placeholderTextColorClassName="accent-placeholder"
137137
className="flex-1 text-base font-sans text-header-foreground"
138-
style={{ paddingVertical: 8 * scale }}
138+
style={{ paddingVertical: 7 * scale }}
139139
/>
140140
</View>
141141
{menuView}
@@ -194,10 +194,7 @@ export function ScreenHeader(props: ScreenHeaderProps) {
194194
{header}
195195
</View>
196196
{searching ? (
197-
<View
198-
className="absolute inset-0 bg-header px-2"
199-
style={{ paddingTop: Math.max(insets.top, 12 * scale), paddingBottom: 8 * scale }}
200-
>
197+
<View className="absolute inset-0 bg-header px-2" style={{ paddingTop, paddingBottom }}>
201198
<View className="flex-1 flex-row items-center gap-1">
202199
<ScreenHeaderButton
203200
accessibilityLabel={search.closeAccessibilityLabel ?? "Close search"}

0 commit comments

Comments
 (0)