fix(mobile): show rounded pull request selection in the sidebar (#18480)

This commit is contained in:
Alex authored and GitHub committed 2026-10-11 20:45:15 -07:00
1 parent 4ab4cdf452
commit 2e24ec44db
10 files changed
+308 -123

No files matched your search

+2
View File
@@ -51,6 +51,7 @@ import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboardi
import { AttachmentFileScreen } from "./features/files/AttachmentFileScreen";
import { ThreadFilesTreeScreen, ThreadFileScreen } from "./features/files/ThreadFilesRouteScreen";
import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout";
import { selectedPullRequestKey } from "./features/pull-requests/pullRequestSelection";
import {
HardwareKeyboardCommandOverlay,
HardwareKeyboardCommandProvider,
@@ -658,6 +659,7 @@ function RootStackLayout(props: {
<AdaptiveWorkspaceLayout
pathname={workspaceLocation.pathname}
workspaceRouteKey={workspaceLocation.routeKey}
selectedPullRequestKey={selectedPullRequestKey(props.state)}
>
{props.children}
<HardwareKeyboardCommandOverlay />
@@ -220,6 +220,7 @@ export function AdaptiveWorkspaceLayout(props: {
readonly children: ReactNode;
readonly pathname: string;
readonly workspaceRouteKey: string | undefined;
readonly selectedPullRequestKey?: string | null;
}) {
const preferencesResult = useAtomValue(mobilePreferencesAtom);
if (!AsyncResult.isSuccess(preferencesResult)) {
@@ -245,6 +246,7 @@ function AdaptiveWorkspaceLayoutContent(
readonly children: ReactNode;
readonly pathname: string;
readonly workspaceRouteKey: string | undefined;
readonly selectedPullRequestKey?: string | null;
} & {
readonly projectGroupingMode: SidebarProjectGroupingMode;
readonly savedThreadListFilters?: ThreadListFilters | undefined;
@@ -739,7 +741,10 @@ function AdaptiveWorkspaceLayoutContent(
/>
)}
>
<AndroidWorkspaceSidebar onRequestVisibility={revealPrimarySidebar}>
<AndroidWorkspaceSidebar
onRequestVisibility={revealPrimarySidebar}
selectedPullRequestKey={props.selectedPullRequestKey ?? null}
>
<AndroidHomeFabLayout sidebar onStartNewTask={handleStartNewTask}>
<ThreadNavigationSidebar
width={layout.listPaneWidth}
@@ -6,6 +6,11 @@ import { ControlPillMenu } from "../../components/ControlPillMenu";
import type { ControlPillMenuProps } from "../../components/ControlPillMenu.types";
import { cn } from "../../lib/cn";
import { relativeTime } from "../../lib/time";
import {
selectedThreadRowColors,
THREAD_LIST_V2_SIDEBAR_ROW_STYLE,
THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE,
} from "../threads/thread-list-v2-row-appearance";
import { PullRequestAvatar, PullRequestDiffStats } from "./PullRequestPresentation";
import {
pullRequestLabelColor,
@@ -20,11 +25,27 @@ export const PullRequestListRow = memo(
readonly item: EnvironmentPullRequestListEntry;
readonly onSelect: (item: EnvironmentPullRequestListEntry) => void;
readonly selected: boolean;
readonly sidebar: boolean;
readonly busy: boolean;
readonly getActions: (item: EnvironmentPullRequestListEntry) => ControlPillMenuProps["actions"];
readonly onAction: (item: EnvironmentPullRequestListEntry, action: string) => void;
}) {
const { item } = props;
const foreground = props.selected
? selectedThreadRowColors.foregroundClassName
: props.sidebar
? "text-drawer-foreground"
: "text-foreground";
const mutedForeground = props.selected
? selectedThreadRowColors.mutedForegroundClassName
: props.sidebar
? "text-drawer-foreground-muted"
: "text-foreground-muted";
const tertiaryForeground = props.selected
? selectedThreadRowColors.mutedForegroundClassName
: props.sidebar
? "text-drawer-foreground-muted"
: "text-foreground-tertiary";
const status = pullRequestStatus(item);
const review = pullRequestListReviewStatus(item);
const checkTint =
@@ -34,123 +55,144 @@ export const PullRequestListRow = memo(
? "accent-danger-foreground"
: "accent-warning-foreground";
return (
<ControlPillMenu
shouldOpenOnLongPress
title={`#${item.number} · ${item.repository}`}
actions={props.getActions(item)}
onPressAction={({ nativeEvent }) => props.onAction(item, nativeEvent.event)}
>
<Pressable
accessibilityRole="button"
accessibilityState={{ selected: props.selected, busy: props.busy }}
accessibilityLabel={`Pull request ${item.number}, ${item.title}, ${status.label}, by ${item.author?.login ?? "unknown author"}${review ? `, ${review.accessibleLabel}` : ""}${item.checksState ? `, checks ${item.checksState}` : ""}${item.stack ? `, stack ${item.stack.position} of ${item.stack.size}` : ""}${item.labels.length ? `, ${item.labels.map((label) => label.name).join(", ")}` : ""}, ${item.additions} additions, ${item.deletions} deletions`}
accessibilityHint="Double tap to open. Touch and hold for quick actions."
onPress={() => props.onSelect(item)}
disabled={props.busy}
className={cn(
"flex-row gap-3 px-4 active:bg-row-hover",
props.selected && "bg-thread-selected",
props.busy && "opacity-50",
)}
<View style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE : undefined}>
<ControlPillMenu
shouldOpenOnLongPress
title={`#${item.number} · ${item.repository}`}
actions={props.getActions(item)}
onPressAction={({ nativeEvent }) => props.onAction(item, nativeEvent.event)}
>
<View className="pt-2.5">
<SymbolView name={status.icon} size={20} tintColorClassName={status.tint} />
</View>
<View className="min-w-0 flex-1 gap-1 border-b border-border-subtle py-2.5">
<View className="flex-row items-center gap-1.5">
<PullRequestAvatar actor={item.author} size={16} />
<Text className="min-w-0 flex-1 text-xs text-foreground-muted" numberOfLines={1}>
{item.repository} <Text className="text-foreground-tertiary">#{item.number}</Text>
</Text>
{item.stack ? (
<View className="flex-row items-center gap-1">
<SymbolView
name="square.3.layers.3d"
size={12}
tintColorClassName="accent-icon-muted"
/>
<Text className="text-2xs tabular-nums text-foreground-muted">
{item.stack.position}/{item.stack.size}
</Text>
</View>
) : null}
<Text className="text-2xs tabular-nums text-foreground-tertiary">
{relativeTime(item.updatedAt)}
</Text>
<Pressable
accessibilityRole="button"
accessibilityState={{ selected: props.selected, busy: props.busy }}
accessibilityLabel={`Pull request ${item.number}, ${item.title}, ${status.label}, by ${item.author?.login ?? "unknown author"}${review ? `, ${review.accessibleLabel}` : ""}${item.checksState ? `, checks ${item.checksState}` : ""}${item.stack ? `, stack ${item.stack.position} of ${item.stack.size}` : ""}${item.labels.length ? `, ${item.labels.map((label) => label.name).join(", ")}` : ""}, ${item.additions} additions, ${item.deletions} deletions`}
accessibilityHint="Double tap to open. Touch and hold for quick actions."
onPress={() => props.onSelect(item)}
disabled={props.busy}
style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_STYLE : undefined}
className={cn(
"flex-row gap-3 overflow-hidden",
!props.sidebar && "px-4 active:bg-row-hover",
props.sidebar && "bg-drawer",
props.sidebar && !props.selected && "active:bg-thread-hover",
props.selected && "bg-thread-selected",
props.busy && "opacity-50",
)}
>
<View className={props.sidebar ? "pt-0.5" : "pt-2.5"}>
<SymbolView name={status.icon} size={20} tintColorClassName={status.tint} />
</View>
<Text
className="text-base leading-5 font-t3-medium text-foreground"
numberOfLines={2}
ellipsizeMode="tail"
<View
className={cn(
"min-w-0 flex-1 gap-1",
!props.sidebar && "border-b border-border-subtle py-2.5",
)}
>
{item.title}
</Text>
<View className="flex-row items-center gap-1.5">
<View className="min-w-0 flex-1 flex-row items-center gap-1">
{item.labels.slice(0, 2).map((label) => {
const color = pullRequestLabelColor(label.color);
return (
<View
key={label.name}
className="min-w-0 shrink flex-row items-center gap-1 rounded-md bg-subtle px-1.5 py-0.5"
style={{ maxWidth: 160, ...(color ? { backgroundColor: `${color}20` } : {}) }}
>
{color ? (
<View
style={{ width: 5, height: 5, borderRadius: 3, backgroundColor: color }}
/>
) : null}
<Text
className="shrink text-2xs font-t3-medium text-foreground-muted"
numberOfLines={1}
<View className="flex-row items-center gap-1.5">
<PullRequestAvatar actor={item.author} size={16} />
<Text className={cn("min-w-0 flex-1 text-xs", mutedForeground)} numberOfLines={1}>
{item.repository} <Text className={tertiaryForeground}>#{item.number}</Text>
</Text>
{item.stack ? (
<View className="flex-row items-center gap-1">
<SymbolView
name="square.3.layers.3d"
size={12}
tintColorClassName={
props.selected
? selectedThreadRowColors.mutedIconTintClassName
: props.sidebar
? "accent-drawer-foreground-muted"
: "accent-foreground-muted"
}
/>
<Text className={cn("text-2xs tabular-nums", mutedForeground)}>
{item.stack.position}/{item.stack.size}
</Text>
</View>
) : null}
<Text className={cn("text-2xs tabular-nums", tertiaryForeground)}>
{relativeTime(item.updatedAt)}
</Text>
</View>
<Text
className={cn("text-base leading-5 font-t3-medium", foreground)}
numberOfLines={2}
ellipsizeMode="tail"
>
{item.title}
</Text>
<View className="flex-row items-center gap-1.5">
<View className="min-w-0 flex-1 flex-row items-center gap-1">
{item.labels.slice(0, 2).map((label) => {
const color = pullRequestLabelColor(label.color);
return (
<View
key={label.name}
className="min-w-0 shrink flex-row items-center gap-1 rounded-md bg-subtle px-1.5 py-0.5"
style={{
maxWidth: 160,
...(color ? { backgroundColor: `${color}20` } : {}),
}}
>
{label.name}
</Text>
</View>
);
})}
{item.labels.length > 2 ? (
<Text className="shrink-0 text-2xs text-foreground-tertiary">
+{item.labels.length - 2}
</Text>
{color ? (
<View
style={{ width: 5, height: 5, borderRadius: 3, backgroundColor: color }}
/>
) : null}
<Text
className={cn("shrink text-2xs font-t3-medium", mutedForeground)}
numberOfLines={1}
>
{label.name}
</Text>
</View>
);
})}
{item.labels.length > 2 ? (
<Text className={cn("shrink-0 text-2xs", tertiaryForeground)}>
+{item.labels.length - 2}
</Text>
) : null}
</View>
{item.checksState ? (
<View className="shrink-0" accessibilityLabel={`Checks ${item.checksState}`}>
<SymbolView
name={
item.checksState === "passing"
? "checkmark.circle"
: item.checksState === "failing"
? "xmark.circle.fill"
: "clock"
}
size={13}
tintColorClassName={checkTint}
/>
</View>
) : null}
{review ? (
<View className="shrink-0" accessibilityLabel={review.accessibleLabel}>
<SymbolView name={review.icon} size={13} tintColorClassName={review.tint} />
</View>
) : null}
{item.additions || item.deletions ? (
<PullRequestDiffStats
additions={item.additions}
deletions={item.deletions}
compact
/>
) : null}
</View>
{item.checksState ? (
<View className="shrink-0" accessibilityLabel={`Checks ${item.checksState}`}>
<SymbolView
name={
item.checksState === "passing"
? "checkmark.circle"
: item.checksState === "failing"
? "xmark.circle.fill"
: "clock"
}
size={13}
tintColorClassName={checkTint}
/>
</View>
) : null}
{review ? (
<View className="shrink-0" accessibilityLabel={review.accessibleLabel}>
<SymbolView name={review.icon} size={13} tintColorClassName={review.tint} />
</View>
) : null}
{item.additions || item.deletions ? (
<PullRequestDiffStats
additions={item.additions}
deletions={item.deletions}
compact
/>
) : null}
</View>
</View>
</Pressable>
</ControlPillMenu>
</Pressable>
</ControlPillMenu>
</View>
);
},
(previous, next) =>
pullRequestListRowsAreEqual(previous.item, next.item) &&
previous.selected === next.selected &&
previous.sidebar === next.sidebar &&
previous.busy === next.busy &&
previous.onSelect === next.onSelect &&
previous.onAction === next.onAction &&
@@ -53,7 +53,12 @@ function PullRequestScrollView(props: ScrollViewProps) {
);
}
export function PullRequestsScreen() {
export function PullRequestsScreen(
props: {
readonly sidebar?: boolean;
readonly selectedPullRequestKey?: string | null;
} = {},
) {
const navigation = useNavigation();
const primaryColumn = use(NativePrimaryColumnContext);
const workspace = useWorkspaceTabs()!;
@@ -135,7 +140,8 @@ export function PullRequestsScreen() {
connectedTargets.map((target) => target.environmentId),
result.updateEntry,
);
const selectedKey = primaryColumn?.selectedPullRequestKey;
const sidebar = props.sidebar === true || primaryColumn !== null;
const selectedKey = props.selectedPullRequestKey ?? primaryColumn?.selectedPullRequestKey;
const entries = useMemo(
() =>
filterPullRequestList(
@@ -179,9 +185,10 @@ export function PullRequestsScreen() {
onAction={select}
busy={busyKey === pullRequestKey(item)}
selected={selectedKey === pullRequestKey(item)}
sidebar={sidebar}
/>
),
[selectPullRequest, selectedKey, actions, select, busyKey],
[selectPullRequest, selectedKey, actions, select, busyKey, sidebar],
);
const previousSearchMode = useRef(tab.searchMode);
useEffect(() => {
@@ -199,11 +206,11 @@ export function PullRequestsScreen() {
: -1;
return (
<View className={primaryColumn ? "flex-1 bg-drawer" : "flex-1 bg-screen"}>
<View className={sidebar ? "flex-1 bg-drawer" : "flex-1 bg-screen"}>
<LegendList
ref={listRef}
data={entries}
extraData={`${primaryColumn?.selectedPullRequestKey}:${busyKey}`}
extraData={`${selectedKey}:${busyKey}`}
keyExtractor={pullRequestKey}
itemsAreEqual={pullRequestListRowsAreEqual}
// Default-size rows measure about 78pt with one title line and 98pt with two.
@@ -0,0 +1,80 @@
import { describe, expect, it } from "vite-plus/test";
import type { NavigationState } from "@react-navigation/native";
import { selectedPullRequestKey } from "./pullRequestSelection";
const params = {
environmentId: "environment-one",
projectId: "project-one",
host: "GitHub.COM",
repository: "Org/Repo",
number: 42,
};
const home = { key: "home", name: "Home" };
const pullRequest = { key: "pr", name: "PullRequest", params };
function selection(routes: NavigationState["routes"], index = routes.length - 1) {
return selectedPullRequestKey({ routes, index });
}
describe("displayed pull request selection", () => {
it("normalizes repository and host while retaining the environment scope", () => {
expect(selection([home, pullRequest])).toBe("environment-one:github.com:org/repo:42");
expect(
selection([
home,
{ ...pullRequest, params: { ...params, environmentId: "environment-two" } },
]),
).toBe("environment-two:github.com:org/repo:42");
});
it.each([
"PullRequestFile",
"PullRequestFiles",
"PullRequestGuideStop",
"PullRequestDiscussion",
"PullRequestReviewers",
"PullRequestReview",
"PullRequestInlineComment",
])("keeps the owning selection on %s", (name) => {
expect(selection([home, pullRequest, { key: name, name, params }])).toBe(
"environment-one:github.com:org/repo:42",
);
});
it("uses the most recently opened PR, including a different hosting service", () => {
expect(
selection([
home,
pullRequest,
{
key: "other-pr",
name: "PullRequest",
params: { ...params, host: "github.enterprise", repository: "Other/Repo", number: 7 },
},
]),
).toBe("environment-one:github.enterprise:other/repo:7");
});
it.each(["Home", "Thread", "ThreadFiles"])("clears an older selection on %s", (name) => {
expect(selection([home, pullRequest, { key: "current", name }])).toBeNull();
});
it("ignores inactive routes after the navigation index", () => {
expect(selection([home, pullRequest], 0)).toBeNull();
});
it("retains the owning PR behind an unrelated overlay", () => {
expect(selection([home, pullRequest, { key: "settings", name: "SettingsSheet" }])).toBe(
"environment-one:github.com:org/repo:42",
);
});
it("does not highlight an older PR when the current PR lacks its hosting identity", () => {
expect(
selection([
home,
pullRequest,
{ key: "unresolved", name: "PullRequest", params: { environmentId: "environment-one" } },
]),
).toBeNull();
});
});
@@ -0,0 +1,32 @@
import type { NavigationState } from "@react-navigation/native";
import { pullRequestListKey } from "./pullRequestList";
/** Follow the displayed PR through its detail routes and sheets, not an older stack entry. */
export function selectedPullRequestKey(state: Pick<NavigationState, "routes" | "index">) {
for (let index = state.index; index >= 0; index--) {
const route = state.routes[index];
if (!route) continue;
if (route.name === "Home" || route.name.startsWith("Thread")) return null;
if (!route.name.startsWith("PullRequest")) continue;
const params = route.params;
if (
params &&
"environmentId" in params &&
"host" in params &&
"repository" in params &&
"number" in params &&
typeof params.environmentId === "string" &&
typeof params.host === "string" &&
typeof params.repository === "string" &&
typeof params.number === "number"
) {
return `${params.environmentId}:${pullRequestListKey({
host: params.host,
repository: params.repository,
number: params.number,
})}`;
}
if (route.name === "PullRequest") return null;
}
return null;
}
@@ -4,6 +4,17 @@ import type { MobileThemeVariables } from "../../lib/mobileTheme";
export const THREAD_LIST_V2_MONO_FONT = "monospace";
export const THREAD_LIST_V2_ROW_CONTENT_CLASS_NAME = "px-3 py-2.5";
export const THREAD_LIST_V2_ROW_DIVIDERS = false;
export const THREAD_LIST_V2_SIDEBAR_ROW_STYLE = {
borderRadius: 20,
paddingHorizontal: 12,
paddingVertical: 10,
} satisfies ViewStyle;
export const THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE = {
borderRadius: 20,
overflow: "hidden",
marginHorizontal: 8,
marginVertical: 2,
} satisfies ViewStyle;
export const selectedThreadRowColors = {
foregroundClassName: "text-thread-selected-foreground",
@@ -25,14 +36,9 @@ export function getThreadListV2RowAppearance(
const backgroundColor = theme[sidebarPane ? "--color-drawer" : "--color-screen"];
const style: ViewStyle = {
backgroundColor: selected ? selectedBackgroundColor : backgroundColor,
borderRadius: 20,
};
const swipeContainerStyle: ViewStyle = {
borderRadius: 20,
overflow: "hidden",
marginHorizontal: 8,
marginVertical: 2,
borderRadius: THREAD_LIST_V2_SIDEBAR_ROW_STYLE.borderRadius,
};
const swipeContainerStyle = THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE;
return {
className: undefined,
@@ -52,7 +58,7 @@ export function getThreadListV2RowAppearance(
? "accent-drawer-foreground-muted"
: "accent-foreground-tertiary",
style,
cardStyle: sidebarPane ? { ...style, paddingHorizontal: 12, paddingVertical: 10 } : style,
cardStyle: sidebarPane ? { ...style, ...THREAD_LIST_V2_SIDEBAR_ROW_STYLE } : style,
swipeContainerStyle,
swipeBackgroundColor: backgroundColor,
providerIconSurfaceColor: selected ? selectedBackgroundColor : backgroundColor,
@@ -4,6 +4,15 @@ import type { MobileThemeVariables } from "../../lib/mobileTheme";
export const THREAD_LIST_V2_MONO_FONT = "Menlo";
export const THREAD_LIST_V2_ROW_CONTENT_CLASS_NAME = "px-5 py-2.5";
export const THREAD_LIST_V2_ROW_DIVIDERS = true;
export const THREAD_LIST_V2_SIDEBAR_ROW_STYLE = {
borderRadius: 12,
paddingHorizontal: 12,
paddingVertical: 10,
} satisfies ViewStyle;
export const THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE = {
borderRadius: 12,
overflow: "hidden",
} satisfies ViewStyle;
export const selectedThreadRowColors = {
foregroundClassName: "text-thread-selected-foreground",
@@ -25,11 +34,11 @@ export function getThreadListV2RowAppearance(
const style: ViewStyle | undefined = sidebarPane
? {
backgroundColor: selected ? selectedBackgroundColor : theme["--color-drawer"],
borderRadius: 12,
borderRadius: THREAD_LIST_V2_SIDEBAR_ROW_STYLE.borderRadius,
}
: undefined;
const swipeContainerStyle: ViewStyle | undefined = sidebarPane
? { borderRadius: 12, overflow: "hidden" }
? THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE
: undefined;
return {
@@ -50,7 +59,7 @@ export function getThreadListV2RowAppearance(
? "accent-drawer-foreground-muted"
: "accent-foreground-tertiary",
style,
cardStyle: sidebarPane ? { ...style, paddingHorizontal: 12, paddingVertical: 10 } : undefined,
cardStyle: sidebarPane ? { ...style, ...THREAD_LIST_V2_SIDEBAR_ROW_STYLE } : undefined,
swipeContainerStyle,
swipeBackgroundColor: theme[sidebarPane ? "--color-drawer" : "--color-screen"],
// Provider badges blend into the surface beneath them.
@@ -8,6 +8,7 @@ import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
export function AndroidWorkspaceSidebar(props: {
readonly children: ReactNode;
readonly onRequestVisibility: () => void;
readonly selectedPullRequestKey: string | null;
}) {
const workspace = useWorkspaceTabs()!;
const context = useMemo(() => ({ ...workspace, bottomClearance: 16 }), [workspace]);
@@ -18,7 +19,7 @@ export function AndroidWorkspaceSidebar(props: {
<View className="flex-1 bg-header">
<MaterialPullRequestToolbar onRequestVisibility={props.onRequestVisibility} />
<MaterialScreenContent insetHorizontal>
<PullRequestsScreen />
<PullRequestsScreen sidebar selectedPullRequestKey={props.selectedPullRequestKey} />
</MaterialScreenContent>
</View>
</WorkspaceTabsContext>
@@ -3,6 +3,7 @@ import type { ReactNode } from "react";
export function AndroidWorkspaceSidebar(props: {
readonly children: ReactNode;
readonly onRequestVisibility: () => void;
readonly selectedPullRequestKey: string | null;
}) {
return props.children;
}