Skip to content

Commit 6375070

Browse files
fix(mobile): feature screens use the components/ui menu, dialog and search primitives (#33193)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent eb97d82 commit 6375070

18 files changed

Lines changed: 561 additions & 1051 deletions

‎apps/mobile/src/components/ui/AppBar.android.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import { ScreenHeaderButton } from "./ScreenHeaderButton.android";
1313
import { Menu } from "./Menu";
1414
import { Button } from "./Button";
1515
import { SearchField } from "./SearchField";
16-
import { androidHeaderMenuActions, findHeaderMenuAction } from "./headerMenu.android";
16+
import { findAppBarMenuItem, menuActionsFromAppBarItems } from "./menuActionItems";
1717
import type { AppBarMenuItem, AppBarProps, AppBarSearch } from "./AppBar.types";
1818
import { useHasWorkspaceAppBar, WorkspaceAppBar } from "./WorkspaceAppBar.android";
1919

2020
function selectMenuItem(items: ReadonlyArray<AppBarMenuItem>, id: string) {
21-
const action = findHeaderMenuAction(items, id);
21+
const action = findAppBarMenuItem(items, id);
2222
if (action && !action.disabled) action.onPress();
2323
}
2424

@@ -134,7 +134,7 @@ function AppBarView(props: AppBarProps & { readonly searchState?: SearchState })
134134
? {
135135
accessibilityLabel: menu.title,
136136
customized: icon?.endsWith(".fill") === true,
137-
actions: androidHeaderMenuActions(menu.items),
137+
actions: menuActionsFromAppBarItems(menu.items),
138138
onSelect: (id) => selectMenuItem(menu.items, id),
139139
}
140140
: undefined
@@ -146,7 +146,7 @@ function AppBarView(props: AppBarProps & { readonly searchState?: SearchState })
146146
const menuView = props.menus?.map((menu) => (
147147
<Menu
148148
key={menu.title}
149-
actions={androidHeaderMenuActions(menu.items)}
149+
actions={menuActionsFromAppBarItems(menu.items)}
150150
isAnchoredToRight
151151
title={menu.status ?? menu.title}
152152
onPressAction={({ nativeEvent }) => selectMenuItem(menu.items, nativeEvent.event)}

‎apps/mobile/src/components/ui/headerMenu.android.ts‎

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,3 @@
1-
import type { MenuAction } from "@react-native-menu/menu";
2-
import type { AppBarMenuItem } from "./AppBar.types";
3-
4-
export function androidHeaderMenuActions(items: ReadonlyArray<AppBarMenuItem>): MenuAction[] {
5-
return items.flatMap((item): MenuAction[] =>
6-
"items" in item
7-
? item.inline && !item.title
8-
? androidHeaderMenuActions(item.items)
9-
: [
10-
{
11-
id: item.id,
12-
title: item.title ?? "",
13-
image: item.icon,
14-
subactions: androidHeaderMenuActions(item.items),
15-
},
16-
]
17-
: [
18-
{
19-
id: item.id,
20-
title: item.title,
21-
subtitle: item.subtitle,
22-
image: item.icon,
23-
imageColor: item.iconColor,
24-
state: item.selected ? "on" : undefined,
25-
attributes:
26-
item.disabled || item.destructive
27-
? { disabled: item.disabled, destructive: item.destructive }
28-
: undefined,
29-
},
30-
],
31-
);
32-
}
33-
34-
export function findHeaderMenuAction(
35-
items: ReadonlyArray<AppBarMenuItem>,
36-
id: string,
37-
): Extract<AppBarMenuItem, { readonly onPress: () => void }> | undefined {
38-
for (const item of items) {
39-
if ("items" in item) {
40-
const action = findHeaderMenuAction(item.items, id);
41-
if (action) return action;
42-
} else if (item.id === id) {
43-
return item;
44-
}
45-
}
46-
return undefined;
47-
}
48-
491
export function splitAndroidHeaderActions<Action extends { readonly overflowOnly?: boolean }>(
502
actions: ReadonlyArray<Action>,
513
wide: boolean,

‎apps/mobile/src/components/ui/menuActionItems.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { MenuAction } from "@react-native-menu/menu";
22
import { describe, expect, it, vi } from "vite-plus/test";
33

4-
import { androidHeaderMenuActions, findHeaderMenuAction } from "./headerMenu.android";
5-
import { appBarMenuItemsFromActions } from "./menuActionItems";
4+
import {
5+
appBarMenuItemsFromActions,
6+
findAppBarMenuItem,
7+
menuActionsFromAppBarItems,
8+
} from "./menuActionItems";
69

710
describe("appBarMenuItemsFromActions", () => {
8-
it("round-trips a filter menu through AppBar items back to Android actions", () => {
11+
it("round-trips a filter menu through AppBar items back to menu actions", () => {
912
const actions: MenuAction[] = [
1013
{
1114
id: "labels",
@@ -26,7 +29,7 @@ describe("appBarMenuItemsFromActions", () => {
2629

2730
const items = appBarMenuItemsFromActions(actions, onSelect);
2831

29-
expect(androidHeaderMenuActions(items)).toEqual([
32+
expect(menuActionsFromAppBarItems(items)).toEqual([
3033
{
3134
id: "labels",
3235
title: "Labels",
@@ -53,7 +56,10 @@ describe("appBarMenuItemsFromActions", () => {
5356
],
5457
},
5558
]);
56-
findHeaderMenuAction(items, "label:docs")?.onPress();
59+
findAppBarMenuItem(items, "label:docs")?.onPress();
5760
expect(onSelect).toHaveBeenCalledWith("label:docs");
61+
expect(
62+
menuActionsFromAppBarItems([{ id: "devices", title: "Devices", inline: true, items: [] }]),
63+
).toMatchObject([{ id: "devices", title: "Devices", displayInline: true }]);
5864
});
5965
});

‎apps/mobile/src/components/ui/menuActionItems.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,50 @@ export function appBarMenuItemsFromActions(
2727
};
2828
});
2929
}
30+
31+
/** Adapts `AppBar` menu items to a `Menu`'s actions; `findAppBarMenuItem` resolves a selection. */
32+
export function menuActionsFromAppBarItems(items: ReadonlyArray<AppBarMenuItem>): MenuAction[] {
33+
return items.flatMap((item): MenuAction[] =>
34+
"items" in item
35+
? item.inline && !item.title
36+
? menuActionsFromAppBarItems(item.items)
37+
: [
38+
{
39+
id: item.id,
40+
title: item.title ?? "",
41+
image: item.icon,
42+
displayInline: item.inline,
43+
subactions: menuActionsFromAppBarItems(item.items),
44+
},
45+
]
46+
: [
47+
{
48+
id: item.id,
49+
title: item.title,
50+
subtitle: item.subtitle,
51+
image: item.icon,
52+
imageColor: item.iconColor,
53+
state: item.selected ? "on" : undefined,
54+
attributes:
55+
item.disabled || item.destructive
56+
? { disabled: item.disabled, destructive: item.destructive }
57+
: undefined,
58+
},
59+
],
60+
);
61+
}
62+
63+
export function findAppBarMenuItem(
64+
items: ReadonlyArray<AppBarMenuItem>,
65+
id: string,
66+
): Extract<AppBarMenuItem, { readonly onPress: () => void }> | undefined {
67+
for (const item of items) {
68+
if ("items" in item) {
69+
const action = findAppBarMenuItem(item.items, id);
70+
if (action) return action;
71+
} else if (item.id === id) {
72+
return item;
73+
}
74+
}
75+
return undefined;
76+
}

‎apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ import { Pressable, StatusBar, View } from "react-native";
1616
import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
1717
import { useSafeAreaInsets } from "react-native-safe-area-context";
1818

19-
import { SymbolView } from "../../components/ui/AppSymbol";
2019
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
2120
import { AppText } from "../../components/ui/AppText";
2221
import { ControlPill } from "../../components/ui/ControlPill";
2322
import { Menu } from "../../components/ui/Menu";
2423
import { GlassSurface } from "../../components/ui/GlassSurface";
2524
import {
26-
androidHeaderMenuActions,
27-
findHeaderMenuAction,
28-
} from "../../components/ui/headerMenu.android";
25+
findAppBarMenuItem,
26+
menuActionsFromAppBarItems,
27+
} from "../../components/ui/menuActionItems";
2928
import { AppBar } from "../../components/ui/AppBar";
3029
import { useBarOverlap } from "../../components/ui/useBarInset";
3130
import type { AppBarMenuItem } from "../../components/ui/AppBar.types";
@@ -376,21 +375,15 @@ export function DevicePreviewScreen({
376375
function DeviceOptionsMenu({ items }: { readonly items: ReadonlyArray<AppBarMenuItem> }) {
377376
return (
378377
<Menu
379-
actions={androidHeaderMenuActions(items)}
378+
actions={menuActionsFromAppBarItems(items)}
380379
isAnchoredToRight
381380
title="Device options"
382381
onPressAction={({ nativeEvent }) => {
383-
const action = findHeaderMenuAction(items, nativeEvent.event);
382+
const action = findAppBarMenuItem(items, nativeEvent.event);
384383
if (action && !action.disabled) action.onPress();
385384
}}
386385
>
387-
<Pressable
388-
accessibilityLabel="Device options"
389-
accessibilityRole="button"
390-
className="size-11 items-center justify-center rounded-full bg-subtle"
391-
>
392-
<SymbolView name="ellipsis" size={18} tintColorClassName="accent-icon" />
393-
</Pressable>
386+
<ControlPill icon="ellipsis" accessibilityLabel="Device options" />
394387
</Menu>
395388
);
396389
}

‎apps/mobile/src/features/layout/workspace/WorkspaceDock.tsx‎

Lines changed: 0 additions & 71 deletions
This file was deleted.

‎apps/mobile/src/features/layout/workspace/WorkspaceSearchField.tsx‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)