Open History to see the last commit
1import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2import type { MenuAction } from "@react-native-menu/menu";
3import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
4import {
5 NativeHeaderToolbar,
6 NativeStackScreenOptions,
7 nativeHeaderScrollEdgeEffects,
8} from "../../native/StackHeader";
9import { Screen, ScreenStack, ScreenStackHeaderConfig } from "react-native-screens";
10import {
11 memo,
12 type Ref,
13 type ReactElement,
14 useCallback,
15 useEffect,
16 useImperativeHandle,
17 useMemo,
18 useRef,
19 useState,
20} from "react";
21import {
22 ActivityIndicator,
23 FlatList,
24 Platform,
25 Pressable,
26 ScrollView,
27 type NativeSyntheticEvent,
28 StyleSheet,
29 useColorScheme,
30 View,
31} from "react-native";
32import { useSafeAreaInsets } from "react-native-safe-area-context";
33
34import { AppText as Text } from "../../components/AppText";
35import { SymbolView } from "../../components/AppSymbol";
36import { AndroidHeaderIconButton, AndroidScreenHeader } from "../../components/AndroidScreenHeader";
37import { ControlPillMenu } from "../../components/ControlPill";
38import { environmentCatalog } from "../../connection/catalog";
39import { useEnvironmentPresentation } from "../../state/presentation";
40import { useAtomCommand } from "../../state/use-atom-command";
41import { useThemeColor } from "../../lib/useThemeColor";
42import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";
43import { useThreadDraftForThread } from "../../state/use-thread-composer-state";
44import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
45import {
46 useAdaptiveWorkspaceLayout,
47 useAdaptiveWorkspacePaneRole,
48 useRegisterWorkspaceInspector,
49} from "../layout/AdaptiveWorkspaceLayout";
50import { useEnvironmentQuery } from "../../state/query";
51import { useSelectedThreadGitActions } from "../../state/use-selected-thread-git-actions";
52import { useSelectedThreadGitState } from "../../state/use-selected-thread-git-state";
53import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree";
54import { useThreadSelection } from "../../state/use-thread-selection";
55import { vcsEnvironment } from "../../state/vcs";
56import { WorkspaceSidebarToolbar } from "../layout/workspace-sidebar-toolbar";
57import { ThreadGitMenu } from "../threads/ThreadGitControls";
58import { useReviewCacheForThread } from "./reviewState";
59import {
60 isNativeReviewDiffDrawEvent,
61 type NativeReviewDiffViewHandle,
62 resolveNativeReviewDiffView,
63} from "../diffs/nativeReviewDiffSurface";
64import { NATIVE_REVIEW_DIFF_CONTENT_WIDTH } from "./nativeReviewDiffAdapter";
65import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
66import { useReviewDiffData } from "./useReviewDiffData";
67import { useReviewDiffPrewarming } from "./useReviewDiffPrewarming";
68import { useReviewFileVisibility } from "./reviewFileVisibility";
69import { useReviewSections } from "./useReviewSections";
70import { useNativeReviewDiffBridge } from "./useNativeReviewDiffBridge";
71import { useReviewCommentSelectionController } from "./useReviewCommentSelectionController";
72import { resolveReviewAvailability } from "./reviewAvailability";
73import { resolveSelectedReviewFileId } from "./reviewPaneSelection";
74import { buildReviewSectionMenu } from "./review-section-menu";
75import type { ReviewSectionItem } from "./reviewModel";
76import { markNativeShowcaseReady } from "../showcase/nativeShowcaseScene";
77
78const REVIEW_HEADER_SPACING = 0;
79const SHOWCASE_ENABLED = process.env.EXPO_PUBLIC_SHOWCASE === "1";
80
81const ReviewNotice = memo(function ReviewNotice(props: { readonly notice: string }) {
82 return (
83 <View className="border-b border-amber-200 bg-amber-50 px-4 py-3 dark:border-amber-900/60 dark:bg-amber-950/40">
84 <Text className="text-xs font-t3-bold uppercase text-amber-700 dark:text-amber-300">
85 Partial diff
86 </Text>
87 <Text className="text-xs leading-normal text-amber-800 dark:text-amber-200">
88 {props.notice}
89 </Text>
90 </View>
91 );
92});
93
94function ReviewSelectionActionBar(props: {
95 readonly bottomInset: number;
96 readonly title: string | null;
97 readonly onOpenComment: (() => void) | null;
98 readonly onClear: () => void;
99}) {
100 if (!props.title) {
101 return null;
102 }
103
104 const content = (
105 <>
106 <SymbolView
107 name={props.onOpenComment ? "text.bubble" : "line.3.horizontal.decrease.circle"}
108 size={16}
109 tintColor="#ffffff"
110 type="monochrome"
111 />
112 <Text className="text-base font-t3-bold text-white">{props.title}</Text>
113 </>
114 );
115
116 return (
117 <View
118 pointerEvents="box-none"
119 style={{
120 position: "absolute",
121 left: 18,
122 right: 18,
123 bottom: Math.max(props.bottomInset, 10) + 18,
124 flexDirection: "row",
125 justifyContent: "center",
126 gap: 10,
127 }}
128 >
129 {props.onOpenComment ? (
130 <Pressable
131 className="h-12 flex-1 flex-row items-center justify-center gap-2 rounded-full bg-blue-600 px-5"
132 onPress={props.onOpenComment}
133 >
134 {content}
135 </Pressable>
136 ) : (
137 <View className="h-12 flex-1 flex-row items-center justify-center gap-2 rounded-full bg-blue-600 px-5">
138 {content}
139 </View>
140 )}
141
142 <Pressable
143 className="h-12 w-12 items-center justify-center rounded-full bg-blue-600"
144 onPress={props.onClear}
145 >
146 <SymbolView name="xmark" size={16} tintColor="#ffffff" type="monochrome" />
147 </Pressable>
148 </View>
149 );
150}
151
152interface ReviewNavigatorFile {
153 readonly id: string;
154 readonly path: string;
155 readonly additions: number;
156 readonly deletions: number;
157}
158
159const ReviewFileNavigatorRow = memo(function ReviewFileNavigatorRow(props: {
160 readonly file: ReviewNavigatorFile;
161 readonly selected: boolean;
162 readonly onSelectFile: (fileId: string | null) => void;
163}) {
164 const { file, selected, onSelectFile } = props;
165 // Tapping the selected file again returns to the all-files diff.
166 const handlePress = useCallback(() => {
167 onSelectFile(selected ? null : file.id);
168 }, [file.id, onSelectFile, selected]);
169
170 return (
171 <Pressable
172 accessibilityRole="button"
173 accessibilityState={{ selected }}
174 className={
175 selected
176 ? "mt-1 min-h-12 justify-center rounded-xl bg-subtle-strong px-3 py-2"
177 : "mt-1 min-h-12 justify-center rounded-xl px-3 py-2 active:bg-subtle"
178 }
179 onPress={handlePress}
180 >
181 <Text
182 className={
183 selected
184 ? "text-xs font-t3-bold text-foreground"
185 : "text-xs font-t3-medium text-foreground-secondary"
186 }
187 numberOfLines={2}
188 >
189 {file.path}
190 </Text>
191 <View className="mt-1 flex-row gap-2">
192 <Text className="text-2xs font-t3-bold text-emerald-600">+{file.additions}</Text>
193 <Text className="text-2xs font-t3-bold text-rose-600">-{file.deletions}</Text>
194 </View>
195 </Pressable>
196 );
197});
198
199interface ReviewFileNavigatorHandle {
200 readonly setVisibleFile: (fileId: string | null) => void;
201}
202
203interface ReviewFileNavigatorProps {
204 readonly files: ReadonlyArray<ReviewNavigatorFile>;
205 readonly headerInset: number;
206 readonly sectionId: string | null;
207 readonly onSelectFile: (fileId: string | null) => void;
208 readonly ref?: Ref<ReviewFileNavigatorHandle>;
209}
210
211function ReviewFileNavigator({
212 files,
213 headerInset,
214 sectionId,
215 onSelectFile,
216 ref,
217}: ReviewFileNavigatorProps) {
218 const insets = useSafeAreaInsets();
219 const sheetColor = String(useThemeColor("--color-sheet"));
220 const foregroundColor = String(useThemeColor("--color-foreground"));
221 const headerScrollEdgeEffects = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
222 const [fileSelection, setFileSelection] = useState<{
223 readonly sectionId: string | null;
224 readonly fileId: string | null;
225 }>({ sectionId: null, fileId: null });
226 const availableFileIds = useMemo(() => files.map((file) => file.id), [files]);
227 const selectedFileId = resolveSelectedReviewFileId({
228 selection: fileSelection,
229 sectionId,
230 availableFileIds,
231 });
232
233 useImperativeHandle(
234 ref,
235 () => ({
236 setVisibleFile: (fileId) => {
237 if (fileId !== null && !availableFileIds.includes(fileId)) {
238 return;
239 }
240 setFileSelection((current) => {
241 if (current.sectionId === sectionId && current.fileId === fileId) {
242 return current;
243 }
244 return { sectionId, fileId };
245 });
246 },
247 }),
248 [availableFileIds, sectionId],
249 );
250
251 const handleSelectFile = useCallback(
252 (fileId: string | null) => {
253 setFileSelection({ sectionId, fileId });
254 onSelectFile(fileId);
255 },
256 [onSelectFile, sectionId],
257 );
258
259 const renderFile = useCallback(
260 ({ item }: { readonly item: ReviewNavigatorFile }) => (
261 <ReviewFileNavigatorRow
262 file={item}
263 selected={selectedFileId === item.id}
264 onSelectFile={handleSelectFile}
265 />
266 ),
267 [handleSelectFile, selectedFileId],
268 );
269
270 const fileList = (
271 <FlatList
272 data={files}
273 extraData={selectedFileId}
274 keyExtractor={(file) => file.id}
275 contentContainerStyle={{
276 paddingHorizontal: 8,
277 paddingBottom: 8,
278 // The nested native header is translucent; start the list below it so
279 // the scroll-edge effect can sample the content (same treatment as
280 // FileTreeBrowser in the Files pane).
281 paddingTop: Platform.OS === "ios" ? insets.top + IOS_NAV_BAR_HEIGHT + 8 : 8,
282 }}
283 scrollIndicatorInsets={
284 Platform.OS === "ios" ? { top: insets.top + IOS_NAV_BAR_HEIGHT } : undefined
285 }
286 renderItem={renderFile}
287 />
288 );
289
290 if (Platform.OS === "ios") {
291 return (
292 <View className="flex-1 border-l border-border bg-sheet">
293 <ScreenStack style={{ flex: 1 }}>
294 <Screen
295 activityState={2}
296 enabled
297 isNativeStack
298 screenId="review-file-navigator-native"
299 scrollEdgeEffects={headerScrollEdgeEffects}
300 style={{ backgroundColor: sheetColor, flex: 1 }}
301 >
302 {fileList}
303 <ScreenStackHeaderConfig
304 backgroundColor="rgba(0,0,0,0)"
305 color={foregroundColor}
306 hideBackButton
307 hideShadow={false}
308 navigationItemStyle="editor"
309 subtitle={`${files.length} ${files.length === 1 ? "file" : "files"}`}
310 title="Changed files"
311 titleColor={foregroundColor}
312 titleFontSize={17}
313 titleFontWeight="700"
314 translucent
315 />
316 </Screen>
317 </ScreenStack>
318 </View>
319 );
320 }
321
322 return (
323 <View className="flex-1 border-l border-border bg-sheet">
324 <View className="border-b border-border" style={{ paddingTop: headerInset }}>
325 <View className="px-4 py-3">
326 <Text className="text-sm font-t3-bold text-foreground">Changed files</Text>
327 <Text className="text-xs text-foreground-muted">
328 {files.length} {files.length === 1 ? "file" : "files"}
329 </Text>
330 </View>
331 </View>
332 {fileList}
333 </View>
334 );
335}
336
337type ReviewSheetProps = StaticScreenProps<{
338 readonly environmentId: EnvironmentId;
339 readonly threadId: ThreadId;
340}>;
341
342export function ReviewSheet(props: ReviewSheetProps) {
343 const isAndroid = Platform.OS === "android";
344 const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
345 useAdaptiveWorkspacePaneRole("inspector");
346 const { panes, showAuxiliaryPane, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
347 const navigation = useNavigation();
348 const insets = useSafeAreaInsets();
349 const colorScheme = useColorScheme();
350 const headerIcon = String(useThemeColor("--color-icon"));
351 const { environmentId, threadId } = props.route.params;
352 const environment = useEnvironmentPresentation(environmentId);
353 const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
354 const isEnvironmentReady = environment.presentation?.connection.phase === "connected";
355 const { draftMessage } = useThreadDraftForThread({ environmentId, threadId });
356 const reviewCache = useReviewCacheForThread({ environmentId, threadId });
357 /* ─── Git actions for the toolbar menu (commit/push without leaving review) ── */
358 const { selectedThread } = useThreadSelection();
359 const { selectedThreadCwd } = useSelectedThreadWorktree();
360 const gitState = useSelectedThreadGitState();
361 const gitActions = useSelectedThreadGitActions();
362 const gitStatusQuery = useEnvironmentQuery(
363 selectedThread !== null && selectedThreadCwd !== null
364 ? vcsEnvironment.status({
365 environmentId: selectedThread.environmentId,
366 input: { cwd: selectedThreadCwd },
367 })
368 : null,
369 );
370 // The selection-based git hooks only apply when this review belongs to the
371 // selected thread (it always does when reached from the thread's toolbar).
372 const gitMenuAvailable =
373 selectedThread !== null && String(selectedThread.id) === String(threadId);
374 const selectedTheme = colorScheme === "dark" ? "dark" : "light";
375 // With a solid (non-overlay) header the content lays out below the header
376 // natively, so no manual top inset is needed. (Android renders its own
377 // in-flow AndroidScreenHeader, so it needs no inset either.)
378 const topContentInset = 0;
379
380 useEffect(() => {
381 showAuxiliaryPane("inspector");
382 }, [environmentId, showAuxiliaryPane, threadId]);
383 const { error, reviewSections, selectedSection, refreshSelectedSection, selectSection } =
384 useReviewSections({
385 enabled: isEnvironmentReady,
386 environmentId,
387 threadId,
388 reviewCache,
389 });
390 useReviewDiffPrewarming({
391 threadKey: reviewCache.threadKey,
392 sections: reviewSections,
393 selectedSectionId: selectedSection?.id ?? null,
394 });
395 const { headerDiffSummary, nativeReviewDiffData, parsedDiff, pendingReviewCommentCount } =
396 useReviewDiffData({
397 threadKey: reviewCache.threadKey,
398 selectedSection,
399 draftMessage,
400 });
401 const NativeReviewDiffView = resolveNativeReviewDiffView()!;
402 const nativeReviewDiffViewRef = useRef<NativeReviewDiffViewHandle>(null);
403 const showcasedReviewDrawRef = useRef<string | null>(null);
404 // Native pull-to-refresh on the diff surface (replaces the old Refresh menu item).
405 const [isPullRefreshing, setIsPullRefreshing] = useState(false);
406 const handlePullToRefresh = useCallback(async () => {
407 setIsPullRefreshing(true);
408 try {
409 await refreshSelectedSection();
410 } finally {
411 setIsPullRefreshing(false);
412 }
413 }, [refreshSelectedSection]);
414 const reviewFileNavigatorRef = useRef<ReviewFileNavigatorHandle>(null);
415 const reviewFiles = parsedDiff.kind === "files" ? parsedDiff.files : [];
416 const fileVisibility = useReviewFileVisibility({
417 threadKey: reviewCache.threadKey,
418 sectionId: selectedSection?.id ?? null,
419 files: reviewFiles,
420 cachedExpandedFileIds: selectedSection?.id
421 ? reviewCache.expandedFileIdsBySection[selectedSection.id]
422 : undefined,
423 cachedViewedFileIds: selectedSection?.id
424 ? reviewCache.viewedFileIdsBySection[selectedSection.id]
425 : undefined,
426 });
427 const { collapsedFileIds, toggleExpandedFile, toggleViewedFile, viewedFileIds } = fileVisibility;
428 const commentSelection = useReviewCommentSelectionController({
429 environmentId,
430 threadId,
431 selectedSection,
432 nativeReviewDiffData,
433 });
434 const nativeBridge = useNativeReviewDiffBridge({
435 threadKey: reviewCache.threadKey,
436 sectionId: selectedSection?.id ?? null,
437 diff: selectedSection?.diff,
438 data: nativeReviewDiffData,
439 scheme: selectedTheme,
440 collapsedFileIds,
441 viewedFileIds,
442 selectedRowIds: commentSelection.selectedRowIds,
443 canHighlight: parsedDiff.kind === "files",
444 });
445 const showcaseReviewKey =
446 SHOWCASE_ENABLED && parsedDiff.kind === "files" && selectedSection
447 ? `${reviewCache.threadKey}:${selectedSection.id}:${nativeBridge.tokensResetKey}`
448 : null;
449 const handleNativeDebug = useCallback(
450 (event: NativeSyntheticEvent<Record<string, unknown>>) => {
451 nativeBridge.onDebug(event);
452 if (
453 showcaseReviewKey === null ||
454 showcasedReviewDrawRef.current === showcaseReviewKey ||
455 !isNativeReviewDiffDrawEvent(event.nativeEvent)
456 ) {
457 return;
458 }
459 showcasedReviewDrawRef.current = showcaseReviewKey;
460 markNativeShowcaseReady("review");
461 },
462 [nativeBridge.onDebug, showcaseReviewKey],
463 );
464
465 const handleSelectFile = useCallback(
466 (fileId: string | null) => {
467 commentSelection.clearSelection();
468 if (fileId !== null && collapsedFileIds.includes(fileId)) {
469 toggleExpandedFile(fileId);
470 }
471 const navigation =
472 fileId === null
473 ? nativeReviewDiffViewRef.current?.scrollToTop(true)
474 : nativeReviewDiffViewRef.current?.scrollToFile(fileId, true);
475 void navigation?.catch((error: unknown) => {
476 console.error("[review] Failed to navigate to diff file", error);
477 });
478 },
479 [collapsedFileIds, commentSelection, toggleExpandedFile],
480 );
481 const handleVisibleFileChange = useCallback(
482 (event: NativeSyntheticEvent<{ readonly fileId?: string | null }>) => {
483 reviewFileNavigatorRef.current?.setVisibleFile(event.nativeEvent.fileId ?? null);
484 },
485 [],
486 );
487 const renderInspector = useCallback(
488 () => (
489 <ReviewFileNavigator
490 ref={reviewFileNavigatorRef}
491 files={nativeReviewDiffData.files}
492 // The workspace inspector column spans the full window height, so the
493 // pane clears the status bar itself.
494 headerInset={insets.top}
495 sectionId={selectedSection?.id ?? null}
496 onSelectFile={handleSelectFile}
497 />
498 ),
499 [handleSelectFile, insets.top, nativeReviewDiffData.files, selectedSection?.id],
500 );
501
502 const handleNativeToggleFile = useCallback(
503 (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => {
504 const { fileId } = event.nativeEvent;
505 if (fileId) {
506 toggleExpandedFile(fileId);
507 }
508 },
509 [toggleExpandedFile],
510 );
511
512 const handleNativeToggleViewedFile = useCallback(
513 (event: NativeSyntheticEvent<{ readonly fileId?: string }>) => {
514 const { fileId } = event.nativeEvent;
515 if (fileId) {
516 toggleViewedFile(fileId);
517 }
518 },
519 [toggleViewedFile],
520 );
521
522 const parsedDiffNotice =
523 parsedDiff.kind === "files" || parsedDiff.kind === "raw" ? parsedDiff.notice : null;
524 const hasCachedSelectedDiff = selectedSection?.diff != null;
525 const hasAnyCachedDiff = reviewSections.some((section) => section.diff != null);
526 const sectionMenu = useMemo(() => buildReviewSectionMenu(reviewSections), [reviewSections]);
527 const { showConnectionNotice, showSectionToolbar } = resolveReviewAvailability({
528 hasEnvironmentPresentation: environment.isReady,
529 isEnvironmentConnected: isEnvironmentReady,
530 hasCachedSelectedDiff,
531 hasAnyCachedDiff,
532 });
533 const androidSectionMenuActions = useMemo<MenuAction[]>(() => {
534 const sectionAction = (section: ReviewSectionItem | null, title: string): MenuAction => ({
535 id: section ? `section:${section.id}` : `unavailable:${title}`,
536 title: section?.id === selectedSection?.id ? `${title} (selected)` : title,
537 attributes: section ? undefined : { disabled: true },
538 });
539 const actions: MenuAction[] = [
540 sectionAction(sectionMenu.workingTree, "Working tree"),
541 sectionAction(sectionMenu.branchChanges, "Branch changes"),
542 sectionAction(sectionMenu.latestTurn, "Latest turn"),
543 ];
544
545 if (sectionMenu.turns.length > 0) {
546 actions.push({
547 id: "turns",
548 title: "Turn",
549 subactions: sectionMenu.turns.map((section) => ({
550 id: `section:${section.id}`,
551 title: section.id === selectedSection?.id ? `${section.title} (selected)` : section.title,
552 subtitle: section.subtitle ?? undefined,
553 })),
554 });
555 }
556
557 // The Android native diff surface has no pull-to-refresh, so refresh
558 // stays a menu action there (iOS refreshes via pull-to-refresh instead).
559 actions.push({
560 id: "refresh",
561 title: "Refresh current diff",
562 attributes: {
563 disabled: !selectedSection || selectedSection.isLoading,
564 },
565 });
566 return actions;
567 }, [sectionMenu, selectedSection]);
568 const handleAndroidSectionMenuAction = useCallback(
569 (event: { nativeEvent: { event: string } }) => {
570 const id = event.nativeEvent.event;
571 if (id === "refresh") {
572 void refreshSelectedSection();
573 } else if (id.startsWith("section:")) {
574 selectSection(id.slice("section:".length));
575 }
576 },
577 [refreshSelectedSection, selectSection],
578 );
579 const handleRetryEnvironment = useCallback(() => {
580 void retryEnvironment(environmentId);
581 }, [environmentId, retryEnvironment]);
582 const handleReturnToThread = useCallback(() => {
583 if (navigation.canGoBack()) {
584 navigation.goBack();
585 return;
586 }
587 navigation.navigate("Thread", {
588 environmentId: String(environmentId),
589 threadId: String(threadId),
590 });
591 }, [environmentId, navigation, threadId]);
592 const androidHeaderSubtitle = [
593 selectedSection?.title,
594 headerDiffSummary.additions,
595 headerDiffSummary.deletions,
596 ]
597 .filter((part): part is string => Boolean(part))
598 .join(" · ");
599
600 // The changed-files navigator lives in the workspace inspector column —
601 // the single right-hand pane per route — instead of an in-screen panel.
602 const showChangedFilesPane =
603 !showConnectionNotice && selectedSection !== null && parsedDiff.kind === "files";
604 useRegisterWorkspaceInspector(showChangedFilesPane ? renderInspector : undefined);
605
606 const listHeader = useMemo(() => {
607 const children: ReactElement[] = [];
608
609 if (error) {
610 children.push(
611 <View key="review-error" className="border-b border-border bg-card px-4 py-3">
612 <Text className="text-sm font-t3-bold text-foreground">Review unavailable</Text>
613 <Text className="text-xs leading-normal text-foreground-muted">{error}</Text>
614 </View>,
615 );
616 }
617
618 if (parsedDiffNotice) {
619 children.push(<ReviewNotice key="review-notice" notice={parsedDiffNotice} />);
620 }
621
622 if (children.length === 0) {
623 return null;
624 }
625
626 return <>{children}</>;
627 }, [error, parsedDiffNotice]);
628 const headerSubtitle = [
629 headerDiffSummary.additions,
630 headerDiffSummary.deletions,
631 pendingReviewCommentCount > 0
632 ? `${pendingReviewCommentCount} comment${pendingReviewCommentCount === 1 ? "" : "s"}`
633 : null,
634 ]
635 .filter(Boolean)
636 .join(" · ");
637 const headerTitleText = selectedSection?.title ?? "Review changes";
638
639 return (
640 <>
641 <NativeStackScreenOptions
642 options={
643 isAndroid
644 ? // Android draws its own in-flow header (AndroidScreenHeader below).
645 { headerShown: false }
646 : {
647 // Static header config lives in Stack.tsx (SOLID_HEADER_OPTIONS — the native
648 // diff scrolls internally, nothing for glass to sample). Only dynamic values
649 // here.
650 headerTintColor: headerIcon,
651 headerTitle: headerTitleText,
652 title: headerTitleText,
653 unstable_headerSubtitle:
654 Platform.OS === "ios" && headerSubtitle.length > 0 ? headerSubtitle : undefined,
655 }
656 }
657 />
658
659 {isAndroid ? (
660 <AndroidScreenHeader
661 title="Review changes"
662 subtitle={androidHeaderSubtitle || "Select a diff"}
663 onBack={handleReturnToThread}
664 trailing={
665 showSectionToolbar ? (
666 <ControlPillMenu
667 actions={androidSectionMenuActions}
668 isAnchoredToRight
669 onPressAction={handleAndroidSectionMenuAction}
670 >
671 <AndroidHeaderIconButton
672 accessibilityLabel="Select review diff"
673 icon="ellipsis.circle"
674 />
675 </ControlPillMenu>
676 ) : null
677 }
678 />
679 ) : null}
680
681 <WorkspaceSidebarToolbar>
682 <NativeHeaderToolbar.Button
683 accessibilityLabel="Back to chat"
684 icon="chevron.left"
685 onPress={handleReturnToThread}
686 />
687 </WorkspaceSidebarToolbar>
688
689 {!isAndroid && (showSectionToolbar || panes.supportsAuxiliaryPane || gitMenuAvailable) ? (
690 <NativeHeaderToolbar placement="right">
691 {panes.supportsAuxiliaryPane ? (
692 <NativeHeaderToolbar.Button
693 accessibilityLabel={
694 panes.auxiliaryPaneVisible ? "Hide changed files" : "Show changed files"
695 }
696 icon="sidebar.right"
697 onPress={toggleAuxiliaryPane}
698 separateBackground
699 />
700 ) : null}
701 {gitMenuAvailable && selectedThread !== null ? (
702 <ThreadGitMenu
703 environmentId={environmentId}
704 threadId={threadId}
705 currentBranch={selectedThread.branch ?? null}
706 gitStatus={gitStatusQuery.data}
707 gitOperationLabel={gitState.gitOperationLabel}
708 onPull={gitActions.onPullSelectedThreadBranch}
709 onRunAction={gitActions.onRunSelectedThreadGitAction}
710 />
711 ) : null}
712 {showSectionToolbar ? (
713 <NativeHeaderToolbar.Menu icon="ellipsis" title="Select diff" separateBackground>
714 <NativeHeaderToolbar.Menu inline>
715 <NativeHeaderToolbar.MenuAction
716 disabled={sectionMenu.workingTree === null}
717 isOn={selectedSection?.id === sectionMenu.workingTree?.id}
718 onPress={() => {
719 if (sectionMenu.workingTree) {
720 selectSection(sectionMenu.workingTree.id);
721 }
722 }}
723 >
724 <NativeHeaderToolbar.Label>Working tree</NativeHeaderToolbar.Label>
725 </NativeHeaderToolbar.MenuAction>
726 <NativeHeaderToolbar.MenuAction
727 disabled={sectionMenu.branchChanges === null}
728 isOn={selectedSection?.id === sectionMenu.branchChanges?.id}
729 onPress={() => {
730 if (sectionMenu.branchChanges) {
731 selectSection(sectionMenu.branchChanges.id);
732 }
733 }}
734 >
735 <NativeHeaderToolbar.Label>Branch changes</NativeHeaderToolbar.Label>
736 </NativeHeaderToolbar.MenuAction>
737 <NativeHeaderToolbar.MenuAction
738 disabled={sectionMenu.latestTurn === null}
739 isOn={selectedSection?.id === sectionMenu.latestTurn?.id}
740 onPress={() => {
741 if (sectionMenu.latestTurn) {
742 selectSection(sectionMenu.latestTurn.id);
743 }
744 }}
745 >
746 <NativeHeaderToolbar.Label>Latest turn</NativeHeaderToolbar.Label>
747 </NativeHeaderToolbar.MenuAction>
748 {sectionMenu.turns.length > 0 ? (
749 <NativeHeaderToolbar.Menu title="Turn">
750 {sectionMenu.turns.map((section) => (
751 <NativeHeaderToolbar.MenuAction
752 key={section.id}
753 isOn={section.id === selectedSection?.id}
754 onPress={() => selectSection(section.id)}
755 subtitle={section.subtitle ?? undefined}
756 >
757 <NativeHeaderToolbar.Label>{section.title}</NativeHeaderToolbar.Label>
758 </NativeHeaderToolbar.MenuAction>
759 ))}
760 </NativeHeaderToolbar.Menu>
761 ) : null}
762 </NativeHeaderToolbar.Menu>
763 </NativeHeaderToolbar.Menu>
764 ) : null}
765 </NativeHeaderToolbar>
766 ) : null}
767
768 <View className="flex-1 bg-sheet">
769 {showConnectionNotice ? (
770 <View className="flex-1" style={{ paddingTop: topContentInset }}>
771 <EnvironmentConnectionNotice
772 environmentLabel={environment.presentation?.entry.target.label ?? "Environment"}
773 connection={
774 environment.presentation?.connection ?? {
775 phase: "available",
776 error: null,
777 traceId: null,
778 }
779 }
780 resourceName="review"
781 onRetry={handleRetryEnvironment}
782 />
783 </View>
784 ) : selectedSection && parsedDiff.kind === "files" ? (
785 <View
786 className="flex-1"
787 style={{
788 backgroundColor: nativeBridge.theme.background,
789 }}
790 >
791 <View
792 className="min-w-0 flex-1"
793 style={{ paddingTop: topContentInset + REVIEW_HEADER_SPACING }}
794 >
795 {listHeader}
796 <View className="min-w-0 flex-1" collapsable={false}>
797 <NativeReviewDiffView
798 collapsable={false}
799 testID="review-native-diff-view"
800 refreshing={isPullRefreshing}
801 onPullToRefresh={() => void handlePullToRefresh()}
802 style={StyleSheet.absoluteFill}
803 appearanceScheme={selectedTheme}
804 collapsedFileIdsJson={nativeBridge.collapsedFileIdsJson}
805 collapsedCommentIdsJson={nativeBridge.collapsedCommentIdsJson}
806 contentResetKey={`${reviewCache.threadKey}:${selectedSection.id}`}
807 contentWidth={NATIVE_REVIEW_DIFF_CONTENT_WIDTH}
808 nativeViewRef={nativeReviewDiffViewRef}
809 rowHeight={nativeReviewDiffStyle.rowHeight}
810 rowsJson={nativeBridge.rowsJson}
811 selectedRowIdsJson={nativeBridge.selectedRowIdsJson}
812 styleJson={nativeBridge.styleJson}
813 themeJson={nativeBridge.themeJson}
814 tokensPatchJson={nativeBridge.tokensPatchJson}
815 tokensResetKey={nativeBridge.tokensResetKey}
816 viewedFileIdsJson={nativeBridge.viewedFileIdsJson}
817 onDebug={handleNativeDebug}
818 onPressLine={commentSelection.onPressLine}
819 onVisibleFileChange={handleVisibleFileChange}
820 onToggleComment={nativeBridge.onToggleComment}
821 onToggleFile={handleNativeToggleFile}
822 onToggleViewedFile={handleNativeToggleViewedFile}
823 />
824 </View>
825 </View>
826 </View>
827 ) : (
828 <ScrollView
829 contentInsetAdjustmentBehavior="never"
830 contentInset={{ top: topContentInset, bottom: Math.max(insets.bottom, 18) + 18 }}
831 contentOffset={{ x: 0, y: -topContentInset }}
832 scrollIndicatorInsets={{
833 top: topContentInset,
834 bottom: Math.max(insets.bottom, 18) + 18,
835 }}
836 showsVerticalScrollIndicator={false}
837 className="flex-1"
838 >
839 {listHeader}
840 {!selectedSection ? (
841 <View className="border-b border-border bg-card px-4 py-5">
842 <Text className="text-sm font-t3-bold text-foreground">No review diffs</Text>
843 <Text className="text-xs leading-normal text-foreground-muted">
844 This thread has no ready turn diffs and the worktree diff is empty.
845 </Text>
846 </View>
847 ) : selectedSection.isLoading && selectedSection.diff === null ? (
848 <View className="items-center gap-3 border-b border-border bg-card px-4 py-6">
849 <ActivityIndicator size="small" />
850 <Text className="text-xs text-foreground-muted">Loading diff…</Text>
851 </View>
852 ) : parsedDiff.kind === "empty" ? (
853 <View className="border-b border-border bg-card px-4 py-5">
854 <Text className="text-sm font-t3-bold text-foreground">No changes</Text>
855 <Text className="text-xs leading-normal text-foreground-muted">
856 {selectedSection.subtitle ?? "This diff is empty."}
857 </Text>
858 </View>
859 ) : parsedDiff.kind === "raw" ? (
860 <View className="gap-3 border-b border-border bg-card px-4 py-4">
861 <Text className="text-xs leading-normal text-foreground-muted">
862 {parsedDiff.reason}
863 </Text>
864 <ScrollView horizontal showsHorizontalScrollIndicator={false} bounces={false}>
865 <Text selectable className="font-mono text-xs leading-relaxed text-foreground">
866 {parsedDiff.text}
867 </Text>
868 </ScrollView>
869 </View>
870 ) : null}
871 </ScrollView>
872 )}
873 <ReviewSelectionActionBar
874 bottomInset={insets.bottom}
875 title={commentSelection.selectionAction?.title ?? null}
876 onOpenComment={commentSelection.selectionAction?.onOpenComment ?? null}
877 onClear={commentSelection.clearSelection}
878 />
879 </View>
880 </>
881 );
882}