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