Skip to content

Commit 72a00c4

Browse files
committed
feat(mobile): Edit-style git pill with Safari-Back long-press menu
The thread-bar CTA was a second control next to Git, so open transitions felt crowded. Tap runs the next step; hold opens the rest of Git (and Terminal) like Safari Back, with glass text like Reminders Edit.
1 parent 9ffb05c commit 72a00c4

12 files changed

Lines changed: 253 additions & 114 deletions

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ import { afterEach, expect, it, vi } from "vite-plus/test";
44

55
vi.mock("react-native", () => ({
66
View: (props: { readonly children?: ReactNode }) => <div>{props.children}</div>,
7+
Pressable: (props: { readonly children?: ReactNode }) => (
8+
<button type="button">{props.children}</button>
9+
),
710
Keyboard: { dismiss: () => {} },
811
BackHandler: { addEventListener: () => ({ remove: () => {} }) },
912
}));
13+
vi.mock("./AppText", () => ({
14+
AppText: (props: { readonly children?: ReactNode }) => <span>{props.children}</span>,
15+
}));
16+
vi.mock("./AppSymbol", () => ({ SymbolView: () => null }));
17+
vi.mock("./AppActivityIndicator", () => ({ AppActivityIndicator: () => null }));
1018
// React Navigation throws this outside a navigator, as for the Arrange threads sheet.
1119
vi.mock("@react-navigation/native", () => ({
1220
useIsFocused: () => {

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

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ function AppBarView(props: AppBarProps & { readonly searchState?: SearchState })
143143
);
144144
}
145145

146-
const menuView = props.menus?.map((menu) => (
146+
const confirmMenuTitle = props.confirm?.menu?.title;
147+
const menusWithoutConfirm = confirmMenuTitle
148+
? (props.menus?.filter((entry) => entry.title !== confirmMenuTitle) ?? [])
149+
: (props.menus ?? []);
150+
const menuView = menusWithoutConfirm.map((menu) => (
147151
<Menu
148152
key={menu.title}
149153
actions={androidHeaderMenuActions(menu.items)}
@@ -154,25 +158,56 @@ function AppBarView(props: AppBarProps & { readonly searchState?: SearchState })
154158
<ScreenHeaderButton accessibilityLabel={menu.title} icon={menu.icon} />
155159
</Menu>
156160
));
157-
const confirmButton = props.confirm ? (
158-
props.confirm.showLabel || !props.confirm.icon ? (
161+
const confirm = props.confirm;
162+
const menuConfirm = confirm?.menu ? (
163+
<Menu
164+
actions={androidHeaderMenuActions(confirm.menu.items)}
165+
isAnchoredToRight
166+
title={confirm.menu.status ?? confirm.menu.title}
167+
shouldOpenOnLongPress
168+
onPressAction={({ nativeEvent }) => selectMenuItem(confirm.menu!.items, nativeEvent.event)}
169+
>
170+
{confirm.showLabel || !confirm.icon ? (
171+
<Button
172+
label={confirm.label}
173+
accessibilityLabel={confirm.accessibilityLabel ?? confirm.label}
174+
tone="text"
175+
loading={confirm.loading}
176+
disabled={confirm.disabled}
177+
onPress={confirm.onPress}
178+
/>
179+
) : (
180+
<AndroidHeaderIconButton
181+
accessibilityLabel={confirm.accessibilityLabel ?? confirm.label}
182+
icon={confirm.icon}
183+
disabled={confirm.disabled}
184+
onPress={confirm.onPress}
185+
/>
186+
)}
187+
</Menu>
188+
) : null;
189+
const labeledConfirm =
190+
confirm && !confirm.menu && (confirm.showLabel || !confirm.icon) ? (
159191
<Button
160-
label={props.confirm.label}
161-
accessibilityLabel={props.confirm.accessibilityLabel ?? props.confirm.label}
192+
label={confirm.label}
193+
accessibilityLabel={confirm.accessibilityLabel ?? confirm.label}
162194
tone="text"
163-
loading={props.confirm.loading}
164-
disabled={props.confirm.disabled}
165-
onPress={props.confirm.onPress}
166-
/>
167-
) : (
168-
<AndroidHeaderIconButton
169-
accessibilityLabel={props.confirm.accessibilityLabel ?? props.confirm.label}
170-
icon={props.confirm.icon}
171-
disabled={props.confirm.disabled}
172-
onPress={props.confirm.onPress}
195+
loading={confirm.loading}
196+
disabled={confirm.disabled}
197+
onPress={confirm.onPress}
173198
/>
174-
)
175-
) : null;
199+
) : null;
200+
const confirmButton = confirm
201+
? (menuConfirm ??
202+
labeledConfirm ?? (
203+
<AndroidHeaderIconButton
204+
accessibilityLabel={confirm.accessibilityLabel ?? confirm.label}
205+
icon={confirm.icon!}
206+
disabled={confirm.disabled}
207+
onPress={confirm.onPress}
208+
/>
209+
))
210+
: null;
176211
const options =
177212
props.embedded || props.sheet ? null : (
178213
<NativeStackScreenOptions

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens"
44
import { NavigationContext } from "@react-navigation/native";
55
import { use, useId, useLayoutEffect } from "react";
66
import { Pressable, View } from "react-native";
7-
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
7+
import { createNativeHeaderMenu, renderNativeHeaderMenuItems } from "./nativeHeaderMenu.ios";
88
import { ScreenHeaderButton } from "./ScreenHeaderButton";
99
import { NativeStackScreenOptions, useScreenOptionsWriter } from "../../native/StackHeader";
1010
import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
@@ -81,12 +81,16 @@ export function AppBar(props: AppBarProps) {
8181
const { colors } = useControlTheme();
8282
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
8383
const { search, menus } = props;
84-
const menu = menus?.[0];
84+
const confirmMenuTitle = props.confirm?.menu?.title;
85+
const menusWithoutConfirm = confirmMenuTitle
86+
? (menus?.filter((entry) => entry.title !== confirmMenuTitle) ?? [])
87+
: (menus ?? []);
88+
const menu = menusWithoutConfirm[0];
8589
const compactSearch =
8690
search !== undefined &&
8791
(search.compactToolbar ?? !layout.usesSplitView) &&
8892
usesNativeMailSearchToolbar;
89-
const visibleMenus = compactSearch ? (menus?.slice(1) ?? []) : (menus ?? []);
93+
const visibleMenus = compactSearch ? menusWithoutConfirm.slice(1) : menusWithoutConfirm;
9094
// Where the mail toolbar isn't used, the Duo keeps search at the bottom of the pane like its
9195
// workspace lists; elsewhere inline search is a button in the bar.
9296
const duoBottomSearch =
@@ -210,6 +214,27 @@ export function AppBar(props: AppBarProps) {
210214
<AppActivityIndicator colorClassName="accent-prominent-action" />
211215
</View>
212216
</Toolbar.Custom>
217+
) : props.confirm?.menu ? (
218+
// Edit-style glass text (or icon) + Safari-Back long-press: native primaryAction
219+
// + menu, no chevron — the glass morphs into the menu on hold.
220+
<Toolbar.Button
221+
icon={
222+
props.confirm.showLabel
223+
? undefined
224+
: props.confirm.icon
225+
? iosIcon(props.confirm.icon)
226+
: iosIcon(props.confirm.menu.icon)
227+
}
228+
label={props.confirm.showLabel ? props.confirm.label : undefined}
229+
accessibilityLabel={props.confirm.accessibilityLabel ?? props.confirm.label}
230+
accessibilityHint="Shows more actions on long press"
231+
disabled={props.confirm.disabled}
232+
onPress={props.confirm.onPress}
233+
menuTitle={props.confirm.menu.status ?? props.confirm.menu.title}
234+
separateBackground
235+
>
236+
{renderNativeHeaderMenuItems(props.confirm.menu.items)}
237+
</Toolbar.Button>
213238
) : props.confirm?.icon && !props.confirm.showLabel ? (
214239
// Custom AppSymbols (e.g. PR glyph) are not SF Symbols — render via SymbolView,
215240
// same footprint as other trailing icons (no prominent pill).

‎apps/mobile/src/components/ui/AppBar.types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export interface AppBarConfirm {
6262
readonly icon?: AppSymbolName;
6363
/** Defaults to `label`. Use when the visible control is icon-only or shortened. */
6464
readonly accessibilityLabel?: string;
65+
/**
66+
* Long-press menu on the confirm control (iOS: primaryAction + menu; Android: long-press).
67+
* When set, AppBar does not also render this menu as a separate trailing icon.
68+
*/
69+
readonly menu?: AppBarMenu;
6570
}
6671

6772
export interface AppBarSearch {
Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,6 @@
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-
49-
export function splitAndroidHeaderActions<Action extends { readonly overflowOnly?: boolean }>(
50-
actions: ReadonlyArray<Action>,
51-
wide: boolean,
52-
) {
53-
const inline = actions.filter((action) => !action.overflowOnly);
54-
const directCount = actions.length > 2 ? (wide ? 3 : 1) : inline.length;
55-
const visibleActions = inline.slice(0, directCount);
56-
return {
57-
visibleActions,
58-
overflowActions: actions.filter((action) => !visibleActions.includes(action)),
59-
};
60-
}
1+
export {
2+
findHeaderMenuAction,
3+
headerMenuActions,
4+
headerMenuActions as androidHeaderMenuActions,
5+
splitAndroidHeaderActions,
6+
} from "./headerMenu";
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import type { MenuAction } from "@react-native-menu/menu";
2+
import type { AppBarMenuItem } from "./AppBar.types";
3+
4+
export function headerMenuActions(items: ReadonlyArray<AppBarMenuItem>): MenuAction[] {
5+
return items.flatMap((item): MenuAction[] =>
6+
"items" in item
7+
? item.inline && !item.title
8+
? headerMenuActions(item.items)
9+
: [
10+
{
11+
id: item.id,
12+
title: item.title ?? "",
13+
image: item.icon,
14+
subactions: headerMenuActions(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+
49+
export function splitAndroidHeaderActions<Action extends { readonly overflowOnly?: boolean }>(
50+
actions: ReadonlyArray<Action>,
51+
wide: boolean,
52+
) {
53+
const inline = actions.filter((action) => !action.overflowOnly);
54+
const directCount = actions.length > 2 ? (wide ? 3 : 1) : inline.length;
55+
const visibleActions = inline.slice(0, directCount);
56+
return {
57+
visibleActions,
58+
overflowActions: actions.filter((action) => !visibleActions.includes(action)),
59+
};
60+
}

‎apps/mobile/src/components/ui/nativeHeaderMenu.ios.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Toolbar } from "./Toolbar";
22

33
import type { AppBarMenu, AppBarMenuItem } from "./AppBar.types";
44

5-
function renderMenuItems(items: ReadonlyArray<AppBarMenuItem>) {
5+
export function renderNativeHeaderMenuItems(items: ReadonlyArray<AppBarMenuItem>) {
66
return items.map((item) =>
77
"items" in item ? (
88
<Toolbar.Menu key={item.id} title={item.title} icon={item.icon} inline={item.inline}>
9-
{renderMenuItems(item.items)}
9+
{renderNativeHeaderMenuItems(item.items)}
1010
</Toolbar.Menu>
1111
) : (
1212
<Toolbar.MenuAction
@@ -34,7 +34,7 @@ export function createNativeHeaderMenu(menu: AppBarMenu) {
3434
separateBackground={menu.separateBackground ?? true}
3535
>
3636
{menu.status ? <Toolbar.Label>{menu.status}</Toolbar.Label> : null}
37-
{renderMenuItems(menu.items)}
37+
{renderNativeHeaderMenuItems(menu.items)}
3838
</Toolbar.Menu>
3939
);
4040
}

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,26 @@ export function ThreadHeader(props: {
2727
useAdaptiveWorkspaceLayout();
2828
const { primaryAction: gitPrimaryAction, menu: gitMenu } = useThreadGitBar(props.gitControls);
2929
const terminalMenu = threadTerminalMenu(props.gitControls);
30-
// Pill already crowds the bar — nest Terminal under Git instead of a second toolbar control.
31-
const menus: AppBarMenu[] =
32-
gitPrimaryAction !== null && terminalMenu
33-
? [
34-
{
35-
...gitMenu,
36-
items: [
37-
...gitMenu.items,
38-
{
39-
id: "git-terminal",
40-
title: terminalMenu.title,
41-
icon:
42-
typeof terminalMenu.icon === "string" ? terminalMenu.icon : terminalMenu.icon.ios,
43-
items: terminalMenu.items,
44-
},
45-
],
46-
},
47-
]
48-
: [gitMenu, ...(terminalMenu ? [terminalMenu] : [])];
30+
// Edit-style text CTA + Safari-Back long-press menu (no chevron). Nest Terminal under Git.
31+
const gitMenuWithTerminal: AppBarMenu =
32+
terminalMenu !== null
33+
? {
34+
...gitMenu,
35+
items: [
36+
...gitMenu.items,
37+
{
38+
id: "git-terminal",
39+
title: terminalMenu.title,
40+
icon:
41+
typeof terminalMenu.icon === "string" ? terminalMenu.icon : terminalMenu.icon.ios,
42+
items: terminalMenu.items,
43+
},
44+
],
45+
}
46+
: gitMenu;
47+
const confirm =
48+
gitPrimaryAction !== null ? { ...gitPrimaryAction, menu: gitMenuWithTerminal } : undefined;
49+
const menus: AppBarMenu[] = gitPrimaryAction !== null ? [] : [gitMenuWithTerminal];
4950
const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible;
5051
const inspectorVisible = props.inspectorMode !== null && panes.auxiliaryPaneVisible;
5152
const actions: AppBarAction[] = props.hasThreadCwd
@@ -78,7 +79,7 @@ export function ThreadHeader(props: {
7879
}
7980
actions={actions}
8081
menus={menus}
81-
confirm={gitPrimaryAction ?? undefined}
82+
confirm={confirm}
8283
trailing={
8384
props.fileInspectorSupported && props.hasThreadCwd ? (
8485
<ScreenHeaderButton

0 commit comments

Comments
 (0)