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