Skip to content
TypeScript

fix(mobile): restore file viewer insets and glass header (#17073)

Julius Marmingee803242d936a
diff --git a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffModule.swift b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffModule.swift
index 96a1785f9fc..5564dce34af 100644
--- a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffModule.swift
+++ b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffModule.swift
@@ -49,6 +49,14 @@ public class T3ReviewDiffModule: Module {
view.setContentWidth(CGFloat(contentWidth))
}
+ Prop("contentInsetTop") { (view: T3ReviewDiffView, inset: Double) in
+ view.setContentInsetTop(CGFloat(inset))
+ }
+
+ Prop("contentInsetBottom") { (view: T3ReviewDiffView, inset: Double) in
+ view.setContentInsetBottom(CGFloat(inset))
+ }
+
Prop("initialRowIndex") { (view: T3ReviewDiffView, initialRowIndex: Double) in
view.setInitialRowIndex(initialRowIndex)
}
diff --git a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift
index 928e3b5669d..dfddaf7016c 100644
--- a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift
+++ b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift
@@ -563,6 +563,24 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
])
}
+ // Source files fill the screen so UIKit can sample content below the glass bar.
+ // Keep the same visible row when header or safe-area reservations change.
+ func setContentInsetTop(_ inset: CGFloat) {
+ scrollView.automaticallyAdjustsScrollIndicatorInsets = false
+ let inset = max(0, inset)
+ let delta = inset - scrollView.contentInset.top
+ guard delta != 0 else { return }
+ scrollView.contentInset.top = inset
+ scrollView.verticalScrollIndicatorInsets.top = inset
+ scrollView.contentOffset.y -= delta
+ updateViewportFrame()
+ }
+
+ func setContentInsetBottom(_ inset: CGFloat) {
+ scrollView.contentInset.bottom = max(0, inset)
+ scrollView.verticalScrollIndicatorInsets.bottom = max(0, inset)
+ }
+
func setContentResetKey(_ contentResetKey: String) {
guard contentResetKey != self.contentResetKey else {
return
@@ -577,7 +595,7 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
hasAppliedInitialRowIndex = false
pendingScrollFileId = nil
isProgrammaticScrollActive = false
- scrollView.setContentOffset(.zero, animated: false)
+ scrollView.setContentOffset(CGPoint(x: 0, y: -scrollView.contentInset.top), animated: false)
updateContentMetrics()
updateViewportFrame()
lastVisibleFileId = nil
@@ -870,8 +888,12 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
}
private func setVerticalContentOffset(_ targetOffset: CGFloat, animated: Bool) {
- let maxOffset = max(scrollView.contentSize.height - scrollView.bounds.height, 0)
- let clampedOffset = min(max(targetOffset, 0), maxOffset)
+ let topInset = scrollView.contentInset.top
+ let maxOffset = max(
+ scrollView.contentSize.height - scrollView.bounds.height + scrollView.contentInset.bottom,
+ -topInset
+ )
+ let clampedOffset = min(max(targetOffset - topInset, -topInset), maxOffset)
let shouldAnimate = animated && abs(scrollView.contentOffset.y - clampedOffset) > 0.5
isProgrammaticScrollActive = shouldAnimate
contentView.isVerticalScrollActive = shouldAnimate
@@ -889,12 +911,10 @@ public final class T3ReviewDiffView: ExpoView, UIScrollViewDelegate {
return
}
- let targetScreenY = max(0, (bounds.height - rowFrame.height) * 0.3)
- let maxOffset = max(scrollView.contentSize.height - scrollView.bounds.height, 0)
- let targetOffset = min(max(rowFrame.minY - targetScreenY, 0), maxOffset)
+ let visibleHeight = bounds.height - scrollView.contentInset.top - scrollView.contentInset.bottom
+ let targetScreenY = max(0, (visibleHeight - rowFrame.height) * 0.3)
hasAppliedInitialRowIndex = true
- scrollView.setContentOffset(CGPoint(x: 0, y: targetOffset), animated: false)
- updateViewportFrame()
+ setVerticalContentOffset(rowFrame.minY - targetScreenY, animated: false)
}
}
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx
index b215ba33807..569bfc11ada 100644
--- a/apps/mobile/src/Stack.tsx
+++ b/apps/mobile/src/Stack.tsx
@@ -159,7 +159,7 @@ const GLASS_HEADER_OPTIONS: AppScreenOptions = {
};
// SOLID: opaque sheet-colored header for surfaces whose content scrolls internally
-// (file viewer, terminal, review) — there is nothing for glass to sample there.
+// (terminal, review) — there is nothing for glass to sample there.
const SOLID_HEADER_OPTIONS: AppScreenOptions = {
headerBackButtonDisplayMode: "minimal",
headerBackTitle: "",
@@ -750,7 +750,7 @@ const RootStackConfig = createWorkspaceStackNavigator({
ThreadFile: createNativeStackScreen({
screen: ThreadFileScreen,
linking: `${THREAD_LINKING_PREFIX}/files/:path*`,
- options: SOLID_HEADER_OPTIONS,
+ options: GLASS_HEADER_OPTIONS,
}),
ThreadMcpApp: createNativeStackScreen({
screen: McpAppFullscreenScreen,
diff --git a/apps/mobile/src/components/ComposerContextSheet.tsx b/apps/mobile/src/components/ComposerContextSheet.tsx
index 208c15268ec..4fbc02ab1e4 100644
--- a/apps/mobile/src/components/ComposerContextSheet.tsx
+++ b/apps/mobile/src/components/ComposerContextSheet.tsx
@@ -47,6 +47,7 @@ function ContextField(props: { label: string; value: string | null | undefined;
style={{ height: Math.min(260, Math.max(100, props.value.split("\n").length * 22 + 36)) }}
>
<SourceFileSurface
+ embedded
contents={props.value}
path={props.label === "HTML" ? "element.html" : "styles.css"}
/>
diff --git a/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts b/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
index fda73410668..16208a7d5a2 100644
--- a/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
+++ b/apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
@@ -121,6 +121,8 @@ export interface NativeReviewDiffViewProps extends ViewProps {
readonly styleJson?: string;
readonly rowHeight: number;
readonly contentWidth: number;
+ readonly contentInsetTop?: number;
+ readonly contentInsetBottom?: number;
readonly initialRowIndex?: number;
readonly refreshing?: boolean;
readonly nativeViewRef?: Ref<NativeReviewDiffViewHandle>;
diff --git a/apps/mobile/src/features/files/FileTreeBrowser.tsx b/apps/mobile/src/features/files/FileTreeBrowser.tsx
index ed42f5345ab..4d313b47b49 100644
--- a/apps/mobile/src/features/files/FileTreeBrowser.tsx
+++ b/apps/mobile/src/features/files/FileTreeBrowser.tsx
@@ -8,7 +8,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppText as Text } from "../../components/AppText";
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
import { cn } from "../../lib/cn";
-import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";
+import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
import {
buildFileTree,
flattenFileTree,
@@ -42,7 +42,6 @@ const FileTreeRow = memo(function FileTreeRow(props: {
readonly item: VisibleFileTreeNode;
readonly selected: boolean;
readonly expanded: boolean;
- readonly loaded: boolean;
readonly loading: boolean;
readonly onPressDirectory: (path: string, expand: boolean) => void;
readonly onPreviewFile?: (path: string) => void;
@@ -98,10 +97,6 @@ const FileTreeRow = memo(function FileTreeRow(props: {
</Text>
{node.kind === "directory" && props.expanded && props.loading ? (
<ActivityIndicator size="small" accessibilityLabel={`Loading ${node.name}`} />
- ) : node.kind === "directory" && props.loaded ? (
- <Text className="text-2xs font-t3-medium text-foreground-tertiary">
- {node.children.length}
- </Text>
) : null}
</Pressable>
);
@@ -115,7 +110,6 @@ export function FileTreeBrowser(props: {
readonly searchQuery: string;
readonly searchTruncated: boolean;
readonly selectedPath: string | null;
- readonly loadedDirectories: ReadonlySet<string>;
readonly loadingDirectories: ReadonlySet<string>;
readonly onLoadDirectory: (path: string) => void;
readonly onPreviewFile?: (path: string) => void;
@@ -128,14 +122,12 @@ export function FileTreeBrowser(props: {
readonly selectedPathAtPress: string | null;
} | null>(null);
const insets = useSafeAreaInsets();
- // Native transparent-header height ≈ safe-area top + nav bar (~44). Matches the
- // observed adjustedContentInset bottom (~102) seen in the native trace.
- const headerInset = Platform.OS === "ios" ? insets.top + IOS_NAV_BAR_HEIGHT : 0;
+ const columnMetrics = useNativeColumnLayoutMetrics();
+ const headerInset = Platform.OS === "ios" ? (columnMetrics?.safeArea.top ?? insets.top) : 0;
const {
onLoadDirectory,
onPreviewFile,
onSelectFile,
- loadedDirectories,
loadingDirectories,
selectedPath: controlledSelectedPath,
} = props;
@@ -226,7 +218,6 @@ export function FileTreeBrowser(props: {
item={item}
selected={item.node.kind === "file" && item.node.path === selectedPath}
expanded={expandedPaths.has(item.node.path)}
- loaded={loadedDirectories.has(item.node.path)}
loading={loadingDirectories.has(item.node.path)}
onPressDirectory={toggleDirectory}
onPreviewFile={onPreviewFile}
@@ -237,7 +228,6 @@ export function FileTreeBrowser(props: {
expandedPaths,
handleSelectFile,
onPreviewFile,
- loadedDirectories,
loadingDirectories,
selectedPath,
toggleDirectory,
@@ -245,8 +235,8 @@ export function FileTreeBrowser(props: {
);
const extraData = useMemo(
- () => ({ expandedPaths, loadedDirectories, loadingDirectories, selectedPath }),
- [expandedPaths, loadedDirectories, loadingDirectories, selectedPath],
+ () => ({ expandedPaths, loadingDirectories, selectedPath }),
+ [expandedPaths, loadingDirectories, selectedPath],
);
// UIKit owns the header inset on every supported iOS version. Keep the
@@ -259,9 +249,7 @@ export function FileTreeBrowser(props: {
data={visibleNodes}
keyExtractor={(item) => item.node.path}
contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
- scrollIndicatorInsets={
- Platform.OS === "ios" ? { top: headerInset, left: 0, right: 0, bottom: 0 } : undefined
- }
+ automaticallyAdjustsScrollIndicatorInsets={Platform.OS === "ios"}
keyboardDismissMode="on-drag"
keyboardShouldPersistTaps="handled"
estimatedItemSize={42}
diff --git a/apps/mobile/src/features/files/SourceFileSurface.tsx b/apps/mobile/src/features/files/SourceFileSurface.tsx
index 42b7dbf282d..928da8b0f54 100644
--- a/apps/mobile/src/features/files/SourceFileSurface.tsx
+++ b/apps/mobile/src/features/files/SourceFileSurface.tsx
@@ -11,9 +11,10 @@ import {
useWindowDimensions,
View,
} from "react-native";
-
+import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppText as Text } from "../../components/AppText";
import { LoadingStrip } from "../../components/LoadingStrip";
+import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
import {
type NativeReviewDiffViewProps,
resolveNativeReviewDiffView,
@@ -39,7 +40,11 @@ import { sourceHighlightAtom } from "./sourceHighlightingState";
interface SourceFileSurfaceProps {
readonly contents: string;
readonly path: string;
+ /** The enclosing sheet or card already reserves its own chrome and safe area. */
+ readonly embedded?: boolean;
readonly initialLine?: number | null;
+ /** Override when a fixed notice already reserves the native header. */
+ readonly headerInsetTop?: number;
/** Keep the entire document in one native text-selection scope. */
readonly selectable?: boolean;
/** Enables native pull-to-refresh on the source surface. */
@@ -184,6 +189,9 @@ function NativeSourceFileSurface(
},
) {
const { NativeView, onRefresh } = props;
+ const insets = useSafeAreaInsets();
+ const columnMetrics = useNativeColumnLayoutMetrics();
+ const safeArea = columnMetrics?.safeArea ?? insets;
const { codeSurface, codeWordBreak, nativeSourceStyle } = useAppearanceCodeSurface();
const { themeAppearance, themeId } = useAppearancePreferences();
const appTheme = useUniwindTheme();
@@ -214,6 +222,8 @@ function NativeSourceFileSurface(
appearanceScheme={themeAppearance}
contentResetKey={props.path}
contentWidth={contentWidth}
+ contentInsetTop={props.embedded ? 0 : (props.headerInsetTop ?? safeArea.top)}
+ contentInsetBottom={props.embedded ? 0 : safeArea.bottom + 8}
initialRowIndex={targetIndex ?? -1}
rowHeight={nativeSourceStyle.rowHeight ?? codeSurface.rowHeight}
rowsJson={rowsJson}
@@ -233,6 +243,7 @@ function NativeSourceFileSurface(
}
function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
+ const usesAutomaticInsets = Platform.OS === "ios" && !props.embedded;
const foreground = useUniwindTheme()["--color-foreground"];
const { codeSurface, codeWordBreak } = useAppearanceCodeSurface();
const { normalizedContents, lines, status, targetIndex, tokens } = useSourceFileModel(props);
@@ -323,6 +334,8 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
const list = (
<FlatList
ref={listRef}
+ contentInsetAdjustmentBehavior={usesAutomaticInsets ? "automatic" : "never"}
+ automaticallyAdjustsScrollIndicatorInsets={usesAutomaticInsets}
refreshControl={refreshControl}
data={lines}
keyExtractor={(_line, index) => String(index)}
@@ -354,6 +367,8 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
<ScrollView
refreshControl={refreshControl}
className="flex-1"
+ contentInsetAdjustmentBehavior={usesAutomaticInsets ? "automatic" : "never"}
+ automaticallyAdjustsScrollIndicatorInsets={usesAutomaticInsets}
contentContainerStyle={{
paddingBottom: codeSurface.rowHeight,
paddingHorizontal: 12,
@@ -393,9 +408,11 @@ export function SourceFileSurface(props: SourceFileSurfaceProps) {
// The native canvas draws source lines without text selection or wrapping. Attachments
// need one selectable text view in either wrap mode; workspace line navigation can still
// use the canvas when wrapping is disabled.
- return NativeView && !codeWordBreak && !props.selectable ? (
- <NativeSourceFileSurface {...props} NativeView={NativeView} />
- ) : (
- <JavaScriptSourceFileSurface {...props} />
- );
+ const surface =
+ NativeView && !codeWordBreak && !props.selectable ? (
+ <NativeSourceFileSurface {...props} NativeView={NativeView} />
+ ) : (
+ <JavaScriptSourceFileSurface {...props} />
+ );
+ return surface;
}
diff --git a/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx b/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
index 6c8cac046bb..ca9adeaea16 100644
--- a/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
+++ b/apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
@@ -48,6 +48,7 @@ import { FileTreeBrowser } from "./FileTreeBrowser";
import { useFileTreeEntries } from "./useFileTreeEntries";
import { preloadWorkspaceFileContents } from "./preload-workspace-file";
import { SourceFileSurface } from "./SourceFileSurface";
+import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
import { ThreadFileNavigatorPane } from "./thread-file-navigator-pane";
import { ScreenHeader } from "../../components/ScreenHeader";
import { WorkspaceFileImagePreview } from "./WorkspaceFileImagePreview";
@@ -229,6 +230,10 @@ function FileContent(props: {
}) {
// Reopening a mutable host file must not reuse a poster from an earlier visit.
const thumbnailInstanceId = useId();
+ const insets = useSafeAreaInsets();
+ const columnMetrics = useNativeColumnLayoutMetrics();
+ const reservedHeaderInset =
+ Platform.OS === "ios" && props.truncated ? (columnMetrics?.safeArea.top ?? insets.top) : 0;
const isMarkdown = isMarkdownPreviewFile(props.relativePath);
const isBrowserFile = isWorkspaceBrowserPreviewPath(props.relativePath);
const isImageFile = isWorkspaceImagePreviewPath(props.relativePath);
@@ -300,7 +305,7 @@ function FileContent(props: {
}
return (
- <View className="flex-1 bg-sheet">
+ <View className="flex-1 bg-sheet" style={{ paddingTop: reservedHeaderInset }}>
{props.truncated ? (
<FilePreviewNotice title="Partial file">
Preview limited to the first 1 MB of a truncated file.
@@ -320,6 +325,7 @@ function FileContent(props: {
contents={props.fileContents}
path={props.relativePath}
initialLine={props.initialLine}
+ headerInsetTop={props.truncated ? 0 : undefined}
onRefresh={props.onRefresh}
/>
)}
@@ -561,7 +567,6 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
<FileTreeBrowser
key={JSON.stringify([environmentId, cwd])}
entries={entriesQuery.entries}
- loadedDirectories={entriesQuery.loadedDirectories}
loadingDirectories={entriesQuery.loadingDirectories}
onLoadDirectory={entriesQuery.loadDirectory}
error={entriesQuery.error}
diff --git a/apps/mobile/src/features/files/thread-file-navigator-pane.tsx b/apps/mobile/src/features/files/thread-file-navigator-pane.tsx
index 998c23b1e30..9ee450edfed 100644
--- a/apps/mobile/src/features/files/thread-file-navigator-pane.tsx
+++ b/apps/mobile/src/features/files/thread-file-navigator-pane.tsx
@@ -87,7 +87,6 @@ export function ThreadFileNavigatorPane(props: {
<FileTreeBrowser
key={JSON.stringify([props.environmentId, props.cwd])}
entries={entriesQuery.entries}
- loadedDirectories={entriesQuery.loadedDirectories}
loadingDirectories={entriesQuery.loadingDirectories}
onLoadDirectory={entriesQuery.loadDirectory}
error={