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

ReviewSheet.tsx

817 lines30.2 KB

1import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
2import { AsyncResult } from "effect/reactivity";
3import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
4import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
5import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
6import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
7import { AppBar } from "../../components/ui/AppBar";
8import type { AppBarMenuItem } from "../../components/ui/AppBar.types";
9import type { ReviewSectionItem } from "./reviewModel";
10import { useReviewHeaderPresentation } from "./useReviewHeaderPresentation";
11import { type Ref, type ReactElement, useImperativeHandle, useRef, useState } from "react";
12import {
13 FlatList,
14 Platform,
15 Pressable,
16 RefreshControl,
17 ScrollView,
18 type NativeSyntheticEvent,
19 StyleSheet,
20 View,
21} from "react-native";
22import { useSafeAreaInsets } from "react-native-safe-area-context";
23import { useReduceMotionEnabled } from "../../lib/appState";
24import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
25import { useContentTopInset } from "../../components/ui/useBarInset";
26import { NativeScrollView } from "../../native/NativeScrollViewMarker";
27​
28import { AppText as Text } from "../../components/ui/AppText";
29import { SymbolView } from "../../components/ui/AppSymbol";
30import { ScreenContent } from "../../components/ui/ScreenContent";
31import { cn } from "../../lib/cn";
32import { environmentCatalog } from "../../connection/catalog";
33import { useEnvironmentPresentation } from "../../state/presentation";
34import { useAtomCommand } from "../../state/use-atom-command";
35import { useThreadDraftForThread } from "../../state/use-thread-composer-state";
36import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
37import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
38import {
39 Inspector,
40 useAdaptiveWorkspaceLayout,
41 useWorkspacePaneState,
42} from "../layout/AdaptiveWorkspaceLayout";
43import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree";
44import { useReviewCacheForThread } from "./reviewState";
45import {
46 isNativeReviewDiffDrawEvent,
47 type NativeReviewDiffViewHandle,
48 resolveNativeReviewDiffView,
49} from "../diffs/nativeReviewDiffSurface";
50import { NATIVE_REVIEW_DIFF_CONTENT_WIDTH } from "./nativeReviewDiffAdapter";
51import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
52import { useReviewDiffData } from "./useReviewDiffData";
53import { useReviewDiffPrewarming } from "./useReviewDiffPrewarming";
54import { useReviewFileVisibility } from "./reviewFileVisibility";
55import { useReviewSections } from "./useReviewSections";
56import { useNativeReviewDiffBridge } from "./useNativeReviewDiffBridge";
57import { useReviewCommentSelectionController } from "./useReviewCommentSelectionController";
58import { resolveReviewAvailability } from "./reviewAvailability";
59import { resolveSelectedReviewFileId } from "./reviewPaneSelection";
60import { buildReviewSectionMenu } from "./review-section-menu";
61import { reportShowcaseSceneRendered } from "../showcase/showcaseRenderSignal";
62import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
63​
64function ReviewHeader(
65 props: Parameters<typeof useReviewHeaderPresentation>[0] & {
66 readonly sectionMenu: ReturnType<typeof buildReviewSectionMenu>;
67 readonly showSectionToolbar: boolean;
68 readonly showChangedFilesToggle: boolean;
69 readonly onSelectSection: (sectionId: string) => void;
70 readonly onReturnToThread: () => void;
71 },
72) {
73 const { toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
74 const { panes } = useWorkspacePaneState();
75 const presentation = useReviewHeaderPresentation(props);
76 const sectionAction = (section: ReviewSectionItem | null, title: string): AppBarMenuItem => ({
77 id: section ? `section:${section.id}` : `unavailable:${title}`,
78 title,
79 disabled: section === null,
80 selected: section !== null && section.id === props.selectedSection?.id,
81 onPress: () => {
82 if (section) props.onSelectSection(section.id);
83 },
84 });
85 return (
86 <AppBar
87 title={presentation.title}
88 subtitle={presentation.subtitle}
89 onBack={props.onReturnToThread}
90 hideBottomBorder
91 backInSplitView={{ accessibilityLabel: "Back to chat", icon: "chevron.left" }}
92 actions={
93 props.showChangedFilesToggle
94 ? [
95 {
96 accessibilityLabel: panes.auxiliaryPaneVisible
97 ? "Hide changed files"
98 : "Show changed files",
99 icon: "sidebar.right",
100 selected: panes.auxiliaryPaneVisible,
101 onPress: toggleAuxiliaryPane,
102 },
103 ]
104 : undefined
105 }
106 menus={[
107 ...(presentation.gitMenu ? [presentation.gitMenu] : []),
108 ...(props.showSectionToolbar
109 ? [
110 {
111 title: "Select diff",
112 icon: presentation.menuIcon,
113 items: [
114 {
115 id: "sections",
116 inline: true,
117 items: [
118 sectionAction(props.sectionMenu.branchChanges, "Changes"),
119 sectionAction(props.sectionMenu.workingTree, "Uncommitted"),
120 sectionAction(props.sectionMenu.latestTurn, "Latest turn"),
121 ],
122 },
123 ...(props.sectionMenu.turns.length > 0
124 ? [
125 {
126 id: "turns",
127 title: "Turn",
128 items: props.sectionMenu.turns.map((section) => ({
129 id: `section:${section.id}`,
130 title: section.title,
131 subtitle: section.subtitle ?? undefined,
132 selected: section.id === props.selectedSection?.id,
133 onPress: () => props.onSelectSection(section.id),
134 })),
135 },
136 ]
137 : []),
138 ...(presentation.refreshAction ? [presentation.refreshAction] : []),
139 ],
140 },
141 ]
142 : []),
143 ]}
144 />
145 );
147​
148const SHOWCASE_ENABLED = process.env.EXPO_PUBLIC_SHOWCASE === "1";
149​
150const ReviewNotice = function ReviewNotice(props: { readonly notice: string }) {
151 return (
152 <View
153 className={cn(
154 "bg-warning px-4 py-3",
155 Platform.OS === "android" ? "m-2 rounded-[20px]" : "border-b border-warning-border",
156 )}
157 >
158 <Text className="text-xs font-t3-bold uppercase text-warning-foreground">Partial diff</Text>
159 <Text className="text-xs leading-normal text-warning-foreground">{props.notice}</Text>
160 </View>
161 );
162};
163​
164function ReviewSelectionActionBar(props: {
165 readonly bottomInset: number;
166 readonly title: string | null;
167 readonly onOpenComment: (() => void) | null;
168 readonly onClear: () => void;
169}) {
170 if (!props.title) {
171 return null;
172 }
173​
174 const content = (
175 <>
176 <SymbolView
177 name={props.onOpenComment ? "text.bubble" : "line.3.horizontal.decrease.circle"}
178 size={16}
179 tintColorClassName="accent-primary-foreground"
180 type="monochrome"
181 />
182 <Text className="text-base font-t3-bold text-primary-foreground">{props.title}</Text>
183 </>
184 );
185​
186 return (
187 <View
188 pointerEvents="box-none"
189 style={{
190 position: "absolute",
191 left: 18,
192 right: 18,
193 bottom: Math.max(props.bottomInset, 10) + 18,
194 flexDirection: "row",
195 justifyContent: "center",
196 gap: 10,
197 }}
198 >
199 {props.onOpenComment ? (
200 <Pressable
201 className="h-12 flex-1 flex-row items-center justify-center gap-2 rounded-full bg-primary px-5"
202 onPress={props.onOpenComment}
203 >
204 {content}
205 </Pressable>
206 ) : (
207 <View className="h-12 flex-1 flex-row items-center justify-center gap-2 rounded-full bg-primary px-5">
208 {content}
209 </View>
210 )}
211​
212 <Pressable
213 className="h-12 w-12 items-center justify-center rounded-full bg-primary"
214 onPress={props.onClear}
215 >
216 <SymbolView
217 name="xmark"
218 size={16}
219 tintColorClassName="accent-primary-foreground"
220 type="monochrome"
221 />
222 </Pressable>
223 </View>
224 );
226​
227interface ReviewNavigatorFile {
228 readonly id: string;
229 readonly path: string;
230 readonly additions: number;
231 readonly deletions: number;
233​
234const ReviewFileNavigatorRow = function ReviewFileNavigatorRow(props: {
235 readonly file: ReviewNavigatorFile;
236 readonly selected: boolean;
237 readonly onSelectFile: (fileId: string | null) => void;
238}) {
239 const { file, selected, onSelectFile } = props;
240 const handlePress = () => {
241 onSelectFile(selected ? null : file.id);
242 };
243​
244 return (
245 <Pressable
246 accessibilityRole="button"
247 accessibilityState={{ selected }}
248 className={
249 Platform.OS === "android"
250 ? cn(
251 "mt-1 min-h-12 justify-center rounded-[20px] px-3 py-2 active:bg-subtle",
252 selected && "bg-subtle-strong",
253 )
254 : selected
255 ? "mt-1 min-h-12 justify-center rounded-xl bg-subtle-strong px-3 py-2"
256 : "mt-1 min-h-12 justify-center rounded-xl px-3 py-2 active:bg-subtle"
257 }
258 onPress={handlePress}
259 >
260 <Text
261 className={
262 selected
263 ? "text-xs font-t3-bold text-foreground"
264 : "text-xs font-t3-medium text-foreground-secondary"
265 }
266 numberOfLines={2}
267 >
268 {file.path}
269 </Text>
270 <View className="mt-1 flex-row gap-2">
271 <Text className="text-2xs font-t3-bold text-adaptive-emerald-700-300">
272 +{formatDiffCount(file.additions)}
273 </Text>
274 <Text className="text-2xs font-t3-bold text-adaptive-rose-700-300">
275 -{formatDiffCount(file.deletions)}
276 </Text>
277 </View>
278 </Pressable>
279 );
280};
281​
282interface ReviewFileNavigatorHandle {
283 readonly setVisibleFile: (fileId: string | null) => void;
285​
286interface ReviewFileNavigatorProps {
287 readonly files: ReadonlyArray<ReviewNavigatorFile>;
288 readonly sectionId: string | null;
289 readonly onSelectFile: (fileId: string | null) => void;
290 readonly ref?: Ref<ReviewFileNavigatorHandle>;
292​
293function ReviewFileNavigator({ files, sectionId, onSelectFile, ref }: ReviewFileNavigatorProps) {
294 const [fileSelection, setFileSelection] = useState<{
295 readonly sectionId: string | null;
296 readonly fileId: string | null;
297 }>({ sectionId: null, fileId: null });
298 const availableFileIds = files.map((file) => file.id);
299 const selectedFileId = resolveSelectedReviewFileId({
300 selection: fileSelection,
301 sectionId,
302 availableFileIds,
303 });
304​
305 useImperativeHandle(
306 ref,
307 () => ({
308 setVisibleFile: (fileId) => {
309 if (fileId !== null && !availableFileIds.includes(fileId)) {
310 return;
311 }
312 setFileSelection((current) => {
313 if (current.sectionId === sectionId && current.fileId === fileId) {
314 return current;
315 }
316 return { sectionId, fileId };
317 });
318 },
319 }),
320 [availableFileIds, sectionId],
321 );
322​
323 const handleSelectFile = (fileId: string | null) => {
324 setFileSelection({ sectionId, fileId });
325 onSelectFile(fileId);
326 };
327​
328 const renderFile = ({ item }: { readonly item: ReviewNavigatorFile }) => (
329 <ReviewFileNavigatorRow
330 file={item}
331 selected={selectedFileId === item.id}
332 onSelectFile={handleSelectFile}
333 />
334 );
335​
336 return (
337 <View className="flex-1 ios:bg-sheet android:bg-header">
338 <AppBar
339 title="Changed files"
340 subtitle={`${files.length} ${files.length === 1 ? "file" : "files"}`}
341 hideBottomBorder
342 />
343 <ScreenContent insetHorizontal>
344 <FlatList
345 renderScrollComponent={NativeScrollView}
346 data={files}
347 extraData={selectedFileId}
348 keyExtractor={(file) => file.id}
349 contentInsetAdjustmentBehavior="automatic"
350 contentContainerStyle={{ paddingHorizontal: 8, paddingVertical: 8 }}
351 renderItem={renderFile}
352 />
353 </ScreenContent>
354 </View>
355 );
357​
358type ReviewSheetProps = StaticScreenProps<{
359 readonly environmentId: EnvironmentId;
360 readonly threadId: ThreadId;
361}>;
362​
363export function ReviewSheet(props: ReviewSheetProps) {
364 const reduceMotion = useReduceMotionEnabled();
365 const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
366 const { panes } = useWorkspacePaneState();
367 const navigation = useNavigation();
368 const selectDetail = useSelectWorkspaceDetail();
369 const insets = useSafeAreaInsets();
370 const { themeAppearance: selectedTheme } = useAppearancePreferences();
371 const { environmentId, threadId } = props.route.params;
372 const environment = useEnvironmentPresentation(environmentId);
373 const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
374 const isEnvironmentReady = environment.presentation?.connection.phase === "connected";
375 const { draftMessage, draftContext } = useThreadDraftForThread({ environmentId, threadId });
376 const reviewCache = useReviewCacheForThread({ environmentId, threadId });
377 const { selectedThreadCwd } = useSelectedThreadWorktree();
378 const columnMetrics = useNativeColumnLayoutMetrics();
379 const safeArea = columnMetrics?.safeArea ?? insets;
380 const topContentInset = useContentTopInset();
381 const bottomContentInset =
382 Platform.OS === "ios" ? safeArea.bottom + 8 : Math.max(insets.bottom, 18) + 18;
383​
384 const {
385 error,
386 reviewSections,
387 selectedSection,
388 refreshSelectedSection,
389 selectSection,
390 isSelectedSectionPending,
391 } = useReviewSections({
392 enabled: isEnvironmentReady,
393 environmentId,
394 threadId,
395 reviewCache,
396 });
397 useReviewDiffPrewarming({
398 threadKey: reviewCache.threadKey,
399 sections: reviewSections,
400 selectedSectionId: selectedSection?.id ?? null,
401 });
402 const {
403 headerDiffSummary,
404 nativeReviewDiffData,
405 parsedDiff,
406 pendingReviewCommentCount,
407 loadVisibleFile,
408 isPending: areFilePatchesPending,
409 } = useReviewDiffData({
410 threadKey: reviewCache.threadKey,
411 environmentId,
412 cwd: selectedThreadCwd,
413 selectedSection,
414 draftMessage,
415 draftContext,
416 });
417 // Expo may return null before registration or in older binaries; use the fallback.
418 const NativeReviewDiffView = resolveNativeReviewDiffView();
419 const nativeReviewDiffViewRef = useRef<NativeReviewDiffViewHandle>(null);
420 const showcasedReviewDrawRef = useRef<string | null>(null);
421 const [isPullRefreshing, setIsPullRefreshing] = useState(false);
422 const handlePullToRefresh = async () => {
423 setIsPullRefreshing(true);
424 await refreshSelectedSection();
425 setIsPullRefreshing(false);
426 };
427 const isRefreshing = isPullRefreshing || isSelectedSectionPending || areFilePatchesPending;
428 // A refresh that starts programmatically adds its height to the native top inset and
429 // subtracts it when it ends. If topContentInset changes in between, the inset ends up
430 // short and the content sits under the header, so the fallback ScrollView starts over.
431 const [fallbackInset, setFallbackInset] = useState(topContentInset);
432 const [fallbackScrollViewKey, setFallbackScrollViewKey] = useState(0);
433 if (fallbackInset !== topContentInset) {
434 setFallbackInset(topContentInset);
435 if (isRefreshing) setFallbackScrollViewKey((key) => key + 1);
436 }
437 const reviewFileNavigatorRef = useRef<ReviewFileNavigatorHandle>(null);
438 const reviewFiles = parsedDiff.kind === "files" ? parsedDiff.files : [];
439 const fileVisibility = useReviewFileVisibility({
440 threadKey: reviewCache.threadKey,
441 sectionId: selectedSection?.id ?? null,
442 files: reviewFiles,
443 cachedExpandedFileIds: selectedSection?.id
444 ? reviewCache.expandedFileIdsBySection[selectedSection.id]
445 : undefined,
446 cachedViewedFileIds: selectedSection?.id
447 ? reviewCache.viewedFileIdsBySection[selectedSection.id]
448 : undefined,
449 });
450 const { collapsedFileIds, toggleExpandedFile, toggleViewedFile, viewedFileIds } = fileVisibility;
451 const commentSelection = useReviewCommentSelectionController({
452 environmentId,
453 threadId,
454 selectedSection,
455 nativeReviewDiffData,
456 });
457 const nativeBridge = useNativeReviewDiffBridge({
458 threadKey: reviewCache.threadKey,
459 sectionId: selectedSection?.id ?? null,
460 diff: selectedSection?.diff,
461 data: nativeReviewDiffData,
462 collapsedFileIds,
463 viewedFileIds,
464 selectedRowIds: commentSelection.selectedRowIds,
465 canHighlight: parsedDiff.kind === "files",
466 });
467 const showcaseReviewKey =
468 SHOWCASE_ENABLED && parsedDiff.kind === "files" && selectedSection
469 ? `${reviewCache.threadKey}:${selectedSection.id}:${nativeBridge.tokensResetKey}:${nativeBridge.themeId}`
470 : null;
471 const handleNativeDebug = (event: NativeSyntheticEvent<Record<string, unknown>>) => {
472 nativeBridge.onDebug(event);
473 if (
474 showcaseReviewKey === null ||
475 showcasedReviewDrawRef.current === showcaseReviewKey ||
476 !isNativeReviewDiffDrawEvent(event.nativeEvent)
477 ) {
478 return;
479 }
480 showcasedReviewDrawRef.current = showcaseReviewKey;
481 reportShowcaseSceneRendered({ scene: "review", themeId: nativeBridge.themeId });
482 };
483​
484 const handleSelectFile = async (fileId: string | null) => {
485 loadVisibleFile(fileId, true);
486 commentSelection.clearSelection();
487 if (fileId !== null && collapsedFileIds.includes(fileId)) {
488 toggleExpandedFile(fileId);
489 }
490 const nativeView = nativeReviewDiffViewRef.current;
491 if (!nativeView) return;
492 const result = await settlePromise(() =>
493 fileId === null
494 ? nativeView.scrollToTop(!reduceMotion)
495 : nativeView.scrollToFile(fileId, !reduceMotion),
496 );
497 if (AsyncResult.isFailure(result)) {
498 console.error("[review] Failed to navigate to diff file", squashAtomCommandFailure(result));
499 }
500 };
501 const handleVisibleFileChange = (
502 event: NativeSyntheticEvent<{ readonly fileId?: string | null }>,
503 ) => {
504 loadVisibleFile(event.nativeEvent.fileId ?? null);
505 reviewFileNavigatorRef.current?.setVisibleFile(event.nativeEvent.fileId ?? null);
506 };
507 const renderInspector = () => (
508 <ReviewFileNavigator
509 ref={reviewFileNavigatorRef}
510 files={nativeReviewDiffData.files}
511 sectionId={selectedSection?.id ?? null}
512 onSelectFile={(fileId) => void handleSelectFile(fileId)}
513 />
514 );
515​
516 const handleNativeToggleFile = (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => {
517 const { fileId } = event.nativeEvent;
518 if (fileId) {
519 loadVisibleFile(fileId, true);
520 toggleExpandedFile(fileId);
521 }
522 };
523​
524 const handleNativeToggleViewedFile = (
525 event: NativeSyntheticEvent<{ readonly fileId?: string }>,
526 ) => {
527 const { fileId } = event.nativeEvent;
528 if (fileId) {
529 toggleViewedFile(fileId);
530 }
531 };
532​
533 const parsedDiffNotice =
534 parsedDiff.kind === "files" || parsedDiff.kind === "raw" ? parsedDiff.notice : null;
535 const hasCachedSelectedDiff = selectedSection?.diff != null;
536 const hasAnyCachedDiff = reviewSections.some((section) => section.diff != null);
537 const sectionMenu = buildReviewSectionMenu(reviewSections);
538 const { showConnectionNotice, showSectionToolbar } = resolveReviewAvailability({
539 hasEnvironmentPresentation: environment.isReady,
540 isEnvironmentConnected: isEnvironmentReady,
541 hasCachedSelectedDiff,
542 hasAnyCachedDiff,
543 });
544 const handleRetryEnvironment = () => {
545 void retryEnvironment(environmentId);
546 };
547 const handleReturnToThread = () => {
548 if (navigation.canGoBack()) {
549 navigation.goBack();
550 return;
551 }
552 selectDetail({
553 name: "Thread",
554 params: { environmentId: String(environmentId), threadId: String(threadId) },
555 });
556 };
557 const androidHeaderSubtitle = [
558 selectedSection?.title,
559 headerDiffSummary.additions,
560 headerDiffSummary.deletions,
561 ]
562 .filter((part): part is string => Boolean(part))
563 .join(" · ");
564​
565 const showChangedFilesPane =
566 !showConnectionNotice &&
567 selectedSection !== null &&
568 parsedDiff.kind === "files" &&
569 NativeReviewDiffView !== null;
570 const showChangedFilesToggle = panes.supportsAuxiliaryPane && showChangedFilesPane;
571​
572 const listHeader = (() => {
573 const children: ReactElement[] = [];
574​
575 if (error) {
576 children.push(
577 <View
578 key="review-error"
579 className={cn(
580 "bg-card px-4 py-3",
581 Platform.OS === "android" ? "m-2 rounded-[20px]" : "border-b border-border",
582 )}
583 >
584 <Text className="text-sm font-t3-bold text-foreground">Review unavailable</Text>
585 <Text className="text-xs leading-normal text-foreground-muted">{error}</Text>
586 </View>,
587 );
588 }
589​
590 if (parsedDiffNotice) {
591 children.push(<ReviewNotice key="review-notice" notice={parsedDiffNotice} />);
592 }
593​
594 if (children.length === 0) {
595 return null;
596 }
597​
598 return <>{children}</>;
599 })();
600 const headerSubtitle = [
601 headerDiffSummary.additions,
602 headerDiffSummary.deletions,
603 pendingReviewCommentCount > 0
604 ? `${pendingReviewCommentCount} comment${pendingReviewCommentCount === 1 ? "" : "s"}`
605 : null,
606 ]
607 .filter(Boolean)
608 .join(" · ");
609 const headerTitleText = selectedSection?.title ?? "Review changes";
610​
611 return (
612 <>
613 {showChangedFilesPane ? (
614 <Inspector
615 revealKey={`${environmentId}:${threadId}`}
616 content={{ active: "changes", panes: [{ key: "changes", render: renderInspector }] }}
617 />
618 ) : null}
619 <ReviewHeader
620 environmentId={environmentId}
621 threadId={threadId}
622 title={headerTitleText}
623 subtitle={headerSubtitle}
624 androidSubtitle={androidHeaderSubtitle}
625 selectedThreadCwd={selectedThreadCwd}
626 sectionMenu={sectionMenu}
627 selectedSection={selectedSection}
628 showSectionToolbar={showSectionToolbar}
629 showChangedFilesToggle={showChangedFilesToggle}
630 onRefresh={handlePullToRefresh}
631 onSelectSection={selectSection}
632 onReturnToThread={handleReturnToThread}
633 />
634​
635 <ScreenContent>
636 <View className="flex-1 bg-sheet android:bg-sheet-solid">
637 {showConnectionNotice ? (
638 <View className="flex-1" style={{ paddingTop: topContentInset }}>
639 <EnvironmentConnectionNotice
640 environmentLabel={environment.presentation?.entry.target.label ?? "Environment"}
641 connection={
642 environment.presentation?.connection ?? {
643 phase: "available",
644 error: null,
645 traceId: null,
646 }
647 }
648 resourceName="review"
649 onRetry={handleRetryEnvironment}
650 />
651 </View>
652 ) : selectedSection && parsedDiff.kind === "files" && NativeReviewDiffView ? (
653 <View
654 className="flex-1"
655 style={{
656 backgroundColor: nativeBridge.theme.background,
657 }}
658 >
659 <View
660 className="min-w-0 flex-1"
661 style={listHeader ? { paddingTop: topContentInset } : undefined}
662 >
663 {listHeader}
664 <View className="min-w-0 flex-1" collapsable={false}>
665 {/* oxlint-disable-next-line react/static-components -- The resolver returns a cached native component with stable identity. */}
666 <NativeReviewDiffView
667 collapsable={false}
668 testID="review-native-diff-view"
669 refreshing={
670 isPullRefreshing || isSelectedSectionPending || areFilePatchesPending
671 }
672 onPullToRefresh={() => void handlePullToRefresh()}
673 style={StyleSheet.absoluteFill}
674 appearanceScheme={selectedTheme}
675 collapsedFileIdsJson={nativeBridge.collapsedFileIdsJson}
676 collapsedCommentIdsJson={nativeBridge.collapsedCommentIdsJson}
677 contentResetKey={`${reviewCache.threadKey}:${selectedSection.id}`}
678 contentWidth={NATIVE_REVIEW_DIFF_CONTENT_WIDTH}
679 contentInsetTop={listHeader ? 0 : topContentInset}
680 contentInsetBottom={bottomContentInset}
681 nativeViewRef={nativeReviewDiffViewRef}
682 rowHeight={nativeReviewDiffStyle.rowHeight}
683 rowsJson={nativeBridge.rowsJson}
684 selectedRowIdsJson={nativeBridge.selectedRowIdsJson}
685 styleJson={nativeBridge.styleJson}
686 themeJson={nativeBridge.themeJson}
687 tokensPatchJson={nativeBridge.tokensPatchJson}
688 tokensResetKey={nativeBridge.tokensResetKey}
689 viewedFileIdsJson={nativeBridge.viewedFileIdsJson}
690 onDebug={handleNativeDebug}
691 onPressLine={commentSelection.onPressLine}
692 onVisibleFileChange={handleVisibleFileChange}
693 onToggleComment={nativeBridge.onToggleComment}
694 onToggleFile={handleNativeToggleFile}
695 onToggleViewedFile={handleNativeToggleViewedFile}
696 />
697 </View>
698 </View>
699 </View>
700 ) : (
701 <ScrollView
702 key={fallbackScrollViewKey}
703 contentContainerStyle={
704 Platform.OS === "android" && (parsedDiff.kind === "empty" || !selectedSection)
705 ? { flexGrow: 1, justifyContent: "center" }
706 : undefined
707 }
708 contentInsetAdjustmentBehavior="never"
709 contentInset={{ top: topContentInset, bottom: bottomContentInset }}
710 contentOffset={{ x: 0, y: -topContentInset }}
711 automaticallyAdjustsScrollIndicatorInsets={false}
712 scrollIndicatorInsets={{ top: topContentInset, bottom: bottomContentInset }}
713 showsVerticalScrollIndicator={false}
714 className="flex-1"
715 refreshControl={
716 // Fallback and empty states need refresh controls; only Android has an explicit refresh menu.
717 <RefreshControl
718 refreshing={isRefreshing}
719 onRefresh={() => void handlePullToRefresh()}
720 />
721 }
722 >
723 {listHeader}
724 {!selectedSection ? (
725 error ? null : (
726 <View
727 className={
728 Platform.OS === "android"
729 ? "items-center px-6 py-5"
730 : "border-b border-border bg-card px-4 py-5"
731 }
732 >
733 <Text className="text-sm font-t3-bold text-foreground">No review diffs</Text>
734 <Text
735 className={cn(
736 "text-xs leading-normal text-foreground-muted",
737 Platform.OS === "android" && "mt-2 text-center",
738 )}
739 >
740 This thread has no ready turn diffs and the worktree diff is empty.
741 </Text>
742 </View>
743 )
744 ) : selectedSection.isLoading && selectedSection.diff === null ? (
745 <View
746 className={cn(
747 "items-center gap-3 px-4 py-6",
748 Platform.OS !== "android" && "border-b border-border bg-card",
749 )}
750 >
751 <AppActivityIndicator size="small" />
752 <Text className="text-xs text-foreground-muted">Loading diff…</Text>
753 </View>
754 ) : parsedDiff.kind === "empty" ? (
755 <View
756 className={
757 Platform.OS === "android"
758 ? "items-center px-6 py-5"
759 : "border-b border-border bg-card px-4 py-5"
760 }
761 >
762 <Text className="text-sm font-t3-bold text-foreground">No changes</Text>
763 <Text
764 className={cn(
765 "text-xs leading-normal text-foreground-muted",
766 Platform.OS === "android" && "mt-2 text-center",
767 )}
768 >
769 {selectedSection.subtitle ?? "This diff is empty."}
770 </Text>
771 </View>
772 ) : parsedDiff.kind === "raw" ? (
773 <View
774 className={cn(
775 "gap-3 bg-card px-4 py-4",
776 Platform.OS === "android" ? "m-2 rounded-[20px]" : "border-b border-border",
777 )}
778 >
779 <Text className="text-xs leading-normal text-foreground-muted">
780 {parsedDiff.reason}
781 </Text>
782 <ScrollView horizontal showsHorizontalScrollIndicator={false} bounces={false}>
783 <Text selectable className="font-mono text-xs leading-relaxed text-foreground">
784 {parsedDiff.text}
785 </Text>
786 </ScrollView>
787 </View>
788 ) : parsedDiff.kind === "files" ? (
789 <View
790 className={cn(
791 "gap-3 bg-card px-4 py-4",
792 Platform.OS === "android" ? "m-2 rounded-[20px]" : "border-b border-border",
793 )}
794 >
795 <Text className="text-xs leading-normal text-foreground-muted">
796 Native diff view unavailable. Showing the raw patch.
797 </Text>
798 <ScrollView horizontal showsHorizontalScrollIndicator={false} bounces={false}>
799 <Text selectable className="font-mono text-xs leading-relaxed text-foreground">
800 {selectedSection?.diff ?? ""}
801 </Text>
802 </ScrollView>
803 </View>
804 ) : null}
805 </ScrollView>
806 )}
807 <ReviewSelectionActionBar
808 bottomInset={insets.bottom}
809 title={commentSelection.selectionAction?.title ?? null}
810 onOpenComment={commentSelection.selectionAction?.onOpenComment ?? null}
811 onClear={commentSelection.clearSelection}
812 />
813 </View>
814 </ScreenContent>
815 </>
816 );