Skip to content

Commit 059c7eb

Browse files
SunkenInTimeclaude
andcommitted
feat(mobile): show project favicons in the Android thread filter menu
The Project submenu of the Android thread filter listed names only, while the thread list and new-task picker show each project's favicon. Android menu actions can now carry a leading view, and both filter menus (phone home and tablet sidebar) pass the existing ProjectFavicon there, sized to the menu's icon slot. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 0fcd5f9 commit 059c7eb

8 files changed

Lines changed: 82 additions & 21 deletions

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MenuAction, MenuComponentProps } from "@react-native-menu/menu";
1+
import type { MenuComponentProps } from "@react-native-menu/menu";
22
import type { ReactNode } from "react";
33
import { useCallback, useEffect, useRef, useState } from "react";
44
import type { StyleProp, ViewStyle } from "react-native";
@@ -8,7 +8,7 @@ import Animated, { FadeIn } from "react-native-reanimated";
88

99
import { OverlayPortal } from "./OverlayPortal";
1010
import { useAndroidControlSizing } from "./useAndroidControlSizing";
11-
import { MaterialMenuPopup } from "./MaterialMenuPopup";
11+
import { MaterialMenuPopup, type AndroidMenuAction } from "./MaterialMenuPopup";
1212

1313
const SCREEN_MARGIN = 12;
1414
const ANCHOR_GAP = 6;
@@ -34,7 +34,7 @@ type OverlayFrame = {
3434
};
3535

3636
export type AndroidAnchoredMenuProps = {
37-
readonly actions: readonly MenuAction[];
37+
readonly actions: readonly AndroidMenuAction[];
3838
readonly title?: string;
3939
readonly onPressAction?: MenuComponentProps["onPressAction"];
4040
/** Applied to the anchor wrapper — call sites flex these to fill toolbars. */
@@ -57,7 +57,7 @@ export type AndroidAnchoredMenuProps = {
5757
export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
5858
const { scale, menuWidth: desiredMenuWidth } = useAndroidControlSizing();
5959
const [anchor, setAnchor] = useState<AnchorSnapshot | null>(null);
60-
const [path, setPath] = useState<readonly MenuAction[]>([]);
60+
const [path, setPath] = useState<readonly AndroidMenuAction[]>([]);
6161
// Height of the modal's root view, in the modal's own coordinate space.
6262
// Menus that flip above their anchor are pinned by their BOTTOM edge
6363
// (bottom = rootHeight - anchorTop), so drill-in height changes grow
@@ -158,7 +158,7 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
158158
const placeable = local !== null && rootHeight !== null;
159159

160160
const onPressItem = useCallback(
161-
(action: MenuAction) => {
161+
(action: AndroidMenuAction) => {
162162
if ((action.subactions?.length ?? 0) > 0) {
163163
setPath((current) => [...current, action]);
164164
return;

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ 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, menuItemHeight } = useAndroidControlSizing();
51+
const { scale, menuItemHeight, iconSize } = 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.
5757
const itemModifiers = [width(props.menuWidth), defaultMinSize({ minHeight: menuItemHeight })];
58+
// Rows without a leading view keep its slot so labels line up, as in Material menus.
59+
const reserveLeading = props.actions.some((action) => action.leading);
5860
const items = (
5961
<>
6062
{props.parent ? (
@@ -84,14 +86,29 @@ export function MaterialMenuPopup(props: MaterialMenuPopupProps) {
8486
modifiers={itemModifiers}
8587
onClick={() => props.onPress(action)}
8688
>
87-
{action.image && isAppSymbolName(action.image) ? (
89+
{action.leading ? (
90+
<DropdownMenuItem.LeadingIcon>
91+
<RNHostView matchContents modifiers={[size(iconSize, iconSize)]}>
92+
<View
93+
style={{ width: iconSize, height: iconSize }}
94+
importantForAccessibility="no-hide-descendants"
95+
>
96+
{action.leading}
97+
</View>
98+
</RNHostView>
99+
</DropdownMenuItem.LeadingIcon>
100+
) : action.image && isAppSymbolName(action.image) ? (
88101
<DropdownMenuItem.LeadingIcon>
89102
<MenuIcon
90103
name={action.image}
91104
destructive={action.attributes?.destructive}
92105
disabled={action.attributes?.disabled}
93106
/>
94107
</DropdownMenuItem.LeadingIcon>
108+
) : reserveLeading ? (
109+
<DropdownMenuItem.LeadingIcon>
110+
<Box modifiers={[size(iconSize, iconSize)]} />
111+
</DropdownMenuItem.LeadingIcon>
95112
) : null}
96113
<DropdownMenuItem.Text>
97114
<Column>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import type { MenuAction } from "@react-native-menu/menu";
2+
import type { ReactNode } from "react";
3+
4+
/** A menu action whose `leading` view, such as a project favicon, replaces its symbol icon. */
5+
export type AndroidMenuAction = Omit<MenuAction, "subactions"> & {
6+
readonly leading?: ReactNode;
7+
readonly subactions?: AndroidMenuAction[];
8+
};
29

310
export interface MaterialMenuPopupProps {
411
readonly menuWidth: number;
@@ -8,10 +15,10 @@ export interface MaterialMenuPopupProps {
815
readonly width: number;
916
readonly height: number;
1017
};
11-
readonly actions: readonly MenuAction[];
18+
readonly actions: readonly AndroidMenuAction[];
1219
readonly title?: string;
13-
readonly parent: MenuAction | null;
14-
readonly onPress: (action: MenuAction) => void;
20+
readonly parent: AndroidMenuAction | null;
21+
readonly onPress: (action: AndroidMenuAction) => void;
1522
readonly onBack: () => void;
1623
readonly onClose: () => void;
1724
/** Keep the editor's window focus and keyboard while showing native menu rows. */

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import type { MenuAction } from "@react-native-menu/menu";
21
import { useCallback, useMemo } from "react";
2+
import type { AndroidMenuAction } from "../../components/MaterialMenuPopup";
3+
import { ProjectFavicon } from "../../components/ProjectFavicon";
4+
import { useAndroidControlSizing } from "../../components/useAndroidControlSizing";
35
import { NativeStackScreenOptions } from "../../native/StackHeader";
46
import { MaterialThreadListToolbar } from "./MaterialThreadListToolbar";
57
import type { HomeHeaderProps } from "./HomeHeader.types";
@@ -11,12 +13,13 @@ function checkedMenuState(checked: boolean) {
1113
}
1214

1315
export function HomeHeader(props: HomeHeaderProps) {
16+
const { iconSize } = useAndroidControlSizing();
1417
// The list uses a fixed creation order and ignores sort/group options, so
1518
// the filter menu only carries the filters and the "customized" icon state
1619
// keys off those alone.
1720
const hasCustomListOptions =
1821
props.selectedEnvironmentId !== null || props.selectedProjectKey !== null;
19-
const menuActions = useMemo<MenuAction[]>(
22+
const menuActions = useMemo<AndroidMenuAction[]>(
2023
() => [
2124
{
2225
id: "environment",
@@ -50,12 +53,28 @@ export function HomeHeader(props: HomeHeaderProps) {
5053
id: `project:${project.key}`,
5154
title: project.label,
5255
state: checkedMenuState(props.selectedProjectKey === project.key),
56+
leading: project.representative ? (
57+
<ProjectFavicon
58+
environmentId={project.representative.environmentId}
59+
faviconPath={project.representative.faviconPath}
60+
projectIcon={project.representative.projectIcon}
61+
projectTitle={project.label}
62+
size={iconSize}
63+
workspaceRoot={project.representative.workspaceRoot}
64+
/>
65+
) : undefined,
5366
})),
5467
],
5568
},
56-
] satisfies MenuAction[])),
69+
] satisfies AndroidMenuAction[])),
70+
],
71+
[
72+
iconSize,
73+
props.environments,
74+
props.projects,
75+
props.selectedEnvironmentId,
76+
props.selectedProjectKey,
5777
],
58-
[props.environments, props.projects, props.selectedEnvironmentId, props.selectedProjectKey],
5978
);
6079
const handleMenuAction = useCallback(
6180
(event: { nativeEvent: { event: string } }) => {

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function HomeRouteScreen() {
9090
}).map((scope) => ({
9191
key: scope.key,
9292
label: scope.title,
93+
representative: scope.representative,
9394
})),
9495
[listOptions.projectGroupingMode, projects, selectedEnvironmentId],
9596
);

‎apps/mobile/src/features/home/MaterialThreadListToolbar.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useCallback, useEffect, useRef, useState, type ComponentProps } from "react";
22
import { BackHandler, Keyboard, type TextInput, View, type LayoutChangeEvent } from "react-native";
33
import { useSafeAreaInsets } from "react-native-safe-area-context";
4-
import type { MenuAction } from "@react-native-menu/menu";
54

65
import { AndroidHeaderIconButton } from "../../components/AndroidScreenHeader";
76
import { CompactBrandTitle } from "../../components/CompactBrandTitle";
87
import { MaterialFloatingActionButton } from "../../components/MaterialFloatingActionButton";
98
import { AndroidAnchoredMenu } from "../../components/AndroidAnchoredMenu";
9+
import type { AndroidMenuAction } from "../../components/MaterialMenuPopup";
1010
import { ControlPillMenu } from "../../components/ControlPill";
1111
import { MaterialSearchField } from "../../components/MaterialSearchField";
1212
import { useHardwareKeyboardCommand } from "../keyboard/hardwareKeyboardCommands";
@@ -19,7 +19,7 @@ import { useMaterialToolbarLayout } from "../../components/useMaterialToolbarLay
1919
export function MaterialThreadListToolbar(props: {
2020
readonly searchQuery: string;
2121
readonly onSearchQueryChange: (query: string) => void;
22-
readonly filterActions: MenuAction[];
22+
readonly filterActions: AndroidMenuAction[];
2323
readonly filterCustomized: boolean;
2424
readonly onFilterAction: NonNullable<ComponentProps<typeof ControlPillMenu>["onPressAction"]>;
2525
readonly onOpenSettings: () => void;

‎apps/mobile/src/features/home/home-list-filter-menu.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
12
import type { EnvironmentId } from "@t3tools/contracts";
23

34
export interface HomeListFilterMenuEnvironment {
@@ -8,6 +9,8 @@ export interface HomeListFilterMenuEnvironment {
89
export interface HomeListFilterMenuProject {
910
readonly key: string;
1011
readonly label: string;
12+
/** Project whose favicon stands for the scope; Android draws it beside the label. */
13+
readonly representative?: EnvironmentProject;
1114
}
1215

1316
type HomeListFilterMenuAction = {

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
type EnvironmentThreadSearchMatch,
1111
} from "@t3tools/client-runtime/state/thread-search";
1212
import { LegendList } from "@legendapp/list/react-native";
13-
import type { MenuAction } from "@react-native-menu/menu";
1413
import { useAtomValue } from "@effect/atom-react";
1514
import { type EnvironmentId, resolveEnvironmentMachineKind } from "@t3tools/contracts";
1615
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -24,6 +23,8 @@ import type { SearchBarCommands } from "react-native-screens";
2423
import { AppText as Text } from "../../components/AppText";
2524
import { CompactBrandTitle } from "../../components/CompactBrandTitle";
2625
import { ControlPillMenu } from "../../components/ControlPill";
26+
import type { AndroidMenuAction } from "../../components/MaterialMenuPopup";
27+
import { ProjectFavicon } from "../../components/ProjectFavicon";
2728
import { SymbolView } from "../../components/AppSymbol";
2829
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
2930
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -134,7 +135,7 @@ function ThreadNavigationSidebarPane(
134135
const drawerColor = materialTheme["--color-drawer"];
135136

136137
const insets = useSafeAreaInsets();
137-
const { fabClearance } = useAndroidControlSizing();
138+
const { fabClearance, iconSize } = useAndroidControlSizing();
138139
const projects = useProjects();
139140
const threads = useThreadShells();
140141
const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
@@ -219,6 +220,7 @@ function ThreadNavigationSidebarPane(
219220
projectScopes.map((scope) => ({
220221
key: scope.key,
221222
label: scope.title,
223+
representative: scope.representative,
222224
})),
223225
[projectScopes],
224226
);
@@ -529,7 +531,7 @@ function ThreadNavigationSidebarPane(
529531
snoozeEnvironmentIds,
530532
threadListV2Layout,
531533
]);
532-
const listMenuActions = useMemo<MenuAction[]>(
534+
const listMenuActions = useMemo<AndroidMenuAction[]>(
533535
() => [
534536
{
535537
id: "environment",
@@ -568,12 +570,24 @@ function ThreadNavigationSidebarPane(
568570
id: `project:${project.key}`,
569571
title: project.label,
570572
state: selectedProjectKey === project.key ? ("on" as const) : ("off" as const),
573+
// iOS hands these actions to the native menu, which can't draw a view.
574+
leading:
575+
Platform.OS === "android" ? (
576+
<ProjectFavicon
577+
environmentId={project.representative.environmentId}
578+
faviconPath={project.representative.faviconPath}
579+
projectIcon={project.representative.projectIcon}
580+
projectTitle={project.label}
581+
size={iconSize}
582+
workspaceRoot={project.representative.workspaceRoot}
583+
/>
584+
) : undefined,
571585
})),
572586
],
573587
},
574-
] satisfies MenuAction[])),
588+
] satisfies AndroidMenuAction[])),
575589
],
576-
[environments, options, projectFilterOptions, selectedProjectKey],
590+
[environments, iconSize, options, projectFilterOptions, selectedProjectKey],
577591
);
578592
const handleListMenuAction = useCallback(
579593
({ nativeEvent }: { readonly nativeEvent: { readonly event: string } }) => {

0 commit comments

Comments
 (0)