Open History to see the last commit
1import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
2import { Chip } from "../../components/ui/Chip";
3import { pullRequestTabOffset } from "./pullRequestTabScroll";
4import { guideFocusedRows, type GuideDiffFocus } from "./guide/guideDiffFocus";
5import { PullRequestGuideContent } from "./guide/PullRequestGuideScreen";
6import { useReviewGuidesEnabled } from "./guide/useReviewGuide";
7import {
8 filterPullRequestActivity,
9 DEFAULT_ACTIVITY_FILTER,
10 type ActivityFilter,
11} from "./pullRequestActivityFilter";
12import { PullRequestActivityFilters } from "./PullRequestActivityFilters";
13import type { LegendListRef } from "@legendapp/list/react-native";
14import { AnimatedLegendList } from "@legendapp/list/reanimated";
15import Animated from "react-native-reanimated";
16import {
17 PR_ROW_LAYOUT,
18 PR_ROW_ENTER,
19 PR_ROW_EXIT,
20 PR_POSITION_LAYOUT,
21} from "./pullRequestAnimations";
22import {
23 canPerformPullRequestAction,
24 openOnProviderLabel,
25 PR_ACTION_ICONS,
26 pullRequestActionLabel,
27} from "./pullRequestActions";
28import * as Clipboard from "expo-clipboard";
29import { Button } from "../../components/ui/Button";
30import { usePullRequestReviewDraft } from "./usePullRequestReviewDraft";
31import { usePullRequestFilesViewed } from "./usePullRequestFilesViewed";
32import { usePullRequestPermissions } from "./usePullRequestPermissions";
33import { usePullRequestDescription } from "./usePullRequestDescription";
34import { usePullRequestAction } from "./usePullRequestAction";
35import { annotatePullRequestDiff, reviewPosition } from "./pullRequestDiffComments";
36import { usePullRequestFileFilter } from "./usePullRequestFileFilter";
37import {
38 handlePullRequestDiffDebugEvent,
39 pullRequestDiffInitialPosition,
40} from "./pullRequestDiffDebug";
41import { usePullRequestDiffHighlightFiles } from "./usePullRequestDiffHighlightFiles";
42import { isTestChangedFile } from "@t3tools/shared/changedFileKind";
43import { useFocusEffect, useNavigation, type StaticScreenProps } from "@react-navigation/native";
44import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
45import { RegistryContext, useAtomRefresh, useAtomValue } from "@effect/atom-react";
46import { pullRequestReviewKey } from "./pullRequestReviewDrafts";
47import {
48 type PullRequestDetail,
49 type PullRequestListEntry,
50 type PullRequestSummary,
51} from "@t3tools/contracts";
52import { PullRequestOverviewLoading } from "./PullRequestOverviewLoading";
53import { copyPullRequestLink, sharePullRequestLink } from "./pullRequestLink";
54import { pullRequestStatus } from "./pullRequestStatus";
55import { use, useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
56import { Linking, Platform, Pressable, RefreshControl, StyleSheet, View } from "react-native";
57import { NativeScrollView } from "../../native/NativeScrollViewMarker";
58import { useSafeAreaInsets } from "react-native-safe-area-context";
59
60import { AppText as Text } from "../../components/ui/AppText";
61import { AppBar } from "../../components/ui/AppBar";
62import { useContentTopInset } from "../../components/ui/useBarInset";
63import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
64import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
65import { useAndroidWorkspaceBack } from "../layout/workspace/useAndroidWorkspaceNavigation";
66import { EmptyState } from "../../components/ui/EmptyState";
67import { SegmentedControl } from "../../components/ui/SegmentedControl";
68import { SymbolView } from "../../components/ui/AppSymbol";
69import { ScreenContent } from "../../components/ui/ScreenContent";
70import { RelativeTime } from "../../components/RelativeTime";
71import { usePullRequestConnected } from "./usePullRequestConnected";
72import { usePullRequestLiveChecks } from "./usePullRequestLiveChecks";
73import { pullRequestLabelColor } from "./pullRequestList";
74import { PullRequestReactions } from "./PullRequestReactions";
75import { composerPullRequests } from "../../state/pull-requests";
76import { useEnvironmentQuery } from "../../state/query";
77import { SourceControlAppAccessNotice } from "./SourceControlAppAccessNotice";
78import { usePullToRefresh } from "../../state/use-pull-to-refresh";
79import {
80 resolveNativeReviewDiffView,
81 type NativeReviewDiffViewHandle,
82 type NativeReviewDiffViewProps,
83} from "../diffs/nativeReviewDiffSurface";
84import {
85 getCachedNativeReviewDiffData,
86 NATIVE_REVIEW_DIFF_CONTENT_WIDTH,
87} from "../review/nativeReviewDiffAdapter";
88import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
89import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
90import { useNativeReviewDiffBridge } from "../review/useNativeReviewDiffBridge";
91import { pullRequestTimelineRows } from "./PullRequestTimeline";
92import { PullRequestActionToolbar, PullRequestCardGroup } from "./PullRequestControls";
93import {
94 pullRequestTarget as requestTarget,
95 usePullRequestDiff,
96 usePullRequestDiffEntry,
97 type PullRequestDiffParams,
98 type PullRequestParams,
99} from "./usePullRequestDiff";
100import {
101 PullRequestAvatar,
102 PullRequestDiffStats,
103 PullRequestReadStatus,
104} from "./PullRequestPresentation";
105import { usePullRequestFilesSection } from "./PullRequestFiles";
106import { usePullRequestMaintainerEdits } from "./usePullRequestMaintainerEdits";
107import { PullRequestDescription } from "./PullRequestDescription";
108import { PullRequestMediaVisibleContext } from "./PullRequestMedia";
109import { PullRequestMarkdownRepository } from "./PullRequestMarkdown";
110import {
111 PullRequestStatusMenu,
112 PullRequestChecksRow,
113 PullRequestBranchRow,
114 PullRequestReviewersRow,
115} from "./PullRequestStatusRows";
116import { PullRequestMergeControls } from "./PullRequestMergeControls";
117import { PullRequestStackCard } from "./PullRequestStackCard";
118import { usePullRequestStack, type PullRequestStackState } from "./usePullRequestStack";
119import { usePullRequestEnvironmentFallback } from "./usePullRequestEnvironmentFallback";
120import { pullRequestFileJumpScope, subscribePullRequestFileJump } from "./pullRequestFileJump";
121import {
122 capitalizeTerm,
123 sourceControlClients,
124} from "@t3tools/client-runtime/source-control-clients";
125
126const EMPTY_IDS: readonly string[] = [];
127
128function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityFilter) {
129 const navigation = useNavigation();
130 const result = useEnvironmentQuery(composerPullRequests.activity(requestTarget(params)));
131 const detail = useEnvironmentQuery(composerPullRequests.detail(requestTarget(params)));
132 const permissions = usePullRequestPermissions(params, detail.data);
133 const filtered = result.data ? filterPullRequestActivity(result.data, filter) : null;
134 const rows = (() => {
135 if (!filtered) return [];
136 const rows = pullRequestTimelineRows(filtered.activity, params, navigation, {
137 permissions,
138 onChanged: result.refresh,
139 });
140 if (filter.newestFirst) {
141 const notice = rows.at(-1)?.key === "truncated" ? rows.pop() : undefined;
142 rows.reverse();
143 if (notice) rows.push(notice);
144 }
145 if (!rows.length)
146 rows.push({
147 key: "empty",
148 date: "",
149 content: (
150 <Text className="py-6 text-sm text-foreground-muted">
151 No activity matches these filters.
152 </Text>
153 ),
154 });
155 return rows;
156 })();
157 return {
158 rows,
159 hiddenCount: filtered?.hiddenCount ?? 0,
160 pending: result.isPending && !result.data,
161 error: result.error,
162 };
163}
164
165function PullRequestIdentity(props: {
166 readonly pr: PullRequestDetail | PullRequestListEntry | PullRequestSummary;
167 readonly params: PullRequestParams;
168}) {
169 const { pr } = props;
170 const status = pullRequestStatus({ state: pr.state, isDraft: pr.isDraft === true });
171 return (
172 <View className="gap-3">
173 <View className="flex-row flex-wrap items-center gap-2">
174 {"capabilities" in pr ? (
175 <PullRequestStatusMenu pr={pr} params={props.params} />
176 ) : (
177 <View className="min-h-8 flex-row items-center gap-1.5">
178 <SymbolView name={status.icon} size={14} tintColorClassName={status.tint} />
179 <Text className={`text-xs font-t3-medium ${status.text}`}>{status.label}</Text>
180 </View>
181 )}
182 <PullRequestDiffStats additions={pr.additions ?? 0} deletions={pr.deletions ?? 0} compact />
183 {"changedFiles" in pr && pr.changedFiles !== undefined ? (
184 <Text className="text-2xs text-foreground-muted">
185 {pr.changedFiles} {pr.changedFiles === 1 ? "file" : "files"}
186 </Text>
187 ) : (
188 <View className="h-3 w-12 rounded bg-subtle-strong" />
189 )}
190 </View>
191 <Text selectable className="text-xl font-t3-bold leading-7">
192 {pr.title}
193 </Text>
194 <View className="flex-row items-center gap-2">
195 <PullRequestAvatar actor={pr.author ?? null} size={20} />
196 <Text className="min-w-0 flex-1 text-xs font-t3-medium" numberOfLines={1}>
197 {pr.author?.login ?? "Unknown author"}
198 </Text>
199 <Text className="shrink text-right text-2xs text-foreground-muted" numberOfLines={1}>
200 Updated <RelativeTime timestamp={pr.updatedAt} /> ago
201 </Text>
202 </View>
203 <View className="flex-row items-start gap-1.5">
204 <Pressable
205 accessibilityRole="button"
206 accessibilityLabel={`Copy base branch ${pr.baseBranch}`}
207 onPress={() => void Clipboard.setStringAsync(pr.baseBranch)}
208 className="min-w-0 shrink active:opacity-70"
209 hitSlop={8}
210 >
211 <Text className="font-mono text-2xs text-foreground-muted">{pr.baseBranch}</Text>
212 </Pressable>
213 <View className="pt-0.5">
214 <SymbolView name="arrow.left" size={11} tintColorClassName="accent-icon-muted" />
215 </View>
216 <Pressable
217 accessibilityRole="button"
218 accessibilityLabel={`Copy head branch ${pr.headBranch}`}
219 onPress={() => void Clipboard.setStringAsync(pr.headBranch)}
220 className="min-w-0 shrink active:opacity-70"
221 hitSlop={8}
222 >
223 <Text className="font-mono text-2xs text-foreground-muted">{pr.headBranch}</Text>
224 </Pressable>
225 </View>
226 </View>
227 );
228}
229
230function PullRequestLabels(props: {
231 readonly pr: PullRequestDetail;
232 readonly params: PullRequestParams;
233}) {
234 const navigation = useNavigation();
235 const connected = usePullRequestConnected(props.params.environmentId);
236 const canWrite = useAtomValue(
237 composerPullRequests.setLabels.permissionAtom(requestTarget(props.params).environmentId),
238 );
239 const editable =
240 connected &&
241 canWrite &&
242 props.pr.capabilities.labels === true &&
243 props.pr.viewerPermissions.labels !== false;
244 if (!props.pr.labels.length && !editable) return null;
245 return (
246 <Animated.View layout={PR_ROW_LAYOUT} className="flex-row flex-wrap gap-2">
247 {props.pr.labels.map((label) => {
248 const color = pullRequestLabelColor(label.color);
249 // Tinted like the list row's label pills, at the overview's chip size.
250 return (
251 <View
252 key={label.name}
253 className="max-w-full flex-row items-center gap-1.5 rounded-2xl bg-grouped-card px-3 py-1"
254 style={color ? { backgroundColor: `${color}20` } : undefined}
255 >
256 {color ? (
257 <View style={{ width: 6, height: 6, borderRadius: 3, backgroundColor: color }} />
258 ) : null}
259 <Text textRole="caption" className="shrink text-foreground-muted" numberOfLines={1}>
260 {label.name}
261 </Text>
262 </View>
263 );
264 })}
265 {editable ? (
266 <Chip
267 label={props.pr.labels.length ? "Edit" : "Add labels"}
268 icon="tag"
269 size="small"
270 accessibilityLabel="Edit labels"
271 onPress={() => navigation.navigate("PullRequestLabels", props.params)}
272 />
273 ) : null}
274 </Animated.View>
275 );
276}
277
278function PullRequestOverview(props: {
279 readonly pr: PullRequestDetail;
280 readonly description: ReturnType<typeof usePullRequestDescription>;
281 readonly params: PullRequestParams;
282 readonly stack: PullRequestStackState;
283 readonly onDescriptionLayout: (y: number) => void;
284 readonly onDescriptionCollapse: () => void;
285 readonly descriptionExpanded: boolean;
286 readonly onDescriptionExpandedChange: (expanded: boolean) => void;
287}) {
288 const { pr } = props;
289 return (
290 <View className="gap-5">
291 <PullRequestStackCard params={props.params} state={props.stack} />
292 <PullRequestCardGroup>
293 <PullRequestChecksRow pr={pr} params={props.params} />
294 <PullRequestReviewersRow pr={pr} params={props.params} />
295 <Animated.View layout={PR_ROW_LAYOUT}>
296 <PullRequestBranchRow pr={pr} params={props.params} />
297 </Animated.View>
298 <Animated.View layout={PR_ROW_LAYOUT}>
299 <PullRequestMergeControls pr={pr} params={props.params} stack={props.stack} />
300 </Animated.View>
301 </PullRequestCardGroup>
302 <PullRequestLabels pr={pr} params={props.params} />
303 <Animated.View
304 layout={PR_POSITION_LAYOUT}
305 onLayout={(event) => props.onDescriptionLayout(event.nativeEvent.layout.y)}
306 >
307 <PullRequestDescription
308 markdown={props.description.body}
309 onTaskListChange={props.description.toggleTask}
310 onCollapse={props.onDescriptionCollapse}
311 expanded={props.descriptionExpanded}
312 onExpandedChange={props.onDescriptionExpandedChange}
313 footer={<PullRequestReactions params={props.params} />}
314 />
315 </Animated.View>
316 </View>
317 );
318}
319
320function usePullRequestToolbarHeight(bottomInset: number) {
321 const { buttonSize } = useAndroidControlSizing();
322 return useState(() => (Platform.OS === "android" ? bottomInset + buttonSize + 40 : 0));
323}
324
325export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestParams>) {
326 const returnToList = useAndroidWorkspaceBack("pullRequests");
327 const { layout } = useAdaptiveWorkspaceLayout();
328 const navigation = useNavigation();
329 const insets = useSafeAreaInsets();
330 const [toolbarHeight, setToolbarHeight] = usePullRequestToolbarHeight(insets.bottom);
331 const contentTopInset = useContentTopInset();
332 // Only iOS lists run under the bottom safe area; Android's floating toolbar pads its own.
333 const contentBottomInset = Platform.OS === "ios" ? insets.bottom : 0;
334 const params = route.params;
335 usePullRequestEnvironmentFallback(params);
336 const connected = usePullRequestConnected(params.environmentId);
337 const [chosenSection, setSection] = useState<"overview" | "activity" | "guide">("overview");
338 const requestedSection = useRef(chosenSection);
339 const [listAnimationsReady, setListAnimationsReady] = useState(false);
340 const [descriptionExpanded, setDescriptionExpanded] = useState(false);
341 const filesContent = usePullRequestFilesSection(params);
342 const guidesEnabled = useReviewGuidesEnabled(params);
343 // The guide tab goes away while guides are off and overview stands in. The pick is kept, so
344 // guides coming back (a settings reload, a reconnect) return to the guide the user chose.
345 const shown = (tab: typeof chosenSection) =>
346 !guidesEnabled && tab === "guide" ? "overview" : tab;
347 const section = shown(chosenSection);
348 const [activityFilter, setActivityFilter] = useState<ActivityFilter>(DEFAULT_ACTIVITY_FILTER);
349 const activityContent = usePullRequestActivityRows(params, activityFilter);
350 const scrollOffsets = useRef<Record<string, number>>({});
351 // The offset of the tab last shown, and which tab that was: a tab standing in for a hidden guide
352 // has its own offset, which only its next scroll would record here.
353 const currentScrollOffset = useRef<{ tab: typeof section; offset: number }>({
354 tab: "overview",
355 offset: -contentTopInset,
356 });
357 const bodyY = useRef(0);
358 const [headerHeight, setHeaderHeight] = useState(0);
359 const [viewportHeight, setViewportHeight] = useState(0);
360 const scrollViews = useRef<Partial<Record<typeof section, LegendListRef | null>>>({});
361 // AnimatedLegendList re-attaches its handle and sets state whenever its ref changes,
362 // so an inline ref in the tab map loops the screen into "Maximum update depth exceeded".
363 const [listRefs] = useState(() => {
364 const listRef = (tab: typeof section) => (list: LegendListRef | null) => {
365 scrollViews.current[tab] = list;
366 };
367 return {
368 overview: listRef("overview"),
369 guide: listRef("guide"),
370 activity: listRef("activity"),
371 };
372 });
373 const selectSection = (next: typeof section) => {
374 if (next === section) return;
375 const from = shown(requestedSection.current);
376 const current =
377 currentScrollOffset.current.tab === from
378 ? currentScrollOffset.current.offset
379 : (scrollOffsets.current[from] ?? -contentTopInset);
380 scrollOffsets.current[section] = current;
381 const headerEnd = Math.max(-contentTopInset, bodyY.current - contentTopInset);
382 const offset = pullRequestTabOffset(current, scrollOffsets.current[next], headerEnd);
383 requestedSection.current = next;
384 scrollOffsets.current[next] = offset;
385 currentScrollOffset.current = { tab: next, offset };
386 // LegendList clamps to its measured rows, which leave out the short-tab minHeight below.
387 scrollViews.current[next]?.getNativeScrollRef().scrollTo({ y: offset, animated: false });
388 setSection(next);
389 };
390 const tabContent = activityContent;
391 const filesY = useRef(0);
392 const descriptionY = useRef(0);
393 const pendingDescriptionJump = useRef(false);
394 const pendingFilesJump = useRef(false);
395 const detailAtom = composerPullRequests.detail(requestTarget(params));
396 const result = useEnvironmentQuery(detailAtom);
397 const pullRefresh = usePullToRefresh(detailAtom);
398 const { refresh: refreshDetail } = result;
399 useFocusEffect(refreshDetail);
400 const pr = usePullRequestLiveChecks(params, result.data);
401 const summary = params.initialSummary;
402 const identity = pr ?? summary;
403 const terminology = sourceControlClients.get(identity?.provider).changeRequest;
404 const permissions = usePullRequestPermissions(params, pr);
405 const description = usePullRequestDescription(params, pr, permissions.canEditChangeRequest);
406 const action = usePullRequestAction(params, pr);
407 const maintainerEdits = usePullRequestMaintainerEdits(
408 params,
409 pr,
410 permissions.canEditMaintainerEdits,
411 );
412 const showsDeleteBranch = pr !== null && canPerformPullRequestAction(pr, "delete-branch");
413 const stateAction = action.available("close")
414 ? "close"
415 : action.available("reopen")
416 ? "reopen"
417 : null;
418 const runStateAction = () =>
419 stateAction === "close" ? action.confirmClose() : void action.perform("reopen");
420 const confirmDeleteBranch = () =>
421 pr &&
422 action.confirm(
423 "delete-branch",
424 pullRequestActionLabel("delete-branch", terminology),
425 `Delete ${pr.headBranch} from ${pr.headRepositoryNameWithOwner ?? pr.repository}? Local branches and worktrees are not changed.`,
426 );
427 const stack = usePullRequestStack(params, pr);
428 const refreshActivity = useAtomRefresh(composerPullRequests.activity(requestTarget(params)));
429 const refreshGuide = useAtomRefresh(composerPullRequests.reviewGuide(requestTarget(params)));
430 const registry = use(RegistryContext);
431 const refresh = () =>
432 pullRefresh.onRefresh(async (signal) => {
433 const target = requestTarget(params);
434 await composerPullRequests.invalidate
435 .run(registry, {
436 environmentId: target.environmentId,
437 input: { reference: target.input },
438 })
439 .catch(() => undefined);
440 if (signal.aborted) return;
441 if (guidesEnabled) refreshGuide();
442 stack.refresh();
443 refreshActivity();
444 filesContent.refresh();
445 });
446 const jumpToFiles = () => {
447 scrollViews.current.overview?.scrollToOffset({
448 offset: bodyY.current + filesY.current - contentTopInset,
449 animated: true,
450 });
451 pendingFilesJump.current = false;
452 };
453 const openFiles = () => {
454 if (section === "overview") jumpToFiles();
455 else {
456 pendingFilesJump.current = true;
457 selectSection("overview");
458 if (filesY.current > 0) requestAnimationFrame(jumpToFiles);
459 }
460 };
461 return (
462 <PullRequestMarkdownRepository params={params} changeRequest={pr}>
463 <View className="flex-1 android:bg-header ios:bg-screen">
464 <AppBar
465 title={`#${params.number}`}
466 subtitle={connected ? params.repository : `${params.repository} · Offline`}
467 onBack={layout.usesSplitView ? undefined : returnToList}
468 menus={[
469 {
470 title: `${capitalizeTerm(terminology.singular)} actions`,
471 icon: "ellipsis",
472 items: [
473 ...(permissions.verdicts.length
474 ? [
475 {
476 id: "submit-review",
477 title: "Submit review",
478 icon: "text.bubble",
479 onPress: () =>
480 navigation.navigate("PullRequestReview", { ...params, mode: "review" }),
481 },
482 ]
483 : []),
484 ...(permissions.canComment
485 ? [
486 {
487 id: "add-comment",
488 title: "Add comment",
489 icon: "plus.bubble",
490 onPress: () =>
491 navigation.navigate("PullRequestReview", { ...params, mode: "comment" }),
492 },
493 ]
494 : []),
495 ...(permissions.canEditChangeRequest
496 ? [
497 {
498 id: "edit-title",
499 title: "Edit title",
500 icon: "pencil",
501 onPress: () =>
502 navigation.navigate("PullRequestEdit", { ...params, field: "title" }),
503 },
504 {
505 id: "edit-description",
506 title: "Edit description",
507 icon: "doc.text",
508 disabled: description.pending,
509 subtitle: description.pending ? "Saving…" : undefined,
510 onPress: () =>
511 navigation.navigate("PullRequestEdit", { ...params, field: "body" }),
512 },
513 ]
514 : []),
515 ...(maintainerEdits.visible
516 ? [
517 {
518 id: "maintainer-edits",
519 title: "Allow edits from maintainers",
520 icon: "pencil",
521 selected: maintainerEdits.value,
522 disabled: maintainerEdits.saving,
523 subtitle: maintainerEdits.subtitle,
524 onPress: maintainerEdits.toggle,
525 },
526 ]
527 : []),
528 ...(identity
529 ? [
530 {
531 id: "open-on-provider",
532 title: openOnProviderLabel(identity.provider),
533 icon: "arrow.up.right",
534 onPress: () => void Linking.openURL(identity.url),
535 },
536 {
537 id: "copy-link",
538 title: "Copy link",
539 icon: "link",
540 onPress: () => copyPullRequestLink(identity),
541 },
542 {
543 id: "share",
544 title: "Share…",
545 icon: "square.and.arrow.up",
546 onPress: () => sharePullRequestLink(identity),
547 },
548 ]
549 : []),
550 ...(stateAction
551 ? [
552 {
553 id: "state",
554 title: pullRequestActionLabel(stateAction, terminology),
555 icon: PR_ACTION_ICONS[stateAction],
556 destructive: stateAction === "close",
557 onPress: runStateAction,
558 },
559 ]
560 : []),
561 ...(showsDeleteBranch
562 ? [
563 {
564 id: "delete-branch",
565 title: pullRequestActionLabel("delete-branch", terminology),
566 icon: PR_ACTION_ICONS["delete-branch"],
567 destructive: true,
568 disabled: !action.available("delete-branch"),
569 subtitle: action.busy
570 ? "Deleting…"
571 : connected
572 ? pr.headBranch
573 : "Reconnect to delete this branch.",
574 onPress: confirmDeleteBranch,
575 },
576 ]
577 : []),
578 ],
579 },
580 ]}
581 />
582 <ScreenContent onLayout={(event) => setViewportHeight(event.nativeEvent.layout.height)}>
583 {(["overview", "guide", "activity"] as const)
584 .filter((tab) => tab !== "guide" || guidesEnabled)
585 .map((tab) => (
586 <View
587 key={tab}
588 style={[StyleSheet.absoluteFill, { opacity: section === tab ? 1 : 0 }]}
589 pointerEvents={section === tab ? "auto" : "none"}
590 accessibilityElementsHidden={section !== tab}
591 importantForAccessibility={section === tab ? "auto" : "no-hide-descendants"}
592 >
593 <AnimatedLegendList
594 ref={listRefs[tab]}
595 // The scroll view owns its resting offset. LegendList keeps the first
596 // initialScrollOffset it gets, and the first render has the window's top
597 // inset (0 on the folded iPhone Duo), not the header's.
598 onScroll={(event) => {
599 const offset = event.nativeEvent.contentOffset.y;
600 scrollOffsets.current[tab] = offset;
601 if (shown(requestedSection.current) === tab)
602 currentScrollOffset.current = { tab, offset };
603 }}
604 className="flex-1"
605 renderScrollComponent={NativeScrollView}
606 // UIKit owns the bar's inset, so a minimizing bar and a resized column
607 // move the list in the same frame as the bar.
608 contentInsetAdjustmentBehavior="automatic"
609 contentInsetStartAdjustment={contentTopInset}
610 // RN scrollTo clamps against raw insets and ignores the automatic bar inset.
611 scrollToOverflowEnabled
612 refreshControl={
613 <RefreshControl
614 refreshing={section === tab && pullRefresh.refreshing}
615 onRefresh={refresh}
616 />
617 }
618 alwaysBounceVertical
619 scrollsToTop={section === tab}
620 onContentSizeChange={() => {
621 if (
622 tab !== "overview" ||
623 section !== "overview" ||
624 !pendingDescriptionJump.current
625 )
626 return;
627 pendingDescriptionJump.current = false;
628 // Collapse changes the scroll range; restore the heading after that layout commits.
629 scrollViews.current.overview?.scrollToOffset({
630 offset: bodyY.current + descriptionY.current - contentTopInset,
631 animated: false,
632 });
633 }}
634 contentContainerStyle={{
635 paddingHorizontal: 16,
636 paddingTop: 8,
637 paddingBottom: 24 + (Platform.OS === "android" ? toolbarHeight : 0),
638 // Short tabs must still be tall enough to preserve the collapsed header.
639 minHeight: Math.max(
640 0,
641 viewportHeight + headerHeight - contentTopInset - contentBottomInset,
642 ),
643 }}
644 data={[
645 {
646 key: `${tab}:body`,
647 content: (
648 <View>
649 {tab === "overview" && identity ? (
650 <View>
651 <SourceControlAppAccessNotice
652 environmentId={params.environmentId}
653 provider={identity.provider}
654 host={params.host}
655 repository={params.repository}
656 />
657 {pr ? (
658 <PullRequestOverview
659 pr={pr}
660 description={description}
661 params={params}
662 stack={stack}
663 descriptionExpanded={descriptionExpanded}
664 onDescriptionExpandedChange={setDescriptionExpanded}
665 onDescriptionLayout={(y) => {
666 descriptionY.current = y;
667 }}
668 onDescriptionCollapse={() => {
669 pendingDescriptionJump.current = true;
670 }}
671 />
672 ) : summary ? (
673 <PullRequestOverviewLoading
674 summary={summary}
675 params={params}
676 stack={stack}
677 />
678 ) : null}
679 <View
680 className="mt-8 border-t border-border-subtle pt-3"
681 onLayout={(event) => {
682 filesY.current = event.nativeEvent.layout.y;
683 if (pendingFilesJump.current) {
684 requestAnimationFrame(() => {
685 if (shown(requestedSection.current) === "overview")
686 jumpToFiles();
687 });
688 }
689 }}
690 >
691 {filesContent.header}
692 </View>
693 </View>
694 ) : null}
695 {tab === "guide" ? (
696 <PullRequestGuideContent
697 params={params}
698 visible={section === "guide"}
699 />
700 ) : null}
701 {tab === "activity" ? (
702 <PullRequestActivityFilters
703 value={activityFilter}
704 onChange={setActivityFilter}
705 hiddenCount={tabContent.hiddenCount}
706 />
707 ) : null}
708 {tab === "activity" ? (
709 <PullRequestReadStatus
710 pending={tabContent.pending}
711 error={tabContent.error}
712 terminology={terminology}
713 />
714 ) : null}
715 </View>
716 ),
717 },
718 ...(tab === "overview"
719 ? identity
720 ? filesContent.rows
721 : []
722 : tab === "activity"
723 ? tabContent.rows
724 : []
725 ).map((row) => ({
726 ...row,
727 key: `${tab}:${row.key}`,
728 content: row.content,
729 })),
730 ]}
731 keyExtractor={(row) => row.key}
732 getItemType={(row) =>
733 row.key.endsWith(":body") ? row.key : row.key.split(":")[0]
734 }
735 // Animating overview fights clipped markdown and collapse scroll correction; file rows can still fade.
736 itemLayoutAnimation={tab === "overview" ? undefined : PR_ROW_LAYOUT}
737 onLoad={() => setListAnimationsReady(true)}
738 renderItem={({ item }) => (
739 <Animated.View
740 key={item.key}
741 entering={
742 listAnimationsReady && !item.key.endsWith(":body")
743 ? PR_ROW_ENTER
744 : undefined
745 }
746 exiting={
747 listAnimationsReady && !item.key.endsWith(":body") ? PR_ROW_EXIT : undefined
748 }
749 >
750 <PullRequestMediaVisibleContext value={section === tab}>
751 {item.content}
752 </PullRequestMediaVisibleContext>
753 </Animated.View>
754 )}
755 recycleItems={false}
756 estimatedItemSize={tab === "overview" ? 64 : 220}
757 maintainVisibleContentPosition={false}
758 ListHeaderComponent={
759 <>
760 <PullRequestReadStatus
761 pending={result.isPending && !identity}
762 error={result.error}
763 terminology={terminology}
764 />
765 {identity ? (
766 <View
767 className="gap-5 pb-5"
768 onLayout={(event) => {
769 bodyY.current = event.nativeEvent.layout.height;
770 setHeaderHeight(event.nativeEvent.layout.height);
771 }}
772 >
773 <PullRequestIdentity pr={identity} params={params} />
774 {/* UIKit draws the tapped control's glass lens outside the hidden
775 tab's opacity, so only the visible tab mounts the control. */}
776 {Platform.OS !== "ios" || section === tab ? (
777 <SegmentedControl
778 options={[
779 { value: "overview", label: "Overview" },
780 ...(guidesEnabled
781 ? [{ value: "guide" as const, label: "Guide" }]
782 : []),
783 { value: "activity", label: "Activity" },
784 ]}
785 selected={section}
786 onSelect={selectSection}
787 role="tab"
788 size="compact"
789 />
790 ) : (
791 <View style={{ height: 32 }} />
792 )}
793 </View>
794 ) : null}
795 </>
796 }
797 ListFooterComponent={tab === "overview" ? filesContent.footer : null}
798 />
799 </View>
800 ))}
801 </ScreenContent>
802 <PullRequestActionToolbar
803 pr={pr}
804 params={params}
805 onOpenFiles={openFiles}
806 onHeightChange={setToolbarHeight}
807 />
808 </View>
809 </PullRequestMarkdownRepository>
810 );
811}
812
813type PullRequestFileRouteProps = StaticScreenProps<
814 PullRequestDiffParams & {
815 readonly path: string;
816 readonly replacingDraftId?: string;
817 readonly focus?: GuideDiffFocus;
818 }
819>;
820
821export function PullRequestFileRouteScreen(props: PullRequestFileRouteProps) {
822 const navigation =
823 useNavigation<NativeStackNavigationProp<ReactNavigation.RootParamList, "PullRequestFile">>();
824 const ready = usePullRequestDiffEntry(navigation);
825 if (ready) return <PullRequestFileRouteContent {...props} />;
826 const title = props.route.params.commit ? "Commit changes" : "Changes";
827 return (
828 <View className="flex-1 bg-screen">
829 <AppBar title={title} onBack={() => navigation.goBack()} />
830 <View className="flex-1 items-center justify-center">
831 <AppActivityIndicator accessibilityLabel="Loading changes" />
832 </View>
833 </View>
834 );
835}
836
837function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
838 const navigation = useNavigation();
839 const insets = useSafeAreaInsets();
840 const contentTopInset = useContentTopInset();
841 const [toolbarHeight, setToolbarHeight] = usePullRequestToolbarHeight(insets.bottom);
842 const commit = route.params.commit;
843 const detail = useEnvironmentQuery(composerPullRequests.detail(requestTarget(route.params)));
844 const terminology = sourceControlClients.get(
845 (detail.data ?? route.params.initialSummary)?.provider,
846 ).changeRequest;
847 const result = usePullRequestDiff(route.params, terminology);
848 const filter = usePullRequestFileFilter(
849 result.parsed,
850 route.params.focus ? route.params.path : undefined,
851 );
852 const { refresh: refreshDetail } = detail;
853 useFocusEffect(refreshDetail);
854 const { loadMore } = result;
855 const parsed = filter.parsed;
856 const reviewDraft = usePullRequestReviewDraft(route.params);
857 const viewed = usePullRequestFilesViewed(route.params, commit ? null : detail.data);
858 const [commitViewedPaths, setCommitViewedPaths] = useState<ReadonlySet<string>>(() => new Set());
859 const permissions = usePullRequestPermissions(route.params, detail.data);
860 const scopeKey = pullRequestReviewKey(route.params);
861 const [diffHead, setDiffHead] = useState({ scopeKey, sha: detail.data?.headSha ?? null });
862 if (diffHead.scopeKey !== scopeKey || (!diffHead.sha && detail.data?.headSha))
863 setDiffHead({ scopeKey, sha: detail.data?.headSha ?? null });
864 const staleDiff = Boolean(
865 !commit && diffHead.sha && detail.data?.headSha && diffHead.sha !== detail.data.headSha,
866 );
867 const canCommentOnDiff =
868 permissions.canInlineComment &&
869 !commit &&
870 !staleDiff &&
871 !detail.isPending &&
872 !result.isPending &&
873 !result.error;
874 const activity = useEnvironmentQuery(composerPullRequests.activity(requestTarget(route.params)));
875 const baseData = useMemo(() => getCachedNativeReviewDiffData({ parsedDiff: parsed }), [parsed]);
876 const highlightFiles = usePullRequestDiffHighlightFiles(route.params, parsed, baseData.files);
877 const data = useMemo(
878 () =>
879 annotatePullRequestDiff(
880 { ...baseData, files: highlightFiles },
881 staleDiff || commit ? [] : (activity.data?.reviewThreads ?? []),
882 commit ? [] : reviewDraft.draft.comments,
883 diffHead.sha ?? undefined,
884 ),
885 [
886 baseData,
887 highlightFiles,
888 staleDiff,
889 commit,
890 activity.data?.reviewThreads,
891 reviewDraft.draft.comments,
892 diffHead.sha,
893 ],
894 );
895 const viewedIds = data.files
896 .filter((file) => (commit ? commitViewedPaths.has(file.path) : viewed.isViewed(file.path)))
897 .map((file) => file.id);
898 const [selectedRowId, setSelectedRowId] = useState<string | null>(null);
899 const selectedRow = data.rows.find((row) => row.id === selectedRowId);
900 const selectedFile = data.files.find((file) => file.id === selectedRow?.fileId);
901 const commentOnLine = (rowId = selectedRowId) => {
902 const row = data.rows.find((row) => row.id === rowId);
903 const file = data.files.find((file) => file.id === row?.fileId);
904 if (!row || !file || !diffHead.sha || !canCommentOnDiff) return;
905 const position = reviewPosition(row);
906 if (!position) return;
907 const oldPath =
908 parsed.kind === "files"
909 ? parsed.files.find((entry) => entry.id === file.id)?.previousPath
910 : null;
911 if (route.params.replacingDraftId) navigation.setParams({ replacingDraftId: undefined });
912 navigation.navigate("PullRequestInlineComment", {
913 ...route.params,
914 ...(route.params.replacingDraftId ? { draftId: route.params.replacingDraftId } : {}),
915 path: file.path,
916 ...(oldPath ? { oldPath } : {}),
917 position,
918 headSha: diffHead.sha,
919 code: row.content ?? "",
920 });
921 };
922 const [jumpPath, setJumpPath] = useState(route.params.path);
923 const requestedFile =
924 result.parsed.kind === "files"
925 ? result.parsed.files.find((file) => file.path === jumpPath)
926 : undefined;
927 const targetFile =
928 data.files.find((file) => file.path === jumpPath) ??
929 (!jumpPath || requestedFile ? data.files[0] : undefined);
930 const focus = route.params.focus;
931 const focusedRows = guideFocusedRows(data.rows, targetFile?.id, focus);
932 const focusIndex = focusedRows.length
933 ? data.rows.findIndex((row) => row.id === focusedRows[0]?.id)
934 : -1;
935 const [collapsedIds, setCollapsedIds] = useState<readonly string[]>(EMPTY_IDS);
936 const [visibleFileId, setVisibleFileId] = useState<string | null>(null);
937 const nativeView = useRef<NativeReviewDiffViewHandle>(null);
938 // The filter the current jump was made under. Hiding or showing test files replaces the rows,
939 // so a jump made under the other filter has to run again. Native applies the entry
940 // destination before its first viewport, so the first one counts as made.
941 const jumpedUnder = useRef<boolean | null>(filter.hideTestFiles);
942 const hasTestFiles =
943 result.parsed.kind === "files" &&
944 result.parsed.files.some((file) => isTestChangedFile(file.path));
945 const jumpStarted = () =>
946 jumpedUnder.current !== null && (!hasTestFiles || jumpedUnder.current === filter.hideTestFiles);
947 const scrollToFile = (fileId: string) => {
948 if (!nativeView.current) return;
949 jumpedUnder.current = filter.hideTestFiles;
950 void nativeView.current.scrollToFile(fileId, false).catch(() => {
951 jumpedUnder.current = null;
952 });
953 };
954 const jumpScope = pullRequestFileJumpScope(route.params);
955 const jumpToFile = useEffectEvent((path: string) => {
956 setJumpPath(path);
957 setSelectedRowId(null);
958 jumpedUnder.current = null;
959 const file = data.files.find((entry) => entry.path === path);
960 if (!file) return;
961 setCollapsedIds((ids) => ids.filter((id) => id !== file.id));
962 scrollToFile(file.id);
963 });
964 // Subscribed for the whole screen, so a pick made while the diff is still loading is kept for
965 // the first draw.
966 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to pull request file jump requests for the screen's lifetime
967 useEffect(() => subscribePullRequestFileJump(jumpScope, (path) => jumpToFile(path)), [jumpScope]);
968 const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
969 const { themeAppearance, appearance, setCodeWordBreak } = useAppearancePreferences();
970 const bridge = useNativeReviewDiffBridge({
971 threadKey: null,
972 sectionId: `pull-request:${route.params.repository}:${route.params.number}:${commit ?? "all"}`,
973 diff: result.patch,
974 data,
975 collapsedFileIds: collapsedIds,
976 viewedFileIds: viewedIds,
977 selectedRowIds: selectedRowId ? [selectedRowId] : focusedRows.map((row) => row.id),
978 canHighlight: true,
979 });
980 const [NativeDiffView] = useState(() => resolveNativeReviewDiffView());
981 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- requests the next page of the paged diff query until the jump target file has loaded
982 useEffect(() => {
983 if (!targetFile) loadMore();
984 }, [targetFile, loadMore]);
985 const onDebug: NonNullable<NativeReviewDiffViewProps["onDebug"]> = (event) =>
986 handlePullRequestDiffDebugEvent(event, {
987 rowCount: data.rows.length,
988 targetFileId: targetFile?.id,
989 focusIndex,
990 isIos: Platform.OS === "ios",
991 nativeView,
992 jumpStarted,
993 setJumpStarted: (started) => {
994 jumpedUnder.current = started ? filter.hideTestFiles : null;
995 },
996 onDebug: bridge.onDebug,
997 loadMore,
998 });
999 const onToggleFile: NonNullable<NativeReviewDiffViewProps["onToggleFile"]> = (event) => {
1000 const id = event.nativeEvent.fileId;
1001 if (!id) return;
1002 setCollapsedIds((ids) =>
1003 ids.includes(id) ? ids.filter((value) => value !== id) : [...ids, id],
1004 );
1005 };
1006 const visibleFile = data.files.find((file) => file.id === visibleFileId) ?? targetFile;
1007 const toggleTestFiles = () => {
1008 setJumpPath(visibleFile?.path ?? route.params.path);
1009 setSelectedRowId(null);
1010 filter.toggle();
1011 };
1012 const title = commit ? "Commit changes" : "Changes";
1013 const seekingFile = !targetFile && result.nextCursor !== null;
1014 const loadingDiff = (result.isPending && !data.rows.length) || (seekingFile && !result.error);
1015 return (
1016 <View className="flex-1 android:bg-header ios:bg-screen">
1017 <AppBar
1018 title={title}
1019 subtitle={`${commit ? commit.slice(0, 7) : `#${route.params.number}`} · ${data.files.length} ${data.files.length === 1 ? "file" : "files"}${filter.hideTestFiles && filter.hiddenCount ? ` · ${filter.hiddenCount} ${filter.hiddenCount === 1 ? "test" : "tests"} hidden` : ""}`}
1020 onBack={() => navigation.goBack()}
1021 menus={[
1022 {
1023 title: "Diff options",
1024 icon: "ellipsis",
1025 items: [
1026 ...(permissions.verdicts.length
1027 ? [
1028 {
1029 id: "submit-review",
1030 title: "Submit review",
1031 icon: "text.bubble",
1032 onPress: () =>
1033 navigation.navigate("PullRequestReview", {
1034 ...route.params,
1035 mode: "review",
1036 }),
1037 },
1038 ]
1039 : []),
1040 ...(permissions.canComment
1041 ? [
1042 {
1043 id: "comment-on-pr",
1044 title: "Add comment",
1045 icon: "plus.bubble",
1046 onPress: () =>
1047 navigation.navigate("PullRequestReview", {
1048 ...route.params,
1049 mode: "comment",
1050 }),
1051 },
1052 ]
1053 : []),
1054 {
1055 id: "word-wrap",
1056 title: "Word wrap",
1057 icon: "text.alignleft",
1058 selected: appearance.codeWordBreak,
1059 onPress: () => setCodeWordBreak(!appearance.codeWordBreak),
1060 },
1061 {
1062 id: "hide-tests",
1063 title: "Hide test files",
1064 icon: "line.3.horizontal.decrease",
1065 selected: filter.hideTestFiles,
1066 onPress: toggleTestFiles,
1067 },
1068 ...(selectedRow && selectedFile && canCommentOnDiff
1069 ? [
1070 {
1071 id: "comment",
1072 title: route.params.replacingDraftId
1073 ? "Move draft to this line"
1074 : "Add review comment",
1075 icon: "bubble.left",
1076 onPress: () => commentOnLine(),
1077 },
1078 ]
1079 : []),
1080 ...(selectedRow && selectedFile
1081 ? [
1082 {
1083 id: "copy",
1084 title: "Copy line",
1085 icon: "document.on.document",
1086 onPress: () => void Clipboard.setStringAsync(selectedRow.content ?? ""),
1087 },
1088 ]
1089 : []),
1090 ],
1091 },
1092 ]}
1093 />
1094 {route.params.replacingDraftId ? (
1095 <Text className="px-4 py-2 text-xs text-foreground-muted">
1096 Select a current line, then choose “Move draft to this line” from its menu.
1097 </Text>
1098 ) : null}
1099 {viewed.error ? (
1100 <Text className="px-4 py-2 text-xs text-danger-foreground">{viewed.error}</Text>
1101 ) : null}
1102 {staleDiff ? (
1103 <View
1104 className="flex-row items-center gap-2 px-4 py-2"
1105 style={{ paddingTop: contentTopInset + 8 }}
1106 >
1107 <Text className="min-w-0 flex-1 text-xs text-foreground-muted">
1108 The branch changed. Reload before adding line comments.
1109 </Text>
1110 <Button
1111 label="Reload changes"
1112 onPress={() => {
1113 result.refresh();
1114 setDiffHead({ scopeKey, sha: detail.data?.headSha ?? null });
1115 jumpedUnder.current = null;
1116 setSelectedRowId(null);
1117 setCollapsedIds(EMPTY_IDS);
1118 }}
1119 />
1120 </View>
1121 ) : null}
1122 <ScreenContent>
1123 <View className="flex-1" collapsable={false}>
1124 {loadingDiff || result.error ? (
1125 <View style={{ paddingTop: staleDiff ? 0 : contentTopInset }}>
1126 <PullRequestReadStatus
1127 pending={loadingDiff}
1128 error={result.error}
1129 terminology={terminology}
1130 />
1131 </View>
1132 ) : null}
1133 {NativeDiffView && data.rows.length && !seekingFile ? (
1134 <View className="flex-1" collapsable={false}>
1135 <NativeDiffView
1136 {...pullRequestDiffInitialPosition(targetFile?.id, focusIndex)}
1137 nativeViewRef={nativeView}
1138 refreshing={result.refreshing}
1139 onPullToRefresh={result.onPullRefresh}
1140 style={StyleSheet.absoluteFill}
1141 rowsJson={bridge.rowsJson}
1142 themeJson={bridge.themeJson}
1143 styleJson={bridge.styleJson}
1144 tokensPatchJson={bridge.tokensPatchJson}
1145 tokensResetKey={bridge.tokensResetKey}
1146 collapsedFileIdsJson={bridge.collapsedFileIdsJson}
1147 onDebug={onDebug}
1148 viewedFileIdsJson={bridge.viewedFileIdsJson}
1149 selectedRowIdsJson={bridge.selectedRowIdsJson}
1150 onPressLine={(event) => {
1151 const rowId = event.nativeEvent.rowId ?? null;
1152 setSelectedRowId(rowId);
1153 if (event.nativeEvent.gesture !== "longPress") commentOnLine(rowId);
1154 }}
1155 onToggleViewedFile={(event) => {
1156 const file = data.files.find((file) => file.id === event.nativeEvent.fileId);
1157 if (!file || (!commit && !viewed.canToggle)) return;
1158 const wasViewed = commit
1159 ? commitViewedPaths.has(file.path)
1160 : viewed.isViewed(file.path);
1161 setCollapsedIds((ids) =>
1162 wasViewed
1163 ? ids.filter((id) => id !== file.id)
1164 : ids.includes(file.id)
1165 ? ids
1166 : [...ids, file.id],
1167 );
1168 if (commit)
1169 setCommitViewedPaths((current) => {
1170 const next = new Set(current);
1171 if (next.has(file.path)) next.delete(file.path);
1172 else next.add(file.path);
1173 return next;
1174 });
1175 else void viewed.toggle(file.path);
1176 }}
1177 onToggleComment={(event) => {
1178 const id = event.nativeEvent.commentId;
1179 if (id?.startsWith("discussion:"))
1180 navigation.navigate("PullRequestDiscussion", {
1181 ...route.params,
1182 discussionId: id.slice("discussion:".length),
1183 });
1184 if (id?.startsWith("draft:")) {
1185 const draft = reviewDraft.draft.comments.find(
1186 (draft) => draft.id === id.slice("draft:".length),
1187 );
1188 if (draft)
1189 navigation.navigate("PullRequestInlineComment", {
1190 ...route.params,
1191 ...draft,
1192 draftId: draft.id,
1193 });
1194 }
1195 }}
1196 onToggleFile={onToggleFile}
1197 onVisibleFileChange={(event) => setVisibleFileId(event.nativeEvent.fileId ?? null)}
1198 appearanceScheme={themeAppearance}
1199 rowHeight={nativeReviewDiffStyle.rowHeight}
1200 contentWidth={NATIVE_REVIEW_DIFF_CONTENT_WIDTH}
1201 contentInsetTop={staleDiff ? 0 : contentTopInset}
1202 contentInsetBottom={Platform.OS === "android" ? toolbarHeight : insets.bottom}
1203 contentResetKey={`pull-request:${route.params.environmentId}:${route.params.repository}:${route.params.number}:${commit ?? "all"}`}
1204 />
1205 </View>
1206 ) : filter.hiddenCount > 0 &&
1207 !data.rows.length &&
1208 !result.isPending &&
1209 !result.error &&
1210 !seekingFile ? (
1211 <View style={{ paddingTop: contentTopInset }}>
1212 <EmptyState
1213 title="Only test files changed"
1214 detail="Test files are hidden from this review."
1215 action={<Button label="Show test files" tone="contrast" onPress={filter.showAll} />}
1216 variant="plain"
1217 />
1218 </View>
1219 ) : !result.isPending && !result.error && !seekingFile ? (
1220 <EmptyState
1221 title="Diff unavailable"
1222 detail={`Open this ${terminology.singular} on its provider to view the changes.`}
1223 variant="plain"
1224 />
1225 ) : null}
1226 {result.nextCursor && result.isPending && data.rows.length && !seekingFile ? (
1227 <View className="flex-row items-center justify-center gap-2 py-2">
1228 <AppActivityIndicator size="small" />
1229 <Text className="text-xs text-foreground-muted">Loading more files…</Text>
1230 </View>
1231 ) : null}
1232 {result.error && result.nextCursor ? (
1233 <View className="self-center">
1234 <Button label="Retry loading remaining files" tone="text" onPress={result.refresh} />
1235 </View>
1236 ) : null}
1237 {parsed.kind === "files" && parsed.notice ? (
1238 <Text className="px-4 py-2 text-2xs text-foreground-muted">{parsed.notice}</Text>
1239 ) : null}
1240 </View>
1241 </ScreenContent>
1242 <PullRequestActionToolbar
1243 pr={detail.data}
1244 params={route.params}
1245 filePath={visibleFile?.path}
1246 onOpenFiles={() => navigation.navigate("PullRequestFiles", route.params)}
1247 onHeightChange={setToolbarHeight}
1248 />
1249 </View>
1250 );
1251}