Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PullRequestRouteScreen.tsx

1,254 lines53.9 KB

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 };
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 );
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 );
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 );
319​
320function usePullRequestToolbarHeight(bottomInset: number) {
321 const { buttonSize } = useAndroidControlSizing();
322 return useState(() => (Platform.OS === "android" ? bottomInset + buttonSize + 40 : 0));
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 scrollViews.current[next]?.scrollToOffset({ offset, animated: false });
387 setSection(next);
388 };
389 const tabContent = activityContent;
390 const filesY = useRef(0);
391 const descriptionY = useRef(0);
392 const pendingDescriptionJump = useRef(false);
393 const pendingFilesJump = useRef(false);
394 const detailAtom = composerPullRequests.detail(requestTarget(params));
395 const result = useEnvironmentQuery(detailAtom);
396 const pullRefresh = usePullToRefresh(detailAtom);
397 const { refresh: refreshDetail } = result;
398 useFocusEffect(refreshDetail);
399 const pr = usePullRequestLiveChecks(params, result.data);
400 const summary = params.initialSummary;
401 const identity = pr ?? summary;
402 const terminology = sourceControlClients.get(identity?.provider).changeRequest;
403 const permissions = usePullRequestPermissions(params, pr);
404 const description = usePullRequestDescription(params, pr, permissions.canEditChangeRequest);
405 const action = usePullRequestAction(params, pr);
406 const maintainerEdits = usePullRequestMaintainerEdits(
407 params,
408 pr,
409 permissions.canEditMaintainerEdits,
410 );
411 const showsDeleteBranch = pr !== null && canPerformPullRequestAction(pr, "delete-branch");
412 const stateAction = action.available("close")
413 ? "close"
414 : action.available("reopen")
415 ? "reopen"
416 : null;
417 const runStateAction = () =>
418 stateAction === "close" ? action.confirmClose() : void action.perform("reopen");
419 const confirmDeleteBranch = () =>
420 pr &&
421 action.confirm(
422 "delete-branch",
423 pullRequestActionLabel("delete-branch", terminology),
424 `Delete ${pr.headBranch} from ${pr.headRepositoryNameWithOwner ?? pr.repository}? Local branches and worktrees are not changed.`,
425 );
426 const stack = usePullRequestStack(params, pr);
427 const refreshActivity = useAtomRefresh(composerPullRequests.activity(requestTarget(params)));
428 const refreshGuide = useAtomRefresh(composerPullRequests.reviewGuide(requestTarget(params)));
429 const registry = use(RegistryContext);
430 const refresh = () =>
431 pullRefresh.onRefresh(async (signal) => {
432 const target = requestTarget(params);
433 await composerPullRequests.invalidate
434 .run(registry, {
435 environmentId: target.environmentId,
436 input: { reference: target.input },
437 })
438 .catch(() => undefined);
439 if (signal.aborted) return;
440 if (guidesEnabled) refreshGuide();
441 stack.refresh();
442 refreshActivity();
443 filesContent.refresh();
444 });
445 const jumpToFiles = () => {
446 scrollViews.current.overview?.scrollToIndex({
447 index: 0,
448 viewPosition: 0,
449 viewOffset: -filesY.current,
450 animated: true,
451 });
452 pendingFilesJump.current = false;
453 };
454 const openFiles = () => {
455 if (section === "overview") jumpToFiles();
456 else {
457 pendingFilesJump.current = true;
458 selectSection("overview");
459 if (filesY.current > 0) requestAnimationFrame(jumpToFiles);
460 }
461 };
462 return (
463 <PullRequestMarkdownRepository params={params} changeRequest={pr}>
464 <View className="flex-1 android:bg-header ios:bg-screen">
465 <AppBar
466 title={`#${params.number}`}
467 subtitle={connected ? params.repository : `${params.repository} · Offline`}
468 onBack={layout.usesSplitView ? undefined : returnToList}
469 menus={[
470 {
471 title: `${capitalizeTerm(terminology.singular)} actions`,
472 icon: "ellipsis",
473 items: [
474 ...(permissions.verdicts.length
475 ? [
476 {
477 id: "submit-review",
478 title: "Submit review",
479 icon: "text.bubble",
480 onPress: () =>
481 navigation.navigate("PullRequestReview", { ...params, mode: "review" }),
482 },
483 ]
484 : []),
485 ...(permissions.canComment
486 ? [
487 {
488 id: "add-comment",
489 title: "Add comment",
490 icon: "plus.bubble",
491 onPress: () =>
492 navigation.navigate("PullRequestReview", { ...params, mode: "comment" }),
493 },
494 ]
495 : []),
496 ...(permissions.canEditChangeRequest
497 ? [
498 {
499 id: "edit-title",
500 title: "Edit title",
501 icon: "pencil",
502 onPress: () =>
503 navigation.navigate("PullRequestEdit", { ...params, field: "title" }),
504 },
505 {
506 id: "edit-description",
507 title: "Edit description",
508 icon: "doc.text",
509 disabled: description.pending,
510 subtitle: description.pending ? "Saving…" : undefined,
511 onPress: () =>
512 navigation.navigate("PullRequestEdit", { ...params, field: "body" }),
513 },
514 ]
515 : []),
516 ...(maintainerEdits.visible
517 ? [
518 {
519 id: "maintainer-edits",
520 title: "Allow edits from maintainers",
521 icon: "pencil",
522 selected: maintainerEdits.value,
523 disabled: maintainerEdits.saving,
524 subtitle: maintainerEdits.subtitle,
525 onPress: maintainerEdits.toggle,
526 },
527 ]
528 : []),
529 ...(identity
530 ? [
531 {
532 id: "open-on-provider",
533 title: openOnProviderLabel(identity.provider),
534 icon: "arrow.up.right",
535 onPress: () => void Linking.openURL(identity.url),
536 },
537 {
538 id: "copy-link",
539 title: "Copy link",
540 icon: "link",
541 onPress: () => copyPullRequestLink(identity),
542 },
543 {
544 id: "share",
545 title: "Share…",
546 icon: "square.and.arrow.up",
547 onPress: () => sharePullRequestLink(identity),
548 },
549 ]
550 : []),
551 ...(stateAction
552 ? [
553 {
554 id: "state",
555 title: pullRequestActionLabel(stateAction, terminology),
556 icon: PR_ACTION_ICONS[stateAction],
557 destructive: stateAction === "close",
558 onPress: runStateAction,
559 },
560 ]
561 : []),
562 ...(showsDeleteBranch
563 ? [
564 {
565 id: "delete-branch",
566 title: pullRequestActionLabel("delete-branch", terminology),
567 icon: PR_ACTION_ICONS["delete-branch"],
568 destructive: true,
569 disabled: !action.available("delete-branch"),
570 subtitle: action.busy
571 ? "Deleting…"
572 : connected
573 ? pr.headBranch
574 : "Reconnect to delete this branch.",
575 onPress: confirmDeleteBranch,
576 },
577 ]
578 : []),
579 ],
580 },
581 ]}
582 />
583 <ScreenContent onLayout={(event) => setViewportHeight(event.nativeEvent.layout.height)}>
584 {(["overview", "guide", "activity"] as const)
585 .filter((tab) => tab !== "guide" || guidesEnabled)
586 .map((tab) => (
587 <View
588 key={tab}
589 style={[StyleSheet.absoluteFill, { opacity: section === tab ? 1 : 0 }]}
590 pointerEvents={section === tab ? "auto" : "none"}
591 accessibilityElementsHidden={section !== tab}
592 importantForAccessibility={section === tab ? "auto" : "no-hide-descendants"}
593 >
594 <AnimatedLegendList
595 ref={listRefs[tab]}
596 // The scroll view owns its resting offset. LegendList keeps the first
597 // initialScrollOffset it gets, and the first render has the window's top
598 // inset (0 on the folded iPhone Duo), not the header's.
599 onScroll={(event) => {
600 const offset = event.nativeEvent.contentOffset.y;
601 scrollOffsets.current[tab] = offset;
602 if (shown(requestedSection.current) === tab)
603 currentScrollOffset.current = { tab, offset };
604 }}
605 className="flex-1"
606 renderScrollComponent={Platform.OS === "ios" ? NativeScrollView : undefined}
607 contentInsetAdjustmentBehavior="never"
608 contentInset={
609 Platform.OS === "ios"
610 ? { top: contentTopInset, bottom: contentBottomInset }
611 : undefined
612 }
613 refreshControl={
614 <RefreshControl
615 refreshing={section === tab && pullRefresh.refreshing}
616 onRefresh={refresh}
617 />
618 }
619 alwaysBounceVertical
620 scrollsToTop={section === tab}
621 onItemSizeChanged={({ itemKey }) => {
622 if (
623 tab !== "overview" ||
624 section !== "overview" ||
625 itemKey !== "overview:body" ||
626 !pendingDescriptionJump.current
627 )
628 return;
629 pendingDescriptionJump.current = false;
630 scrollViews.current.overview?.scrollToIndex({
631 index: 0,
632 viewPosition: 0,
633 viewOffset: -descriptionY.current,
634 animated: false,
635 });
636 }}
637 contentContainerStyle={{
638 paddingHorizontal: 16,
639 paddingTop: 8,
640 paddingBottom: 24 + (Platform.OS === "android" ? toolbarHeight : 0),
641 // Short tabs must still be tall enough to preserve the collapsed header.
642 minHeight: Math.max(
643 0,
644 viewportHeight + headerHeight - contentTopInset - contentBottomInset,
645 ),
646 }}
647 data={[
648 {
649 key: `${tab}:body`,
650 content: (
651 <View>
652 {tab === "overview" && identity ? (
653 <View>
654 <SourceControlAppAccessNotice
655 environmentId={params.environmentId}
656 provider={identity.provider}
657 host={params.host}
658 repository={params.repository}
659 />
660 {pr ? (
661 <PullRequestOverview
662 pr={pr}
663 description={description}
664 params={params}
665 stack={stack}
666 descriptionExpanded={descriptionExpanded}
667 onDescriptionExpandedChange={setDescriptionExpanded}
668 onDescriptionLayout={(y) => {
669 descriptionY.current = y;
670 }}
671 onDescriptionCollapse={() => {
672 pendingDescriptionJump.current = true;
673 }}
674 />
675 ) : summary ? (
676 <PullRequestOverviewLoading
677 summary={summary}
678 params={params}
679 stack={stack}
680 />
681 ) : null}
682 <View
683 className="mt-8 border-t border-border-subtle pt-3"
684 onLayout={(event) => {
685 filesY.current = event.nativeEvent.layout.y;
686 if (pendingFilesJump.current) {
687 requestAnimationFrame(() => {
688 if (shown(requestedSection.current) === "overview")
689 jumpToFiles();
690 });
691 }
692 }}
693 >
694 {filesContent.header}
695 </View>
696 </View>
697 ) : null}
698 {tab === "guide" ? (
699 <PullRequestGuideContent
700 params={params}
701 visible={section === "guide"}
702 />
703 ) : null}
704 {tab === "activity" ? (
705 <PullRequestActivityFilters
706 value={activityFilter}
707 onChange={setActivityFilter}
708 hiddenCount={tabContent.hiddenCount}
709 />
710 ) : null}
711 {tab === "activity" ? (
712 <PullRequestReadStatus
713 pending={tabContent.pending}
714 error={tabContent.error}
715 terminology={terminology}
716 />
717 ) : null}
718 </View>
719 ),
720 },
721 ...(tab === "overview"
722 ? identity
723 ? filesContent.rows
724 : []
725 : tab === "activity"
726 ? tabContent.rows
727 : []
728 ).map((row) => ({
729 ...row,
730 key: `${tab}:${row.key}`,
731 content: row.content,
732 })),
733 ]}
734 keyExtractor={(row) => row.key}
735 getItemType={(row) =>
736 row.key.endsWith(":body") ? row.key : row.key.split(":")[0]
737 }
738 // Animating overview fights clipped markdown and collapse scroll correction; file rows can still fade.
739 itemLayoutAnimation={tab === "overview" ? undefined : PR_ROW_LAYOUT}
740 onLoad={() => setListAnimationsReady(true)}
741 renderItem={({ item }) => (
742 <Animated.View
743 key={item.key}
744 entering={
745 listAnimationsReady && !item.key.endsWith(":body")
746 ? PR_ROW_ENTER
747 : undefined
748 }
749 exiting={
750 listAnimationsReady && !item.key.endsWith(":body") ? PR_ROW_EXIT : undefined
751 }
752 >
753 <PullRequestMediaVisibleContext value={section === tab}>
754 {item.content}
755 </PullRequestMediaVisibleContext>
756 </Animated.View>
757 )}
758 recycleItems={false}
759 estimatedItemSize={tab === "overview" ? 64 : 220}
760 maintainVisibleContentPosition={false}
761 ListHeaderComponent={
762 <>
763 <PullRequestReadStatus
764 pending={result.isPending && !identity}
765 error={result.error}
766 terminology={terminology}
767 />
768 {identity ? (
769 <View
770 className="gap-5 pb-5"
771 onLayout={(event) => {
772 bodyY.current = event.nativeEvent.layout.height;
773 setHeaderHeight(event.nativeEvent.layout.height);
774 }}
775 >
776 <PullRequestIdentity pr={identity} params={params} />
777 {/* UIKit draws the tapped control's glass lens outside the hidden
778 tab's opacity, so only the visible tab mounts the control. */}
779 {Platform.OS !== "ios" || section === tab ? (
780 <SegmentedControl
781 options={[
782 { value: "overview", label: "Overview" },
783 ...(guidesEnabled
784 ? [{ value: "guide" as const, label: "Guide" }]
785 : []),
786 { value: "activity", label: "Activity" },
787 ]}
788 selected={section}
789 onSelect={selectSection}
790 role="tab"
791 size="compact"
792 />
793 ) : (
794 <View style={{ height: 32 }} />
795 )}
796 </View>
797 ) : null}
798 </>
799 }
800 ListFooterComponent={tab === "overview" ? filesContent.footer : null}
801 />
802 </View>
803 ))}
804 </ScreenContent>
805 <PullRequestActionToolbar
806 pr={pr}
807 params={params}
808 onOpenFiles={openFiles}
809 onHeightChange={setToolbarHeight}
810 />
811 </View>
812 </PullRequestMarkdownRepository>
813 );
815​
816type PullRequestFileRouteProps = StaticScreenProps<
817 PullRequestDiffParams & {
818 readonly path: string;
819 readonly replacingDraftId?: string;
820 readonly focus?: GuideDiffFocus;
821 }
822>;
823​
824export function PullRequestFileRouteScreen(props: PullRequestFileRouteProps) {
825 const navigation =
826 useNavigation<NativeStackNavigationProp<ReactNavigation.RootParamList, "PullRequestFile">>();
827 const ready = usePullRequestDiffEntry(navigation);
828 if (ready) return <PullRequestFileRouteContent {...props} />;
829 const title = props.route.params.commit ? "Commit changes" : "Changes";
830 return (
831 <View className="flex-1 bg-screen">
832 <AppBar title={title} onBack={() => navigation.goBack()} />
833 <View className="flex-1 items-center justify-center">
834 <AppActivityIndicator accessibilityLabel="Loading changes" />
835 </View>
836 </View>
837 );
839​
840function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
841 const navigation = useNavigation();
842 const insets = useSafeAreaInsets();
843 const contentTopInset = useContentTopInset();
844 const [toolbarHeight, setToolbarHeight] = usePullRequestToolbarHeight(insets.bottom);
845 const commit = route.params.commit;
846 const detail = useEnvironmentQuery(composerPullRequests.detail(requestTarget(route.params)));
847 const terminology = sourceControlClients.get(
848 (detail.data ?? route.params.initialSummary)?.provider,
849 ).changeRequest;
850 const result = usePullRequestDiff(route.params, terminology);
851 const filter = usePullRequestFileFilter(
852 result.parsed,
853 route.params.focus ? route.params.path : undefined,
854 );
855 const { refresh: refreshDetail } = detail;
856 useFocusEffect(refreshDetail);
857 const { loadMore } = result;
858 const parsed = filter.parsed;
859 const reviewDraft = usePullRequestReviewDraft(route.params);
860 const viewed = usePullRequestFilesViewed(route.params, commit ? null : detail.data);
861 const [commitViewedPaths, setCommitViewedPaths] = useState<ReadonlySet<string>>(() => new Set());
862 const permissions = usePullRequestPermissions(route.params, detail.data);
863 const scopeKey = pullRequestReviewKey(route.params);
864 const [diffHead, setDiffHead] = useState({ scopeKey, sha: detail.data?.headSha ?? null });
865 if (diffHead.scopeKey !== scopeKey || (!diffHead.sha && detail.data?.headSha))
866 setDiffHead({ scopeKey, sha: detail.data?.headSha ?? null });
867 const staleDiff = Boolean(
868 !commit && diffHead.sha && detail.data?.headSha && diffHead.sha !== detail.data.headSha,
869 );
870 const canCommentOnDiff =
871 permissions.canInlineComment &&
872 !commit &&
873 !staleDiff &&
874 !detail.isPending &&
875 !result.isPending &&
876 !result.error;
877 const activity = useEnvironmentQuery(composerPullRequests.activity(requestTarget(route.params)));
878 const baseData = useMemo(() => getCachedNativeReviewDiffData({ parsedDiff: parsed }), [parsed]);
879 const highlightFiles = usePullRequestDiffHighlightFiles(route.params, parsed, baseData.files);
880 const data = useMemo(
881 () =>
882 annotatePullRequestDiff(
883 { ...baseData, files: highlightFiles },
884 staleDiff || commit ? [] : (activity.data?.reviewThreads ?? []),
885 commit ? [] : reviewDraft.draft.comments,
886 diffHead.sha ?? undefined,
887 ),
888 [
889 baseData,
890 highlightFiles,
891 staleDiff,
892 commit,
893 activity.data?.reviewThreads,
894 reviewDraft.draft.comments,
895 diffHead.sha,
896 ],
897 );
898 const viewedIds = data.files
899 .filter((file) => (commit ? commitViewedPaths.has(file.path) : viewed.isViewed(file.path)))
900 .map((file) => file.id);
901 const [selectedRowId, setSelectedRowId] = useState<string | null>(null);
902 const selectedRow = data.rows.find((row) => row.id === selectedRowId);
903 const selectedFile = data.files.find((file) => file.id === selectedRow?.fileId);
904 const commentOnLine = (rowId = selectedRowId) => {
905 const row = data.rows.find((row) => row.id === rowId);
906 const file = data.files.find((file) => file.id === row?.fileId);
907 if (!row || !file || !diffHead.sha || !canCommentOnDiff) return;
908 const position = reviewPosition(row);
909 if (!position) return;
910 const oldPath =
911 parsed.kind === "files"
912 ? parsed.files.find((entry) => entry.id === file.id)?.previousPath
913 : null;
914 if (route.params.replacingDraftId) navigation.setParams({ replacingDraftId: undefined });
915 navigation.navigate("PullRequestInlineComment", {
916 ...route.params,
917 ...(route.params.replacingDraftId ? { draftId: route.params.replacingDraftId } : {}),
918 path: file.path,
919 ...(oldPath ? { oldPath } : {}),
920 position,
921 headSha: diffHead.sha,
922 code: row.content ?? "",
923 });
924 };
925 const [jumpPath, setJumpPath] = useState(route.params.path);
926 const requestedFile =
927 result.parsed.kind === "files"
928 ? result.parsed.files.find((file) => file.path === jumpPath)
929 : undefined;
930 const targetFile =
931 data.files.find((file) => file.path === jumpPath) ??
932 (!jumpPath || requestedFile ? data.files[0] : undefined);
933 const focus = route.params.focus;
934 const focusedRows = guideFocusedRows(data.rows, targetFile?.id, focus);
935 const focusIndex = focusedRows.length
936 ? data.rows.findIndex((row) => row.id === focusedRows[0]?.id)
937 : -1;
938 const [collapsedIds, setCollapsedIds] = useState<readonly string[]>(EMPTY_IDS);
939 const [visibleFileId, setVisibleFileId] = useState<string | null>(null);
940 const nativeView = useRef<NativeReviewDiffViewHandle>(null);
941 // The filter the current jump was made under. Hiding or showing test files replaces the rows,
942 // so a jump made under the other filter has to run again. Native applies the entry
943 // destination before its first viewport, so the first one counts as made.
944 const jumpedUnder = useRef<boolean | null>(filter.hideTestFiles);
945 const hasTestFiles =
946 result.parsed.kind === "files" &&
947 result.parsed.files.some((file) => isTestChangedFile(file.path));
948 const jumpStarted = () =>
949 jumpedUnder.current !== null && (!hasTestFiles || jumpedUnder.current === filter.hideTestFiles);
950 const scrollToFile = (fileId: string) => {
951 if (!nativeView.current) return;
952 jumpedUnder.current = filter.hideTestFiles;
953 void nativeView.current.scrollToFile(fileId, false).catch(() => {
954 jumpedUnder.current = null;
955 });
956 };
957 const jumpScope = pullRequestFileJumpScope(route.params);
958 const jumpToFile = useEffectEvent((path: string) => {
959 setJumpPath(path);
960 setSelectedRowId(null);
961 jumpedUnder.current = null;
962 const file = data.files.find((entry) => entry.path === path);
963 if (!file) return;
964 setCollapsedIds((ids) => ids.filter((id) => id !== file.id));
965 scrollToFile(file.id);
966 });
967 // Subscribed for the whole screen, so a pick made while the diff is still loading is kept for
968 // the first draw.
969 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to pull request file jump requests for the screen's lifetime
970 useEffect(() => subscribePullRequestFileJump(jumpScope, (path) => jumpToFile(path)), [jumpScope]);
971 const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
972 const { themeAppearance, appearance, setCodeWordBreak } = useAppearancePreferences();
973 const bridge = useNativeReviewDiffBridge({
974 threadKey: null,
975 sectionId: `pull-request:${route.params.repository}:${route.params.number}:${commit ?? "all"}`,
976 diff: result.patch,
977 data,
978 collapsedFileIds: collapsedIds,
979 viewedFileIds: viewedIds,
980 selectedRowIds: selectedRowId ? [selectedRowId] : focusedRows.map((row) => row.id),
981 canHighlight: true,
982 });
983 const [NativeDiffView] = useState(() => resolveNativeReviewDiffView());
984 // 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
985 useEffect(() => {
986 if (!targetFile) loadMore();
987 }, [targetFile, loadMore]);
988 const onDebug: NonNullable<NativeReviewDiffViewProps["onDebug"]> = (event) =>
989 handlePullRequestDiffDebugEvent(event, {
990 rowCount: data.rows.length,
991 targetFileId: targetFile?.id,
992 focusIndex,
993 isIos: Platform.OS === "ios",
994 nativeView,
995 jumpStarted,
996 setJumpStarted: (started) => {
997 jumpedUnder.current = started ? filter.hideTestFiles : null;
998 },
999 onDebug: bridge.onDebug,
1000 loadMore,
1001 });
1002 const onToggleFile: NonNullable<NativeReviewDiffViewProps["onToggleFile"]> = (event) => {
1003 const id = event.nativeEvent.fileId;
1004 if (!id) return;
1005 setCollapsedIds((ids) =>
1006 ids.includes(id) ? ids.filter((value) => value !== id) : [...ids, id],
1007 );
1008 };
1009 const visibleFile = data.files.find((file) => file.id === visibleFileId) ?? targetFile;
1010 const toggleTestFiles = () => {
1011 setJumpPath(visibleFile?.path ?? route.params.path);
1012 setSelectedRowId(null);
1013 filter.toggle();
1014 };
1015 const title = commit ? "Commit changes" : "Changes";
1016 const seekingFile = !targetFile && result.nextCursor !== null;
1017 const loadingDiff = (result.isPending && !data.rows.length) || (seekingFile && !result.error);
1018 return (
1019 <View className="flex-1 android:bg-header ios:bg-screen">
1020 <AppBar
1021 title={title}
1022 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` : ""}`}
1023 onBack={() => navigation.goBack()}
1024 menus={[
1026 title: "Diff options",
1027 icon: "ellipsis",
1028 items: [
1029 ...(permissions.verdicts.length
1030 ? [
1032 id: "submit-review",
1033 title: "Submit review",
1034 icon: "text.bubble",
1035 onPress: () =>
1036 navigation.navigate("PullRequestReview", {
1037 ...route.params,
1038 mode: "review",
1039 }),
1040 },
1042 : []),
1043 ...(permissions.canComment
1044 ? [
1046 id: "comment-on-pr",
1047 title: "Add comment",
1048 icon: "plus.bubble",
1049 onPress: () =>
1050 navigation.navigate("PullRequestReview", {
1051 ...route.params,
1052 mode: "comment",
1053 }),
1054 },
1056 : []),
1058 id: "word-wrap",
1059 title: "Word wrap",
1060 icon: "text.alignleft",
1061 selected: appearance.codeWordBreak,
1062 onPress: () => setCodeWordBreak(!appearance.codeWordBreak),
1063 },
1065 id: "hide-tests",
1066 title: "Hide test files",
1067 icon: "line.3.horizontal.decrease",
1068 selected: filter.hideTestFiles,
1069 onPress: toggleTestFiles,
1070 },
1071 ...(selectedRow && selectedFile && canCommentOnDiff
1072 ? [
1074 id: "comment",
1075 title: route.params.replacingDraftId
1076 ? "Move draft to this line"
1077 : "Add review comment",
1078 icon: "bubble.left",
1079 onPress: () => commentOnLine(),
1080 },
1082 : []),
1083 ...(selectedRow && selectedFile
1084 ? [
1086 id: "copy",
1087 title: "Copy line",
1088 icon: "document.on.document",
1089 onPress: () => void Clipboard.setStringAsync(selectedRow.content ?? ""),
1090 },
1092 : []),
1093 ],
1094 },
1095 ]}
1096 />
1097 {route.params.replacingDraftId ? (
1098 <Text className="px-4 py-2 text-xs text-foreground-muted">
1099 Select a current line, then choose “Move draft to this line” from its menu.
1100 </Text>
1101 ) : null}
1102 {viewed.error ? (
1103 <Text className="px-4 py-2 text-xs text-danger-foreground">{viewed.error}</Text>
1104 ) : null}
1105 {staleDiff ? (
1106 <View
1107 className="flex-row items-center gap-2 px-4 py-2"
1108 style={{ paddingTop: contentTopInset + 8 }}
1110 <Text className="min-w-0 flex-1 text-xs text-foreground-muted">
1111 The branch changed. Reload before adding line comments.
1112 </Text>
1113 <Button
1114 label="Reload changes"
1115 onPress={() => {
1116 result.refresh();
1117 setDiffHead({ scopeKey, sha: detail.data?.headSha ?? null });
1118 jumpedUnder.current = null;
1119 setSelectedRowId(null);
1120 setCollapsedIds(EMPTY_IDS);
1121 }}
1122 />
1123 </View>
1124 ) : null}
1125 <ScreenContent>
1126 <View className="flex-1" collapsable={false}>
1127 {loadingDiff || result.error ? (
1128 <View style={{ paddingTop: staleDiff ? 0 : contentTopInset }}>
1129 <PullRequestReadStatus
1130 pending={loadingDiff}
1131 error={result.error}
1132 terminology={terminology}
1133 />
1134 </View>
1135 ) : null}
1136 {NativeDiffView && data.rows.length && !seekingFile ? (
1137 <View className="flex-1" collapsable={false}>
1138 <NativeDiffView
1139 {...pullRequestDiffInitialPosition(targetFile?.id, focusIndex)}
1140 nativeViewRef={nativeView}
1141 refreshing={result.refreshing}
1142 onPullToRefresh={result.onPullRefresh}
1143 style={StyleSheet.absoluteFill}
1144 rowsJson={bridge.rowsJson}
1145 themeJson={bridge.themeJson}
1146 styleJson={bridge.styleJson}
1147 tokensPatchJson={bridge.tokensPatchJson}
1148 tokensResetKey={bridge.tokensResetKey}
1149 collapsedFileIdsJson={bridge.collapsedFileIdsJson}
1150 onDebug={onDebug}
1151 viewedFileIdsJson={bridge.viewedFileIdsJson}
1152 selectedRowIdsJson={bridge.selectedRowIdsJson}
1153 onPressLine={(event) => {
1154 const rowId = event.nativeEvent.rowId ?? null;
1155 setSelectedRowId(rowId);
1156 if (event.nativeEvent.gesture !== "longPress") commentOnLine(rowId);
1157 }}
1158 onToggleViewedFile={(event) => {
1159 const file = data.files.find((file) => file.id === event.nativeEvent.fileId);
1160 if (!file || (!commit && !viewed.canToggle)) return;
1161 const wasViewed = commit
1162 ? commitViewedPaths.has(file.path)
1163 : viewed.isViewed(file.path);
1164 setCollapsedIds((ids) =>
1165 wasViewed
1166 ? ids.filter((id) => id !== file.id)
1167 : ids.includes(file.id)
1168 ? ids
1169 : [...ids, file.id],
1170 );
1171 if (commit)
1172 setCommitViewedPaths((current) => {
1173 const next = new Set(current);
1174 if (next.has(file.path)) next.delete(file.path);
1175 else next.add(file.path);
1176 return next;
1177 });
1178 else void viewed.toggle(file.path);
1179 }}
1180 onToggleComment={(event) => {
1181 const id = event.nativeEvent.commentId;
1182 if (id?.startsWith("discussion:"))
1183 navigation.navigate("PullRequestDiscussion", {
1184 ...route.params,
1185 discussionId: id.slice("discussion:".length),
1186 });
1187 if (id?.startsWith("draft:")) {
1188 const draft = reviewDraft.draft.comments.find(
1189 (draft) => draft.id === id.slice("draft:".length),
1190 );
1191 if (draft)
1192 navigation.navigate("PullRequestInlineComment", {
1193 ...route.params,
1194 ...draft,
1195 draftId: draft.id,
1196 });
1198 }}
1199 onToggleFile={onToggleFile}
1200 onVisibleFileChange={(event) => setVisibleFileId(event.nativeEvent.fileId ?? null)}
1201 appearanceScheme={themeAppearance}
1202 rowHeight={nativeReviewDiffStyle.rowHeight}
1203 contentWidth={NATIVE_REVIEW_DIFF_CONTENT_WIDTH}
1204 contentInsetTop={staleDiff ? 0 : contentTopInset}
1205 contentInsetBottom={Platform.OS === "android" ? toolbarHeight : insets.bottom}
1206 contentResetKey={`pull-request:${route.params.environmentId}:${route.params.repository}:${route.params.number}:${commit ?? "all"}`}
1207 />
1208 </View>
1209 ) : filter.hiddenCount > 0 &&
1210 !data.rows.length &&
1211 !result.isPending &&
1212 !result.error &&
1213 !seekingFile ? (
1214 <View style={{ paddingTop: contentTopInset }}>
1215 <EmptyState
1216 title="Only test files changed"
1217 detail="Test files are hidden from this review."
1218 action={<Button label="Show test files" tone="contrast" onPress={filter.showAll} />}
1219 variant="plain"
1220 />
1221 </View>
1222 ) : !result.isPending && !result.error && !seekingFile ? (
1223 <EmptyState
1224 title="Diff unavailable"
1225 detail={`Open this ${terminology.singular} on its provider to view the changes.`}
1226 variant="plain"
1227 />
1228 ) : null}
1229 {result.nextCursor && result.isPending && data.rows.length && !seekingFile ? (
1230 <View className="flex-row items-center justify-center gap-2 py-2">
1231 <AppActivityIndicator size="small" />
1232 <Text className="text-xs text-foreground-muted">Loading more files…</Text>
1233 </View>
1234 ) : null}
1235 {result.error && result.nextCursor ? (
1236 <View className="self-center">
1237 <Button label="Retry loading remaining files" tone="text" onPress={result.refresh} />
1238 </View>
1239 ) : null}
1240 {parsed.kind === "files" && parsed.notice ? (
1241 <Text className="px-4 py-2 text-2xs text-foreground-muted">{parsed.notice}</Text>
1242 ) : null}
1243 </View>
1244 </ScreenContent>
1245 <PullRequestActionToolbar
1246 pr={detail.data}
1247 params={route.params}
1248 filePath={visibleFile?.path}
1249 onOpenFiles={() => navigation.navigate("PullRequestFiles", route.params)}
1250 onHeightChange={setToolbarHeight}
1251 />
1252 </View>
1253 );