Open History to see the last commit
1import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
2import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
3import type { MenuAction } from "@react-native-menu/menu";
4import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5import { ActivityIndicator, Platform, View } from "react-native";
6import { useSafeAreaInsets } from "react-native-safe-area-context";
7import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
8import {
9 EnvironmentId,
10 type ProjectListEntriesResult,
11 type ProjectReadFileResult,
12 ThreadId,
13} from "@t3tools/contracts";
14
15import { AndroidHeaderIconButton, AndroidScreenHeader } from "../../components/AndroidScreenHeader";
16import { SymbolView } from "../../components/AppSymbol";
17import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
18import { ControlPillMenu } from "../../components/ControlPill";
19import { EmptyState } from "../../components/EmptyState";
20import { LoadingScreen } from "../../components/LoadingScreen";
21import { resolveFileSelectionNavigationAction } from "../../lib/adaptive-navigation";
22import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
23import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
24import { useUniwindTheme } from "../../lib/useUniwindTheme";
25import { useThreadSelection } from "../../state/use-thread-selection";
26import { useSelectedThreadWorktree } from "../../state/use-selected-thread-worktree";
27import { useEnvironmentQuery } from "../../state/query";
28import { projectEnvironment } from "../../state/projects";
29import {
30 useAdaptiveWorkspaceLayout,
31 useAdaptiveWorkspacePaneRole,
32 useRegisterWorkspaceInspector,
33} from "../layout/AdaptiveWorkspaceLayout";
34import {
35 createNativeMailSearchToolbarItem,
36 NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED,
37} from "../layout/native-mail-search-toolbar";
38import { WorkspaceSidebarToolbar } from "../layout/workspace-sidebar-toolbar";
39import { ReviewHighlighterProvider } from "../review/ReviewHighlighterProvider";
40import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
41import { ThreadRouteScreen } from "../threads/ThreadRouteScreen";
42import { FileMarkdownPreview } from "./FileMarkdownPreview";
43import { FileTreeBrowser } from "./FileTreeBrowser";
44import { preloadWorkspaceFileContents } from "./preload-workspace-file";
45import { SourceFileSurface } from "./SourceFileSurface";
46import { ThreadFileNavigatorPane } from "./thread-file-navigator-pane";
47import { WorkspaceFileImagePreview } from "./WorkspaceFileImagePreview";
48import { WorkspaceFileWebPreview } from "./WorkspaceFileWebPreview";
49import {
50 basename,
51 isBrowserPreviewFile,
52 isImagePreviewFile,
53 isMarkdownPreviewFile,
54 isSvgImagePreviewFile,
55} from "./filePath";
56import { useWorkspaceFileAssetUrl } from "./workspaceFileAssetUrl";
57
58type FileViewMode = "preview" | "source";
59
60function firstRouteParam(value: string | string[] | undefined): string | null {
61 if (Array.isArray(value)) {
62 return value[0] ?? null;
63 }
64
65 return value ?? null;
66}
67
68function normalizeRoutePath(value: string | string[] | undefined): string | null {
69 const path = Array.isArray(value) ? value.join("/") : value;
70 if (path === undefined || path.trim().length === 0) {
71 return null;
72 }
73 return path;
74}
75
76function normalizeRouteLine(value: string | null): number | null {
77 if (value === null) {
78 return null;
79 }
80 const parsed = Number(value);
81 return Number.isInteger(parsed) && parsed > 0 ? parsed : null;
82}
83
84function defaultViewMode(path: string | null): FileViewMode {
85 return path !== null && (isBrowserPreviewFile(path) || isImagePreviewFile(path))
86 ? "preview"
87 : "source";
88}
89
90function FileContent(props: {
91 readonly activeMode: FileViewMode;
92 readonly previewUri: string | null;
93 readonly fileContents: string | null;
94 readonly fileError: string | null;
95 readonly relativePath: string;
96 readonly initialLine: number | null;
97 readonly truncated: boolean;
98 readonly onRefresh?: () => Promise<void> | void;
99}) {
100 const isMarkdown = isMarkdownPreviewFile(props.relativePath);
101 const isBrowserFile = isBrowserPreviewFile(props.relativePath);
102 const isImageFile = isImagePreviewFile(props.relativePath);
103
104 if (props.activeMode === "preview" && isImageFile) {
105 if (isSvgImagePreviewFile(props.relativePath)) {
106 return <WorkspaceFileWebPreview uri={props.previewUri} />;
107 }
108 return (
109 <WorkspaceFileImagePreview
110 accessibilityLabel={basename(props.relativePath)}
111 uri={props.previewUri}
112 />
113 );
114 }
115
116 if (props.activeMode === "preview" && isBrowserFile) {
117 return <WorkspaceFileWebPreview uri={props.previewUri} />;
118 }
119
120 if (props.fileError && props.fileContents === null) {
121 return (
122 <View className="flex-1 items-center justify-center bg-sheet px-6">
123 <EmptyState title="File unavailable" detail={props.fileError} />
124 </View>
125 );
126 }
127
128 if (props.fileContents === null) {
129 return (
130 <View className="flex-1 items-center justify-center gap-3 bg-sheet px-6">
131 <ActivityIndicator />
132 <Text className="text-center text-sm text-foreground-muted">Loading file...</Text>
133 </View>
134 );
135 }
136
137 return (
138 <View className="flex-1 bg-sheet">
139 {props.truncated ? (
140 <View className="border-b border-adaptive-amber-200-900-a60 bg-adaptive-amber-50-950-a40 px-4 py-2">
141 <Text className="text-2xs font-t3-bold uppercase text-adaptive-amber-700-300">
142 Partial file
143 </Text>
144 <Text className="text-xs leading-snug text-adaptive-amber-800-200">
145 Preview limited to the first 1 MB of a truncated file.
146 </Text>
147 </View>
148 ) : null}
149 {props.activeMode === "preview" && isMarkdown ? (
150 <FileMarkdownPreview markdown={props.fileContents} onRefresh={props.onRefresh} />
151 ) : (
152 <SourceFileSurface
153 contents={props.fileContents}
154 path={props.relativePath}
155 initialLine={props.initialLine}
156 onRefresh={props.onRefresh}
157 />
158 )}
159 </View>
160 );
161}
162
163type ThreadFilesRouteScreenProps = StaticScreenProps<{
164 readonly environmentId: string;
165 readonly threadId: string;
166}>;
167
168type ThreadFileRouteScreenProps = StaticScreenProps<{
169 readonly environmentId: string;
170 readonly threadId: string;
171 readonly path: string[];
172 readonly line?: string;
173}>;
174
175function useThreadFilesWorkspace(params: {
176 readonly environmentId?: string | string[];
177 readonly threadId?: string | string[];
178}) {
179 const routeEnvironmentId = firstRouteParam(params.environmentId);
180 const routeThreadId = firstRouteParam(params.threadId);
181 const { selectedThread, selectedThreadProject } = useThreadSelection();
182 const { selectedThreadCwd } = useSelectedThreadWorktree();
183 const environmentId =
184 routeEnvironmentId !== null
185 ? EnvironmentId.make(routeEnvironmentId)
186 : (selectedThread?.environmentId ?? null);
187 const threadId = routeThreadId !== null ? ThreadId.make(routeThreadId) : null;
188 const project = selectedThreadProject as {
189 readonly title?: string;
190 readonly workspaceRoot?: string;
191 } | null;
192
193 return {
194 cwd: selectedThreadCwd ?? project?.workspaceRoot ?? null,
195 environmentId,
196 projectName: project?.title ?? "Files",
197 selectedThread,
198 threadId,
199 };
200}
201
202function FilesUnavailable() {
203 return (
204 <View className="flex-1 items-center justify-center bg-sheet px-6">
205 <NativeStackScreenOptions options={{ title: "Files" }} />
206 <EmptyState
207 title="Files unavailable"
208 detail="This thread does not have an active workspace path."
209 />
210 </View>
211 );
212}
213
214function FilesToolbarBottomFade() {
215 const sheetColor = String(useUniwindTheme()["--color-sheet"]);
216
217 if (process.env.EXPO_OS !== "ios") {
218 return null;
219 }
220
221 return (
222 <View
223 pointerEvents="none"
224 accessibilityElementsHidden
225 importantForAccessibility="no-hide-descendants"
226 className="absolute inset-x-0 bottom-0 z-[1] h-28"
227 >
228 <Svg width="100%" height="100%">
229 <Defs>
230 <LinearGradient id="files-toolbar-bottom-fade" x1="0%" x2="0%" y1="0%" y2="100%">
231 <Stop offset="0%" stopColor={sheetColor} stopOpacity={0} />
232 <Stop offset="58%" stopColor={sheetColor} stopOpacity={0.72} />
233 <Stop offset="100%" stopColor={sheetColor} stopOpacity={0.96} />
234 </LinearGradient>
235 </Defs>
236 <Rect width="100%" height="100%" fill="url(#files-toolbar-bottom-fade)" />
237 </Svg>
238 </View>
239 );
240}
241
242export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
243 useAdaptiveWorkspacePaneRole("inspector");
244 const navigation = useNavigation();
245 const { fileInspector, layout, panes, showAuxiliaryPane, togglePrimarySidebar } =
246 useAdaptiveWorkspaceLayout();
247 const [searchQuery, setSearchQuery] = useState("");
248 const isAndroid = Platform.OS === "android";
249 const { themeAppearance: highlightTheme } = useAppearancePreferences();
250 const theme = useUniwindTheme();
251 const sheetSurfaceColor = theme["--color-sheet-solid"];
252 const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
253 props.route.params,
254 );
255 const revealedInspectorRef = useRef(false);
256 const entriesQuery = useEnvironmentQuery(
257 environmentId !== null && cwd !== null && !fileInspector.supported
258 ? projectEnvironment.listEntries({
259 environmentId,
260 input: { cwd },
261 })
262 : null,
263 );
264 const entriesData = entriesQuery.data as ProjectListEntriesResult | null;
265 const handleReturnToThread = useCallback(() => {
266 if (navigation.canGoBack()) {
267 navigation.goBack();
268 return;
269 }
270 if (environmentId !== null && threadId !== null) {
271 navigation.dispatch(
272 StackActions.replace("Thread", {
273 environmentId: String(environmentId),
274 threadId: String(threadId),
275 }),
276 );
277 }
278 }, [environmentId, navigation, threadId]);
279
280 const handleSelectFile = useCallback(
281 (path: string) => {
282 if (environmentId === null || threadId === null) {
283 return;
284 }
285 const params = {
286 environmentId: String(environmentId),
287 threadId: String(threadId),
288 path: path.split("/").filter((segment) => segment.length > 0),
289 };
290 const navigationAction = resolveFileSelectionNavigationAction({
291 hasPersistentFileInspector: fileInspector.supported,
292 });
293 if (navigationAction === "replace") {
294 navigation.dispatch(StackActions.replace("ThreadFile", params));
295 return;
296 }
297 navigation.navigate("ThreadFile", params);
298 },
299 [environmentId, fileInspector.supported, navigation, threadId],
300 );
301 const renderInspector = useCallback(
302 (headerInset: number) =>
303 environmentId !== null && cwd !== null ? (
304 <ThreadFileNavigatorPane
305 cwd={cwd}
306 environmentId={environmentId}
307 headerInset={headerInset}
308 projectName={projectName}
309 selectedPath={null}
310 onSelectFile={handleSelectFile}
311 />
312 ) : null,
313 [cwd, environmentId, handleSelectFile, projectName],
314 );
315 const handlePreviewFile = useCallback(
316 (relativePath: string) => {
317 if (environmentId === null || cwd === null) {
318 return;
319 }
320 preloadWorkspaceFileContents({
321 cwd,
322 environmentId,
323 relativePath,
324 theme: highlightTheme,
325 });
326 },
327 [cwd, environmentId, highlightTheme],
328 );
329 useEffect(() => {
330 if (fileInspector.supported && cwd !== null && !revealedInspectorRef.current) {
331 revealedInspectorRef.current = true;
332 showAuxiliaryPane("inspector");
333 }
334 }, [cwd, fileInspector.supported, showAuxiliaryPane]);
335
336 if (selectedThread === null || environmentId === null || threadId === null) {
337 if (fileInspector.supported) {
338 return (
339 <ThreadRouteScreen
340 onReturnToThread={handleReturnToThread}
341 renderInspector={renderInspector}
342 route={props.route}
343 />
344 );
345 }
346 return <LoadingScreen message="Opening files..." messagePlacement="above-spinner" />;
347 }
348
349 if (cwd === null) {
350 return <FilesUnavailable />;
351 }
352
353 if (fileInspector.supported) {
354 return (
355 <ThreadRouteScreen
356 onReturnToThread={handleReturnToThread}
357 renderInspector={renderInspector}
358 route={props.route}
359 />
360 );
361 }
362
363 const usesCompactMailToolbar =
364 Platform.OS === "ios" && !layout.usesSplitView && NATIVE_MAIL_SEARCH_TOOLBAR_SUPPORTED;
365
366 return (
367 <>
368 {/* Static header config (glass preset and title) lives in Stack.tsx. The
369 live sheet color stays dynamic here so the FlatList can remain the
370 direct scene child for native scroll-edge sampling. */}
371 <NativeStackScreenOptions
372 options={{
373 contentStyle: { backgroundColor: sheetSurfaceColor },
374 headerShown: !isAndroid,
375 unstable_headerSubtitle:
376 Platform.OS === "ios" && projectName.length > 0 ? projectName : undefined,
377 // No refresh button: the list already supports pull-to-refresh.
378 unstable_headerToolbarItems: usesCompactMailToolbar
379 ? () => [
380 createNativeMailSearchToolbarItem({
381 onSearchTextChange: setSearchQuery,
382 placeholder: "Search files",
383 searchTextChangeId: "files-search-text",
384 }),
385 ]
386 : undefined,
387 headerSearchBarOptions: usesCompactMailToolbar
388 ? undefined
389 : {
390 allowToolbarIntegration: true,
391 autoCapitalize: "none",
392 hideNavigationBar: false,
393 placeholder: "Search files",
394 onChangeText: (event) => {
395 setSearchQuery(event.nativeEvent.text);
396 },
397 onCancelButtonPress: () => {
398 setSearchQuery("");
399 },
400 },
401 }}
402 />
403 {isAndroid ? (
404 <>
405 <AndroidScreenHeader
406 title="Files"
407 subtitle={projectName}
408 onBack={handleReturnToThread}
409 actions={[
410 {
411 accessibilityLabel: "Refresh files",
412 icon: "arrow.clockwise",
413 onPress: entriesQuery.refresh,
414 },
415 ]}
416 />
417 <View className="flex-row items-center gap-2 border-b border-border px-3 py-2">
418 <SymbolView
419 name="magnifyingglass"
420 size={17}
421 tintColorClassName={"accent-icon-muted"}
422 type="monochrome"
423 />
424 <TextInput
425 accessibilityLabel="Search files"
426 autoCapitalize="none"
427 autoCorrect={false}
428 className="min-h-10 flex-1 rounded-xl py-2 text-sm"
429 placeholder="Search files"
430 value={searchQuery}
431 onChangeText={setSearchQuery}
432 />
433 </View>
434 </>
435 ) : (
436 <>
437 {layout.usesSplitView ? (
438 <NativeHeaderToolbar placement="left">
439 <NativeHeaderToolbar.Button
440 accessibilityLabel={panes.primarySidebarVisible ? "Maximize files" : "Show threads"}
441 icon={
442 panes.primarySidebarVisible
443 ? "arrow.up.left.and.arrow.down.right"
444 : "sidebar.left"
445 }
446 onPress={togglePrimarySidebar}
447 separateBackground
448 />
449 </NativeHeaderToolbar>
450 ) : null}
451 {usesCompactMailToolbar ? null : (
452 <NativeHeaderToolbar placement="bottom">
453 <NativeHeaderToolbar.SearchBarSlot />
454 </NativeHeaderToolbar>
455 )}
456 </>
457 )}
458 <FileTreeBrowser
459 entries={entriesData?.entries ?? []}
460 error={entriesQuery.error}
461 isPending={entriesQuery.isPending}
462 searchQuery={searchQuery}
463 selectedPath={null}
464 onPreviewFile={handlePreviewFile}
465 onRefresh={entriesQuery.refresh}
466 onSelectFile={handleSelectFile}
467 />
468 <FilesToolbarBottomFade />
469 </>
470 );
471}
472
473export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
474 useAdaptiveWorkspacePaneRole("inspector");
475 const navigation = useNavigation();
476 const { fileInspector, panes, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout();
477 const iconColor = useUniwindTheme()["--color-icon"];
478 const isAndroid = Platform.OS === "android";
479 const params = props.route.params;
480 const relativePath = normalizeRoutePath(params.path);
481 const targetLine = normalizeRouteLine(firstRouteParam(params.line));
482 const { cwd, environmentId, projectName, selectedThread, threadId } = useThreadFilesWorkspace(
483 props.route.params,
484 );
485 const [modeOverride, setModeOverride] = useState<{
486 readonly path: string;
487 readonly mode: FileViewMode;
488 } | null>(null);
489 const [previewRevision, setPreviewRevision] = useState(0);
490 const isBrowserFile = relativePath !== null && isBrowserPreviewFile(relativePath);
491 const isImageFile = relativePath !== null && isImagePreviewFile(relativePath);
492 const canPreview =
493 relativePath !== null && (isMarkdownPreviewFile(relativePath) || isBrowserFile || isImageFile);
494 const activeMode =
495 relativePath !== null && modeOverride?.path === relativePath
496 ? modeOverride.mode
497 : defaultViewMode(relativePath);
498 const resolvedActiveMode = canPreview ? activeMode : "source";
499 const assetPreviewPath = isBrowserFile || isImageFile ? relativePath : null;
500 const assetPreviewUri = useWorkspaceFileAssetUrl({
501 cwd,
502 environmentId,
503 relativePath: assetPreviewPath,
504 threadId,
505 });
506 const previewUri =
507 assetPreviewUri === null || previewRevision === 0
508 ? assetPreviewUri
509 : `${assetPreviewUri}${assetPreviewUri.includes("?") ? "&" : "?"}revision=${previewRevision}`;
510 const needsFileContents =
511 relativePath !== null &&
512 (resolvedActiveMode === "source" || isMarkdownPreviewFile(relativePath));
513 const fileQuery = useEnvironmentQuery(
514 environmentId !== null && cwd !== null && relativePath !== null && needsFileContents
515 ? projectEnvironment.readFile({
516 environmentId,
517 input: { cwd, relativePath },
518 })
519 : null,
520 );
521 const fileData = fileQuery.data as ProjectReadFileResult | null;
522
523 const handleSelectFile = useCallback(
524 (path: string) => {
525 navigation.navigate("ThreadFile", {
526 environmentId: String(environmentId),
527 threadId: String(threadId),
528 path: path.split("/").filter(Boolean),
529 });
530 },
531 [environmentId, navigation, threadId],
532 );
533 const renderInspector = useCallback(
534 (headerInset: number) =>
535 fileInspector.supported && environmentId !== null && cwd !== null ? (
536 <ThreadFileNavigatorPane
537 cwd={cwd}
538 environmentId={environmentId}
539 headerInset={headerInset}
540 projectName={projectName}
541 selectedPath={relativePath}
542 onSelectFile={handleSelectFile}
543 />
544 ) : undefined,
545 [cwd, environmentId, fileInspector.supported, handleSelectFile, projectName, relativePath],
546 );
547 // The workspace inspector column spans the full window height. On iOS the
548 // pane brings its own nested native header; elsewhere it pads itself below
549 // the top inset.
550 const safeAreaInsets = useSafeAreaInsets();
551 const inspectorHeaderInset = Platform.OS === "ios" ? 0 : safeAreaInsets.top;
552 // Hand the file navigator to the workspace so it renders beside the
553 // navigator, outside this screen's native header.
554 const renderWorkspaceInspector = useCallback(
555 () => renderInspector(inspectorHeaderInset),
556 [inspectorHeaderInset, renderInspector],
557 );
558 useRegisterWorkspaceInspector(fileInspector.supported ? renderWorkspaceInspector : undefined);
559
560 const fileMenuActions = useMemo(() => {
561 if (relativePath === null) return [];
562 const canToggleMode = canPreview && !isImageFile;
563 return [
564 canToggleMode
565 ? ({
566 id: "preview",
567 title: "Preview",
568 icon: "eye",
569 inline: true,
570 onPress: () => setModeOverride({ path: relativePath, mode: "preview" }),
571 } as const)
572 : null,
573 canToggleMode
574 ? ({
575 id: "source",
576 title: "Source",
577 icon: "doc.text",
578 inline: true,
579 onPress: () => setModeOverride({ path: relativePath, mode: "source" }),
580 } as const)
581 : null,
582 {
583 id: "copy-path",
584 title: "Copy path",
585 icon: "doc.on.doc",
586 inline: false,
587 onPress: () => copyTextWithHaptic(relativePath),
588 } as const,
589 isBrowserFile && typeof assetPreviewUri === "string"
590 ? ({
591 id: "open-browser",
592 title: Platform.OS === "ios" ? "Open in Safari" : "Open in browser",
593 icon: "safari",
594 inline: false,
595 onPress: () => tryOpenExternalUrl(assetPreviewUri, "file-preview"),
596 } as const)
597 : null,
598 resolvedActiveMode === "preview" && (isBrowserFile || isImageFile)
599 ? ({
600 id: "refresh",
601 title: "Refresh",
602 icon: "arrow.clockwise",
603 inline: false,
604 onPress: () => setPreviewRevision((current) => current + 1),
605 } as const)
606 : null,
607 ].filter((action) => action !== null);
608 }, [assetPreviewUri, canPreview, isBrowserFile, isImageFile, relativePath, resolvedActiveMode]);
609
610 const androidFileMenuActions = useMemo<MenuAction[]>(
611 () =>
612 fileMenuActions.map((action) => ({
613 id: action.id,
614 title: action.title,
615 image: action.icon,
616 state: action.id === resolvedActiveMode ? "on" : undefined,
617 })),
618 [fileMenuActions, resolvedActiveMode],
619 );
620 const handleAndroidFileMenuAction = useCallback(
621 (event: { nativeEvent: { event: string } }) => {
622 const action = fileMenuActions.find(({ id }) => id === event.nativeEvent.event);
623 void action?.onPress();
624 },
625 [fileMenuActions],
626 );
627 const handleReturnToThread = useCallback(() => {
628 if (environmentId !== null && threadId !== null) {
629 navigation.dispatch(
630 StackActions.replace("Thread", {
631 environmentId: String(environmentId),
632 threadId: String(threadId),
633 }),
634 );
635 }
636 }, [environmentId, navigation, threadId]);
637 const handleBack = useCallback(() => {
638 if (navigation.canGoBack()) {
639 navigation.goBack();
640 return;
641 }
642 handleReturnToThread();
643 }, [handleReturnToThread, navigation]);
644
645 if (selectedThread === null || environmentId === null || threadId === null) {
646 return <LoadingScreen message="Opening file..." messagePlacement="above-spinner" />;
647 }
648
649 if (cwd === null) {
650 return <FilesUnavailable />;
651 }
652
653 if (relativePath === null) {
654 return (
655 <View className="flex-1 items-center justify-center bg-sheet px-6">
656 <NativeStackScreenOptions options={{ title: "Files" }} />
657 <EmptyState title="File unavailable" detail="This file path is invalid." />
658 </View>
659 );
660 }
661
662 const parentDir = relativePath.split("/").slice(0, -1).join("/");
663 const headerSubtitle = [projectName, parentDir].filter(Boolean).join(" · ");
664
665 return (
666 <ReviewHighlighterProvider>
667 <View className="flex-1 bg-sheet">
668 <NativeStackScreenOptions
669 options={{
670 // Static header config lives in Stack.tsx (SOLID_HEADER_OPTIONS: solid
671 // sheet-colored header — this route's content scrolls internally, so
672 // there is nothing for glass to sample). Only dynamic values here.
673 headerShown: !isAndroid,
674 headerTintColor: iconColor,
675 headerTitle: basename(relativePath),
676 title: basename(relativePath),
677 unstable_headerSubtitle:
678 Platform.OS === "ios" && headerSubtitle.length > 0 ? headerSubtitle : undefined,
679 }}
680 />
681 {isAndroid ? (
682 <AndroidScreenHeader
683 title={basename(relativePath)}
684 subtitle={headerSubtitle}
685 onBack={handleBack}
686 trailing={
687 <>
688 {fileInspector.supported ? (
689 <AndroidHeaderIconButton
690 accessibilityLabel={
691 panes.auxiliaryPaneVisible ? "Hide file navigator" : "Show file navigator"
692 }
693 icon="sidebar.right"
694 onPress={toggleAuxiliaryPane}
695 />
696 ) : null}
697 <ControlPillMenu
698 actions={androidFileMenuActions}
699 isAnchoredToRight
700 title="File actions"
701 onPressAction={handleAndroidFileMenuAction}
702 >
703 <AndroidHeaderIconButton accessibilityLabel="File actions" icon="ellipsis" />
704 </ControlPillMenu>
705 </>
706 }
707 />
708 ) : null}
709 <WorkspaceSidebarToolbar>
710 {fileInspector.supported ? (
711 <NativeHeaderToolbar.Button
712 accessibilityLabel="Return to chat"
713 icon="chevron.left"
714 onPress={handleReturnToThread}
715 />
716 ) : null}
717 </WorkspaceSidebarToolbar>
718 <NativeHeaderToolbar placement="right">
719 {fileInspector.supported ? (
720 <NativeHeaderToolbar.Button
721 accessibilityLabel={
722 panes.auxiliaryPaneVisible ? "Hide file navigator" : "Show file navigator"
723 }
724 icon="sidebar.right"
725 onPress={toggleAuxiliaryPane}
726 separateBackground
727 />
728 ) : null}
729 <NativeHeaderToolbar.Menu accessibilityLabel="File actions" icon="ellipsis">
730 {fileMenuActions.some(({ inline }) => inline) ? (
731 <NativeHeaderToolbar.Menu inline>
732 {fileMenuActions
733 .filter(({ inline }) => inline)
734 .map((action) => (
735 <NativeHeaderToolbar.MenuAction
736 key={action.id}
737 icon={action.icon}
738 isOn={action.id === resolvedActiveMode}
739 onPress={action.onPress}
740 >
741 {action.title}
742 </NativeHeaderToolbar.MenuAction>
743 ))}
744 </NativeHeaderToolbar.Menu>
745 ) : null}
746 {fileMenuActions
747 .filter(({ inline }) => !inline)
748 .map((action) => (
749 <NativeHeaderToolbar.MenuAction
750 key={action.id}
751 icon={action.icon}
752 onPress={action.onPress}
753 >
754 {action.title}
755 </NativeHeaderToolbar.MenuAction>
756 ))}
757 </NativeHeaderToolbar.Menu>
758 </NativeHeaderToolbar>
759 <FileContent
760 activeMode={resolvedActiveMode}
761 previewUri={previewUri}
762 fileContents={fileData?.contents ?? null}
763 fileError={fileQuery.error}
764 initialLine={targetLine}
765 relativePath={relativePath}
766 truncated={fileData?.truncated ?? false}
767 onRefresh={() => fileQuery.refresh()}
768 />
769 </View>
770 </ReviewHighlighterProvider>
771 );
772}