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

PullRequestRouteScreen.tsx

1,242 lines51.4 KB

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