Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(mobile): 精简文件预览并统一悬浮玻璃操作

Dash366098d74559
diff --git a/apps/mobile/app/files/preview/[sessionId].tsx b/apps/mobile/app/files/preview/[sessionId].tsx
index 24e384265f..0f3c5d97e1 100644
--- a/apps/mobile/app/files/preview/[sessionId].tsx
+++ b/apps/mobile/app/files/preview/[sessionId].tsx
@@ -1,4 +1,3 @@
-import { SystemNavigationBack, useSystemNavigationBack } from '@/platform/chrome/SystemNavigationBack';
/**
* 远程文件 Quick Look 预览。
*
@@ -11,7 +10,7 @@ import { SystemNavigationBack, useSystemNavigationBack } from '@/platform/chrome
* 文本 = readFile(acceptGzip,pako 解码)+ 行号列表;图片 = 缩略图立即显示,
* OSS 导出原图就绪后无缝换源(不出 loading 态,规则 7);其它 = 占位 + 下载。
* markdown 与 HTML 额外有「渲染 / 源码」双态,默认渲染。HTML 使用浮动浏览器控件,
- * 源码和文件操作收进更多菜单;markdown 保留原来的切换栏并复用已读文本。
+ * 所有文件共用悬浮控件,源码切换、文件信息与路径操作收进更多菜单。
* HTML 渲染完整目录快照,源码仍走文本通道与原有大小限制。
*
* absPath 单文件模式(route 参 absPath,与 relPath 互斥):聊天 chip 指向
@@ -26,7 +25,7 @@ import { Image } from 'expo-image';
import { useFocusEffect, useIsFocused, useLocalSearchParams, useRouter } from 'expo-router';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { ArrowDownToLine, Copy, Database, File as FileIcon, Info, MessageSquarePlus, Share as ShareIcon } from 'lucide-react-native';
+import { ArrowDownToLine, Database, File as FileIcon, Info } from 'lucide-react-native';
import {
ActivityIndicator,
Alert,
@@ -60,7 +59,6 @@ import { decodeGzipBase64Text, mergePathIntoComposerDraft, shareMimeForFileName
import { appendQuote, truncateQuoteText } from '@/session/chatQuoteStore';
import { getCachedPreviewText, storeCachedPreviewText } from '@/session/fileBrowserCache';
import { exportRemoteFileToUrl } from '@/session/fileBrowserExport';
-import { FileTransferBusyNotice } from '@/session/FileTransferBusyNotice';
import type { RemoteMediaSshContext } from '@/session/fileBrowserGallery';
import { HtmlSnapshotReader } from '@/session/HtmlFileReader';
import { HtmlPreviewLoading } from '@/session/HtmlPreviewLoading';
@@ -72,7 +70,7 @@ import type { MobileHtmlPreview } from '@/session/mobileHtmlPreview';
import { prepareMobileHtmlPreview, type PrepareMobileHtmlPreview } from '@/session/mobileHtmlPreview';
import { useHtmlSnapshot } from '@/session/useHtmlSnapshot';
import { MainWindowActionButton } from '@/components/MobilePrimitives';
-import { FileBrowserSegmentedControl } from '@/session/FileBrowserSegmentedControl';
+import { useHtmlBrowserViewport } from '@/session/useHtmlBrowserViewport';
import { MarkdownFileReader } from '@/session/MarkdownFileReader';
import { RemoteMediaPlayerWebView } from '@/session/mediaPlayerWebView';
import { NativeVideoPlayer } from '@/session/NativeVideoPlayer';
@@ -119,7 +117,7 @@ type TextPreviewState =
type RichTextKind = 'markdown' | 'html';
type HtmlBrowserActions = Pick<HtmlBrowserChromeProps,
- 'busy' | 'notice' | 'onCancelNotice' | 'onClose' | 'onShare' | 'onCopyPath' | 'onAddToTask'>;
+ 'meta' | 'busy' | 'notice' | 'onCancelNotice' | 'onClose' | 'onShare' | 'onCopyPath' | 'onAddToTask'>;
interface SiblingListing {
key: string;
@@ -198,7 +196,6 @@ function RemoteFilePreviewContent() {
const targetLineRaw = Number(readRouteString(params.line) ?? '');
const targetLine = Number.isInteger(targetLineRaw) && targetLineRaw > 0 ? targetLineRaw : null;
const router = useRouter();
- const systemBack = useSystemNavigationBack();
const previewWindow = useAdaptiveWindow();
const pageInsets = useSafeAreaInsets();
const [measuredPageWidth, setMeasuredPageWidth] = useState<number | null>(null);
@@ -659,15 +656,7 @@ function RemoteFilePreviewContent() {
);
}
return (
- <SafeAreaView style={styles.safeArea} testID="filePreview.screen">
- <SystemNavigationBack close label={t('files.preview.done')} onPress={() => goBackGuarded(router)} />
- <PreviewNav
- hideDone={systemBack}
- meta=""
- onDone={() => goBackGuarded(router)}
- onShare={null}
- title={pathDisplayName(singleAbsPath ?? initialRelPath)}
- />
+ <SafeAreaView edges={[]} style={styles.safeArea} testID="filePreview.screen">
<View style={styles.centerFill}>
{error ? <>
<Text style={styles.hintText}>{t('files.preview.readFailed')}</Text>
@@ -677,29 +666,27 @@ function RemoteFilePreviewContent() {
} }} />
</> : <ActivityIndicator color={colors.textTertiary} />}
</View>
+ <HtmlBrowserChrome
+ document
+ title={pathDisplayName(pendingPath)}
+ path={absolutePathOf(pendingPath)}
+ top={pageInsets.top}
+ bottom={pageInsets.bottom}
+ left={pageInsets.left + spacing.md}
+ right={pageInsets.right + spacing.md}
+ busy
+ pending
+ onClose={() => goBackGuarded(router)}
+ onShare={() => {}}
+ onCopyPath={() => {}}
+ onAddToTask={() => {}}
+ />
</SafeAreaView>
);
}
- const htmlBrowser = richTextKindOf(current.relPath) === 'html';
return (
- <SafeAreaView edges={htmlBrowser ? [] : undefined} style={styles.safeArea} testID="filePreview.screen">
- {!htmlBrowser ? <>
- <SystemNavigationBack close label={t('files.preview.done')} onPress={() => goBackGuarded(router)} />
- <PreviewNav
- hideDone={systemBack}
- meta={[
- `${pageIndex + 1} / ${siblings.length}`,
- // absPath 单文件模式没有目录列举,size 未知(0)不显示,避免「0 B」。
- ...(current.sizeBytes > 0 ? [formatByteSize(current.sizeBytes)] : []),
- ].join(' · ')}
- onDone={() => goBackGuarded(router)}
- onShare={() => void downloadAndShare(current)}
- title={current.name}
- />
- <View style={styles.navHairline} />
- </> : null}
-
+ <SafeAreaView edges={[]} style={styles.safeArea} testID="filePreview.screen">
<FlatList
onLayout={event => setMeasuredPageWidth(Math.max(1, event.nativeEvent.layout.width))}
data={siblings}
@@ -739,6 +726,10 @@ function RemoteFilePreviewContent() {
maker={maker}
onDownload={() => void downloadAndShare(item)}
htmlBrowserActions={{
+ meta: [
+ `${index + 1} / ${siblings.length}`,
+ ...(item.sizeBytes > 0 ? [formatByteSize(item.sizeBytes)] : []),
+ ].join(' · '),
busy: !!busyLabel,
notice: busyLabel ?? notice,
// busyLabel 只由导出 / 分享设置,进行中的提示带「取消」。
@@ -784,31 +775,6 @@ function RemoteFilePreviewContent() {
windowSize={3}
/>
- {!htmlBrowser ? <>
- <View style={styles.toolbarHairline} />
- <View style={styles.toolbar}>
- <ToolbarButton
- disabled={!!busyLabel}
- Icon={Copy}
- label={t('files.preview.copyPath')}
- onPress={() => void copyPath(current)}
- testID="filePreview.copyPath"
- />
- <ToolbarButton
- disabled={!!busyLabel}
- Icon={MessageSquarePlus}
- label={t('files.preview.sendToSession')}
- onPress={() => sendToSession(current)}
- testID="filePreview.sendToSession"
- />
- </View>
- {busyLabel ? (
- <FileTransferBusyNotice label={busyLabel} onCancel={cancelExport} testID="filePreview.busy" />
- ) : notice ? (
- <Text style={styles.noticeText} testID="filePreview.notice">{notice}</Text>
- ) : null}
- </> : null}
-
{lightboxImages.length > 0 ? (
<ImageLightbox
images={lightboxImages}
@@ -822,42 +788,6 @@ function RemoteFilePreviewContent() {
/* ------------------------------ 页面组件 ------------------------------ */
-function PreviewNav({
- hideDone = false,
- meta,
- onDone,
- onShare,
- title,
-}: {
- hideDone?: boolean;
- meta: string;
- onDone(): void;
- onShare: (() => void) | null;
- title: string;
-}) {
- const styles = useThemedStyles(makeStyles);
- const { colors } = useTheme();
- const { t } = useTranslation();
- return (
- <View style={styles.navRow}>
- {!hideDone ? <Pressable accessibilityLabel={t('files.preview.done')} hitSlop={10} onPress={onDone} testID="filePreview.done">
- <Text style={styles.doneText}>{t('files.preview.done')}</Text>
- </Pressable> : null}
- <View style={styles.navTitleCol}>
- <Text numberOfLines={1} style={styles.navTitle} testID="filePreview.title">{title}</Text>
- {meta ? <Text numberOfLines={1} style={styles.navMeta}>{meta}</Text> : null}
- </View>
- {onShare ? (
- <Pressable accessibilityLabel={t('files.preview.a11yShare')} hitSlop={10} onPress={onShare} testID="filePreview.share">
- <ShareIcon color={colors.textPrimary} size={iconSize.xl} strokeWidth={iconStroke.regular} />
- </Pressable>
- ) : (
- <View style={{ width: iconSize.xl }} />
- )}
- </View>
- );
-}
-
function FilePreviewPage({
deviceId,
absolutePathOf,
@@ -903,8 +833,18 @@ function FilePreviewPage({
workdir: string;
}) {
const { t } = useTranslation();
+ const styles = useThemedStyles(makeStyles);
+ const insets = useSafeAreaInsets();
+ const contentPadding = {
+ paddingTop: insets.top + HTML_BROWSER_CONTROL_SIZE + spacing.xs,
+ paddingBottom: insets.bottom + spacing.xs,
+ paddingLeft: insets.left,
+ paddingRight: insets.right,
+ };
+ const avKind = avKindFor(item.relPath);
+ let content;
if (item.thumb === 'image') {
- return (
+ content = (
<ImagePreviewPage
active={active}
exportToUrl={exportToUrl}
@@ -914,15 +854,11 @@ function FilePreviewPage({
workdir={workdir}
/>
);
- }
- if (item.previewKind === 'pdf') {
- return <PdfPreviewPage active={active} exportToUrl={exportToUrl} item={item} onDownload={onDownload} recoveryEpoch={recoveryEpoch} workdir={workdir} />;
- }
- const avKind = avKindFor(item.relPath);
- if (avKind) {
- return <AvPreviewPage active={active} exportToUrl={exportToUrl} item={item} kind={avKind} onDownload={onDownload} visible={visible} workdir={workdir} />;
- }
- if (item.thumb === 'doc') {
+ } else if (item.previewKind === 'pdf') {
+ content = <PdfPreviewPage active={active} exportToUrl={exportToUrl} item={item} onDownload={onDownload} recoveryEpoch={recoveryEpoch} workdir={workdir} />;
+ } else if (avKind) {
+ content = <AvPreviewPage active={active} exportToUrl={exportToUrl} item={item} kind={avKind} onDownload={onDownload} visible={visible} workdir={workdir} />;
+ } else if (item.thumb === 'doc') {
return (
<TextPreviewPage
key={maker.fileBrowser.cacheScope}
@@ -944,8 +880,24 @@ function FilePreviewPage({
workdir={workdir}
/>
);
+ } else {
+ content = <UnsupportedPage item={item} onDownload={onDownload} reason={t('files.preview.unsupportedType')} />;
}
- return <UnsupportedPage item={item} onDownload={onDownload} reason={t('files.preview.unsupportedType')} />;
+ return (
+ <View style={styles.textPage}>
+ <View style={[styles.textPage, item.previewKind !== 'pdf' && contentPadding]}>{content}</View>
+ {visible ? <HtmlBrowserChrome
+ document
+ {...htmlBrowserActions}
+ title={item.name}
+ path={absolutePathOf(item.relPath)}
+ top={insets.top}
+ bottom={insets.bottom}
+ left={insets.left + spacing.md}
+ right={insets.right + spacing.md}
+ /> : null}
+ </View>
+ );
}
/**
@@ -1089,6 +1041,13 @@ function PdfPreviewPage({
recoveryEpoch: number;
workdir: string;
}) {
+ const insets = useSafeAreaInsets();
+ const { viewRef, measure, viewportStyle, obscuredContentInsets } = useHtmlBrowserViewport({
+ top: insets.top + HTML_BROWSER_CONTROL_SIZE + spacing.xs,
+ bottom: insets.bottom + spacing.xs,
+ left: insets.left,
+ right: insets.right,
+ });
const styles = useThemedStyles(makeStyles);
const { colors } = useTheme();
const { t } = useTranslation();
@@ -1152,7 +1111,14 @@ function PdfPreviewPage({
</View>
);
}
- return <WebView source={pdfSource} originWhitelist={['https://*', 'http://*', 'file://*']} style={styles.pdfView} testID="filePreview.pdfView" />;
+ return <View ref={viewRef} onLayout={measure} collapsable={false} style={[styles.pdfView, viewportStyle]}>
+ <WebView source={pdfSource} originWhitelist={['https://*', 'http://*', 'file://*']}
+ automaticallyAdjustContentInsets={false}
+ contentInsetAdjustmentBehavior="never"
+ obscuredContentInsets={obscuredContentInsets}
+ contentInset={obscuredContentInsets}
+ style={styles.pdfView} testID="filePreview.pdfView" />
+ </View>;
}
/**
@@ -1208,7 +1174,7 @@ function TextPreviewPage({
// Sit directly against the safe-area edges; only a small gap separates page content.
const browserTop = insets.top;
const browserBottom = insets.bottom;
- const browserContentInset = { top: browserTop + HTML_BROWSER_CONTROL_SIZE + spacing.xs, bottom: browserBottom + HTML_BROWSER_CONTROL_SIZE + spacing.xs };
+ const browserContentInset = { top: browserTop + HTML_BROWSER_CONTROL_SIZE + spacing.xs, bottom: browserBottom + (richKind === 'html' ? HTML_BROWSER_CONTROL_SIZE : 0) + spacing.xs };
const browserRef = useRef<WebView>(null);
const [website, setWebsite] = useState<WebsiteVisit | null>(null);
const [browserNavigation, setBrowserNavigation] = useState<{
@@ -1338,17 +1304,6 @@ function TextPreviewPage({
setState({ status: 'loading' });
setTextReloadEpoch((epoch) => epoch + 1);
};
- if (state.status === 'loading' && richKind !== 'html') {
- return (
- <View style={styles.centerFill}>
- <ActivityIndicator color={colors.textTertiary} />
- </View>
- );
- }
- if (state.status === 'unavailable' && richKind !== 'html') {
- return <UnsupportedPage item={item} onDownload={onDownload} reason={state.reason} onRetry={state.retryable ? retryText : undefined} />;
- }
-
const ready = state.status === 'ready' ? state : null;
const targetIndex = targetLine !== null && targetLine <= (ready?.lines.length ?? 0) ? targetLine - 1 : null;
const lineNumWidth = String(ready?.lines.length ?? 0).length;
@@ -1359,38 +1314,15 @@ function TextPreviewPage({
const navigation = htmlPanWanted && browserNavigation && browserNavigation.preview === htmlSnapshot.preview ? browserNavigation.state : null;
return (
<View style={styles.textPage}>
- <View style={[styles.textPage, richKind === 'html' && richView === 'source' && {
- paddingTop: browserContentInset.top, paddingBottom: browserContentInset.bottom,
- paddingLeft: insets.left, paddingRight: insets.right,
- }]}>
+ <View style={styles.textPage}>
{clipped ? (
- <View style={styles.truncBar} testID="filePreview.truncBanner">
+ <View style={[styles.truncBar, { marginTop: browserContentInset.top }]} testID="filePreview.truncBanner">
<Info color={colors.textSecondary} size={iconSize.sm} strokeWidth={iconStroke.regular} />
<Text style={styles.truncText}>
{ready?.truncated ? t('files.preview.truncated2mb') : t('files.preview.truncatedLines', { lines: MAX_RENDERED_LINES })}
</Text>
</View>
) : null}
- {/* HTML 的模式切换在浮动浏览器菜单中;Markdown 保留原有胶囊。 */}
- {canRenderRich && richKind !== 'html' ? (
- <View style={styles.mdToggleRow}>
- <FileBrowserSegmentedControl<'rendered' | 'source'>
- accessibilityLabel={t('files.preview.mdViewA11y', { view: richView === 'rendered' ? t('files.preview.mdRendered') : t('files.preview.mdSource') })}
- onChange={setRichView}
- options={(['rendered', 'source'] as const).map((value) => {
- const label = t(value === 'rendered' ? 'files.preview.mdRendered' : 'files.preview.mdSource');
- return {
- value,
- label,
- accessibilityLabel: t('files.preview.mdViewA11y', { view: label }),
- testID: `filePreview.richView.${value}`,
- };
- })}
- testID="filePreview.richView"
- value={richView}
- />
- </View>
- ) : null}
{showRendered ? (
richKind === 'html' ? (
// **只在真正可见的当前页挂载**(review P1):HTML 里的脚本是可执行的不可信
@@ -1419,6 +1351,7 @@ function TextPreviewPage({
) : (
<MarkdownFileReader
markdown={ready?.content ?? ''}
+ viewportInsets={{ ...browserContentInset, top: clipped ? 0 : browserContentInset.top, left: insets.left, right: insets.right }}
onPageSwipe={onMarkdownPageSwipe ? (direction) => onMarkdownPageSwipe(item.key, direction) : undefined}
onQuoteSelection={onQuoteSelection}
targetLine={targetLine}
@@ -1432,7 +1365,13 @@ function TextPreviewPage({
onRetry={state.retryable ? retryText : undefined} />
) : (
<FlatList
- contentContainerStyle={styles.codeContent}
+ contentContainerStyle={[styles.codeContent, {
+ paddingTop: clipped ? spacing.md : browserContentInset.top + spacing.md,
+ paddingBottom: browserContentInset.bottom + spacing.md,
+ paddingLeft: insets.left + spacing.lg,
+ paddingRight: insets.right + spacing.lg,
+ }]}
+ scrollIndicatorInsets={browserContentInset}
data={state.lines}
initialNumToRender={40}
keyExtractor={(_, index) => String(index)}
@@ -1463,6 +1402,18 @@ function TextPreviewPage({
/>
)}
</View>
+ {richKind !== 'html' && visible ? <HtmlBrowserChrome
+ document
+ {...htmlBrowserActions}
+ title={item.name}
+ path={absolutePathOf(item.relPath)}
+ top={browserTop}
+ bottom={browserBottom}
+ left={insets.left + spacing.md}
+ right={insets.right + spacing.md}
+ source={richView === 'source'}
+ onToggleSource={canRenderRich ? () => setRichView(value => value === 'rendered' ? 'source' : 'rendered') : undefined}
+ /> : null}
{richKind === 'html' && visible ? (
<HtmlBrowserChrome
{...htmlBrowserActions}
@@ -1646,36 +1597,6 @@ function GenericGlyph({ name }: { name: string }) {
);
}
-function ToolbarButton({
- disabled,
- Icon,
- label,
- onPress,
- testID,
-}: {
- disabled?: boolean;
- Icon: React.ComponentType<{ color?: string; size?: number; strokeWidth?: number }>;
- label: string;
- onPress(): void;
- testID: string;
-}) {
- const styles = useThemedStyles(makeStyles);
- const { colors } = useTheme();
- return (
- <Pressable
- accessibilityLabel={label}
- accessibilityRole="button"
- disabled={disabled}
- onPress={onPress}
- style={({ pressed }) => [styles.toolItem, (pressed || disabled) && styles.pressed]}
- testID={testID}
- >
- <Icon color={colors.textPrimary} size={iconSize.xl} strokeWidth={iconStroke.regular} />
- <Text style={styles.toolLabel}>{label}</Text>
- </Pressable>
- );
-}
-
/* ------------------------------ 工具 ------------------------------ */
function fallbackItem(relPath: string): FileBrowserGridItem {
@@ -1721,18 +1642,6 @@ const makeStyles = (colors: ThemeColors) => {
justifyContent: 'center',
paddingHorizontal: spacing.xl,
},
- navRow: {
- alignItems: 'center',
- flexDirection: 'row',
- gap: spacing.md,
- paddingHorizontal: spacing.lg,
- paddingVertical: spacing.md,
- },
- doneText: { color: colors.textPrimary, fontSize: typeScale.bodyLarge, lineHeight: lineHeight.bodyLarge, fontWeight: fontWeight.medium },
- navTitleCol: { alignItems: 'center', flex: 1, gap: 2, minWidth: 0 },
- navTitle: { color: colors.textPrimary, fontSize: typeScale.body, lineHeight: lineHeight.body, fontWeight: fontWeight.semibold },
- navMeta: { color: colors.textTertiary, fontSize: typeScale.caption, lineHeight: lineHeight.caption },
- navHairline: { backgroundColor: colors.border, height: StyleSheet.hairlineWidth },
truncBar: {
alignItems: 'center',
backgroundColor: colors.surfaceChip,
@@ -1744,10 +1653,6 @@ const makeStyles = (colors: ThemeColors) => {
},
truncText: { color: colors.textSecondary, fontSize: typeScale.footnote, lineHeight: lineHeight.caption },
textPage: { flex: 1 },
- mdToggleRow: {
- paddingHorizontal: spacing.lg,
- paddingVertical: spacing.sm,
- },
codeList: { flex: 1 },
codeContent: { paddingHorizontal: spacing.lg, paddingVertical: spacing.md },
codeLine: { flexDirection: 'row', gap: spacing.sm + 2 },
@@ -1836,22 +1741,5 @@ const makeStyles = (colors: ThemeColors) => {
paddingHorizontal: spacing.xl,
},
ctaLabel: { color: colors.ctaText, fontSize: typeScale.bodySmall, lineHeight: lineHeight.bodySmall, fontWeight: fontWeight.medium },
- toolbarHairline: { backgroundColor: colors.border, height: StyleSheet.hairlineWidth },
- toolbar: {
- backgroundColor: colors.surface,
- flexDirection: 'row',
- justifyContent: 'space-around',
- paddingBottom: spacing.sm,
- paddingTop: spacing.md,
- },
- toolItem: { alignItems: 'center', gap: spacing.xs, minWidth: 64 },
- toolLabel: { color: colors.textSecondary, fontSize: typeScale.micro, lineHeight: lineHeight.micro },
- noticeText: {
- color: colors.textSecondary,
- fontSize: typeScale.footnote,
- lineHeight: lineHeight.caption,
- paddingBottom: spacing.sm,
- textAlign: 'center',
- },
});
};
diff --git a/apps/mobile/src/i18n/locales/en/files.json b/apps/mobile/src/i18n/locales/en/files.json
index 8c712dae18..d5fef41e36 100644
--- a/apps/mobile/src/i18n/locales/en/files.json
+++ b/apps/mobile/src/i18n/locales/en/files.json
@@ -85,6 +85,7 @@
"browserMore": "More actions",
"browserShowSource": "View source",
"browserShowPage": "Back to webpage",
+ "browserShowDocument": "View document",
"browserAddToTask": "Add to current task",
"browserFileInfo": "File information",
"done": "Done",
@@ -117,9 +118,6 @@
"htmlResourcesMissing": "{{count}} page resource(s) could not be fetched; images or styles may be missing",
"htmlResourcesTruncated": "Too many page resources; only the first {{limit}} were attempted",
"htmlResourcesOverBudget": "{{count}} more resource(s) were skipped because the page's total size limit was reached",
- "mdRendered": "Rendered",
- "mdSource": "Source",
- "mdViewA11y": "{{view}} view",
"a11yViewImage": "View full image {{name}}",
"fetchOriginalFailed": "Failed to fetch original: {{detail}}",
"a11yRetryOriginal": "Retry fetching the original image",
diff --git a/apps/mobile/src/i18n/locales/ja/files.json b/apps/mobile/src/i18n/locales/ja/files.json
index 293465de46..28c77788e0 100644
--- a/apps/mobile/src/i18n/locales/ja/files.json
+++ b/apps/mobile/src/i18n/locales/ja/files.json
@@ -85,6 +85,7 @@
"browserMore": "その他の操作",
"browserShowSource": "ソースを表示",
"browserShowPage": "ウェブページに戻る",
+ "browserShowDocument": "本文を表示",
"browserAddToTask": "現在のタスクに追加",
"browserFileInfo": "ファイル情報",
"done": "完了",
@@ -117,9 +118,6 @@
"htmlResourcesMissing": "{{count}} 件のページリソースを取得できませんでした。画像やスタイルが欠ける場合があります",
"htmlResourcesTruncated": "ページリソースが多すぎます。先頭 {{limit}} 件のみ処理しました",
"htmlResourcesOverBudget": "合計サイズの上限に達したため、さらに {{count}} 件のリソースを取得していません",
- "mdRendered": "レンダリング",
- "mdSource": "ソース",
- "mdViewA11y": "{{view}}表示",
"a11yViewImage": "画像を拡大表示 {{name}}",
"fetchOriginalFailed": "オリジナル画像の取得に失敗しました:{{detail}}",
"a11yRetryOriginal": "オリジナル画像の取得を再試行",
diff --git a/apps/mobile/src/i18n/locales/ko/files.json b/apps/mobile/src/i18n/locales/ko/files.json
index 34eecdb57d..83ba500266 100644
--- a/apps/mobile/src/i18n/locales/ko/files.json
+++ b/apps/mobile/src/i18n/locales/ko/files.json
@@ -85,6 +85,7 @@
"browserMore": "추가 작업",
"browserShowSource": "소스 보기",
"browserShowPage": "웹페이지로 돌아가기",
+ "browserShowDocument": "본문 보기",
"browserAddToTask": "현재 작업에 추가",
"browserFileInfo": "파일 정보",
"done": "완료",
@@ -117,9 +118,6 @@
"htmlResourcesMissing": "페이지 리소스 {{count}}개를 가져오지 못했습니다. 이미지나 스타일이 누락될 수 있습니다",
"htmlResourcesTruncated": "페이지 리소스가 너무 많습니다. 처음 {{limit}}개만 처리했습니다",
"htmlResourcesOverBudget": "전체 크기 상한에 도달해 리소스 {{count}}개를 더 가져오지 않았습니다",
- "mdRendered": "렌더링",
- "mdSource": "소스",
- "mdViewA11y": "{{view}} 보기",
"a11yViewImage": "큰 이미지 보기 {{name}}",
"fetchOriginalFailed": "원본 이미지 가져오기에 실패했습니다: {{detail}}",
"a11yRetryOriginal": "원본 이미지 가져오기 재시도",
diff --git a/apps/mobile/src/i18n/locales/zh-CN/files.json b/apps/mobile/src/i18n/locales/zh-CN/files.json
index df724a32ca..f7ba385162 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/files.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/files.json
@@ -85,6 +85,7 @@
"browserMore": "更多操作",
"browserShowSource": "查看源码",
"browserShowPage": "返回网页",
+ "browserShowDocument": "查看正文",
"browserAddToTask": "添加到当前任务",
"browserFileInfo": "文件信息",
"done": "完成",
@@ -117,9 +118,6 @@
"htmlResourcesMissing": "{{count}} 项页面资源没取到,可能缺图或缺样式",
"htmlResourcesTruncated": "页面资源过多,只处理了前 {{limit}} 项",
"htmlResourcesOverBudget": "另有 {{count}} 项资源因总大小超限未取回",
- "mdRendered": "渲染",
- "mdSource": "源码",
- "mdViewA11y": "{{view}}视图",
"a11yViewImage": "查看大图 {{name}}",
"fetchOriginalFailed": "取回原图失败:{{detail}}",
"a11yRetryOriginal": "重试取回原图",
diff --git a/apps/mobile/src/i18n/locales/zh-TW/files.json b/apps/mobile/src/i18n/locales/zh-TW/files.json
index 7aee48ccaa..bfa907630e 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/files.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/files.json
@@ -85,6 +85,7 @@
"browserMore": "更多操作",
"browserShowSource": "檢視原始碼",
"browserShowPage": "返回網頁",
+ "browserShowDocument": "檢視正文",
"browserAddToTask": "加入目前任務",
"browserFileInfo": "檔案資訊",
"done": "完成",
@@ -117,9 +118,6 @@
"htmlResourcesMissing": "{{count}} 項頁面資源沒取到,可能缺圖或缺樣式",
"htmlResourcesTruncated": "頁面資源過多,只處理了前 {{limit}} 項",
"htmlResourcesOverBudget": "另有 {{count}} 項資源因總大小超限未取回",
- "mdRendered": "渲染",
- "mdSource": "原始碼",
- "mdViewA11y": "{{view}}檢視",
"a11yViewImage": "檢視大圖 {{name}}",
"fetchOriginalFailed": "取回原圖失敗:{{detail}}",
"a11yRetryOriginal": "重試取回原圖",
diff --git a/apps/mobile/src/session/HtmlBrowserChrome.ios.tsx b/apps/mobile/src/session/HtmlBrowserChrome.ios.tsx
index 785aa703d8..47e4742402 100644
--- a/apps/mobile/src/session/HtmlBrowserChrome.ios.tsx
+++ b/apps/mobile/src/session/HtmlBrowserChrome.ios.tsx
@@ -32,7 +32,7 @@ import {
padding,
shapes,
} from "@expo/ui/swift-ui/modifiers";
-import { Alert, StyleSheet, View } from "react-native";
+import { ActivityIndicator, Alert, StyleSheet, View } from "react-native";
import { useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Text } from "@/components/AppText";
@@ -42,19 +42,21 @@ import { useLiquidGlassAvailable } from "./useLiquidGlassAvailable";
import {
HTML_BROWSER_CONTROL_SIZE as size,
type HtmlBrowserChromeProps,
+ type DocumentPreviewChromeProps,
} from "./HtmlBrowserChrome.types";
/** Native SwiftUI controls float above the WebView; the empty space passes touches through. */
-export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
+export function HtmlBrowserChrome(p: HtmlBrowserChromeProps | DocumentPreviewChromeProps) {
const { colors, mode } = useTheme();
const { t } = useTranslation();
const glass = useLiquidGlassAvailable();
const [editing, setEditing] = useState(false);
- const addressText = useNativeState(p.address);
+ const addressText = useNativeState(p.document ? '' : p.address);
const addressRef = useRef<TextFieldRef>(null);
- const beginEditing = () => { addressText.set(p.address); setEditing(true); };
- const submitAddress = () => { if (p.onNavigate(addressText.get())) setEditing(false); };
- const showFileInfo = () => Alert.alert(p.title, p.path);
+ const beginEditing = () => { if (!p.document) { addressText.set(p.address); setEditing(true); } };
+ const submitAddress = () => { if (!p.document && p.onNavigate(addressText.get())) setEditing(false); };
+ const showFileInfo = () => Alert.alert(p.title, [p.meta, p.path].filter(Boolean).join('\n'));
+ const website = !p.document && p.website;
// Size the visible glass itself, not an outer frame around a system-sized label.
// Menu and Button have different intrinsic sizes (especially ellipsis vs share).
// Untinted glass adapts to the page behind it: a light page in Dark mode turned it light
@@ -84,6 +86,66 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
seedColor: colors.textPrimary,
ignoreSafeArea: "all" as const,
};
+ const moreMenu = (
+ <Host {...host} style={{ width: size, height: size }}>
+ <Menu
+ label={
+ <Image
+ systemName="ellipsis"
+ size={iconSize.lg}
+ modifiers={[frame({ width: size, height: size })]}
+ />
+ }
+ testID="filePreview.browser.more"
+ modifiers={[
+ ...circle,
+ menuOrder("fixed"),
+ disabled(p.pending === true),
+ accessibilityLabel(t("files.preview.browserMore")),
+ ]}
+ >
+ {p.document ? <Button
+ label={t("files.preview.a11yShare")}
+ systemImage="square.and.arrow.up"
+ onPress={p.onShare}
+ testID="filePreview.share"
+ modifiers={[disabled(p.busy)]}
+ /> : null}
+ {!website && <Section title={p.title}>
+ <Button
+ label={t("files.preview.browserFileInfo")}
+ systemImage="doc"
+ onPress={showFileInfo}
+ />
+ </Section>}
+ {p.onToggleSource ? <Button
+ label={t(
+ website ? "files.preview.browserReturnToFile" : p.source
+ ? p.document ? "files.preview.browserShowDocument" : "files.preview.browserShowPage"
+ : "files.preview.browserShowSource",
+ )}
+ systemImage="chevron.left.forwardslash.chevron.right"
+ onPress={p.onToggleSource}
+ testID="filePreview.browser.source"
+ /> : null}
+ <Divider />
+ <Button
+ label={t(website ? "files.preview.browserCopyAddress" : "files.preview.copyPath")}
+ systemImage="doc.on.doc"
+ onPress={p.onCopyPath}
+ testID="filePreview.copyPath"
+ modifiers={[disabled(p.busy)]}
+ />
+ {!website && <Button
+ label={t("files.preview.browserAddToTask")}
+ systemImage="text.bubble"
+ onPress={p.onAddToTask}
+ testID="filePreview.sendToSession"
+ modifiers={[disabled(p.busy)]}
+ />}
+ </Menu>
+ </Host>
+ );
return (
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
<View
@@ -91,8 +153,8 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
style={{
position: "absolute",
top: p.top,
- left: p.left,
- right: p.right,
+ left: p.document ? Math.max(p.left, p.right) : p.left,
+ right: p.document ? Math.max(p.left, p.right) : p.right,
flexDirection: "row",
gap: spacing.sm,
}}
@@ -115,7 +177,15 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
spacing={0}
modifiers={[frame({ maxWidth: Infinity, height: size }), capsule]}
>
- {editing ? <TextField
+ {p.document ? <NativeText
+ testID="filePreview.title"
+ modifiers={[
+ font({ size: typeScale.footnote }),
+ lineLimit(1),
+ padding({ horizontal: spacing.lg }),
+ frame({ maxWidth: Infinity, height: size, alignment: "center" }),
+ ]}
+ >{p.title}</NativeText> : editing ? <TextField
ref={addressRef}
text={addressText}
autoFocus
@@ -171,7 +241,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
</NativeText>
</HStack>
</Button>}
- {editing ? <Button
+ {p.document ? null : editing ? <Button
label={t("files.preview.browserCancelAddress")}
systemImage="xmark"
onPress={() => setEditing(false)}
@@ -195,13 +265,14 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
)}
</HStack>
</Host>
+ {p.document ? moreMenu : null}
</View>
{p.notice ? (
<View
pointerEvents={p.onCancelNotice ? "box-none" : "none"}
style={{
position: "absolute",
- bottom: p.bottom + size + spacing.sm,
+ bottom: p.bottom + (p.document ? spacing.sm : size + spacing.sm),
left: p.left,
right: p.right,
alignItems: "center",
@@ -217,13 +288,14 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
borderRadius: radius.container,
}}
>
+ {p.onCancelNotice ? <ActivityIndicator color={colors.textTertiary} size="small" /> : null}
<Text
accessibilityLiveRegion="polite"
testID="filePreview.notice"
style={{
flexShrink: 1,
color: colors.textPrimary,
- fontSize: typeScale.caption,
+ fontSize: typeScale.footnote,
lineHeight: lineHeight.caption,
}}
>
@@ -242,7 +314,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
</View>
</View>
) : null}
- <View
+ {!p.document ? <View
pointerEvents="box-none"
style={{
position: "absolute",
@@ -253,7 +325,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
gap: spacing.md,
}}
>
- <Host {...host} style={{ width: size * 2, height: size }}>
+ {!p.document ? <Host {...host} style={{ width: size * 2, height: size }}>
<HStack spacing={0} modifiers={[capsule]}>
<Button
label={t("files.preview.browserBack")}
@@ -270,7 +342,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
modifiers={[...icon, disabled(!p.canGoForward)]}
/>
</HStack>
- </Host>
+ </Host> : null}
<View pointerEvents="none" style={{ flex: 1 }} />
<Host {...host} style={{ width: size, height: size }}>
<Button
@@ -289,58 +361,8 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
/>
</Button>
</Host>
- <Host {...host} style={{ width: size, height: size }}>
- <Menu
- label={
- <Image
- systemName="ellipsis"
- size={iconSize.lg}
- modifiers={[frame({ width: size, height: size })]}
- />
- }
- testID="filePreview.browser.more"
- modifiers={[
- ...circle,
- menuOrder("fixed"),
- disabled(p.pending === true),
- accessibilityLabel(t("files.preview.browserMore")),
- ]}
- >
- {!p.website && <Section title={p.title}>
- <Button
- label={t("files.preview.browserFileInfo")}
- systemImage="doc"
- onPress={showFileInfo}
- />
- </Section>}
- <Button
- label={t(
- p.website ? "files.preview.browserReturnToFile" : p.source
- ? "files.preview.browserShowPage"
- : "files.preview.browserShowSource",
- )}
- systemImage="chevron.left.forwardslash.chevron.right"
- onPress={p.onToggleSource}
- testID="filePreview.browser.source"
- />
- <Divider />
- <Button
- label={t(p.website ? "files.preview.browserCopyAddress" : "files.preview.copyPath")}
- systemImage="doc.on.doc"
- onPress={p.onCopyPath}
- testID="filePreview.copyPath"
- modifiers={[disabled(p.busy)]}
- />
- {!p.website && <Button
- label={t("files.preview.browserAddToTask")}
- systemImage="text.bubble"
- onPress={p.onAddToTask}
- testID="filePreview.sendToSession"
- modifiers={[disabled(p.busy)]}
- />}
- </Menu>
- </Host>
- </View>
+ {moreMenu}
+ </View> : null}
</View>
);
}
diff --git a/apps/mobile/src/session/HtmlBrowserChrome.tsx b/apps/mobile/src/session/HtmlBrowserChrome.tsx
index 0e2a260787..c786963234 100644
--- a/apps/mobile/src/session/HtmlBrowserChrome.tsx
+++ b/apps/mobile/src/session/HtmlBrowserChrome.tsx
@@ -38,16 +38,18 @@ import {
import {
HTML_BROWSER_CONTROL_SIZE as size,
type HtmlBrowserChromeProps,
+ type DocumentPreviewChromeProps,
} from "./HtmlBrowserChrome.types";
/** Android/web use opaque themed surfaces so arbitrary webpage colors cannot erase the controls. */
-export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
+export function HtmlBrowserChrome(p: HtmlBrowserChromeProps | DocumentPreviewChromeProps) {
const { t } = useTranslation();
const { colors } = useTheme();
const styles = useThemedStyles(makeStyles);
const [menuOpen, setMenuOpen] = useState(false);
const [editing, setEditing] = useState(false);
- const [address, setAddress] = useState(p.address);
+ const [address, setAddress] = useState(p.document ? '' : p.address);
+ const website = !p.document && p.website;
const afterClose = useRef<(() => void) | null>(null);
const close = () => setMenuOpen(false);
const choose = (action: () => void) => {
@@ -84,11 +86,13 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
<View
pointerEvents="box-none"
- style={[styles.row, { top: p.top, left: p.left, right: p.right }]}
+ style={[styles.row, { top: p.top, left: p.document ? Math.max(p.left, p.right) : p.left, right: p.document ? Math.max(p.left, p.right) : p.right }]}
>
{button(X, t("files.preview.done"), p.onClose, "filePreview.done")}
- <View style={styles.address}>
- {editing ? <TextInput
+ <View style={[styles.address, p.document && styles.documentTitle]}>
+ {p.document ? <View style={styles.addressTitle}>
+ <Text numberOfLines={1} style={[styles.title, styles.centeredTitle]} testID="filePreview.title">{p.title}</Text>
+ </View> : editing ? <TextInput
value={address}
onChangeText={setAddress}
autoFocus
@@ -124,7 +128,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
{p.title}
</Text>
</Pressable>}
- {editing ? button(X, t("files.preview.browserCancelAddress"), () => setEditing(false), "filePreview.browser.cancelAddress") : p.loading ? (
+ {p.document ? null : editing ? button(X, t("files.preview.browserCancelAddress"), () => setEditing(false), "filePreview.browser.cancelAddress") : p.loading ? (
<View style={styles.button}>
<ActivityIndicator color={colors.textSecondary} />
</View>
@@ -138,13 +142,21 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
)
)}
</View>
+ {p.document ? button(
+ Ellipsis,
+ t("files.preview.browserMore"),
+ () => setMenuOpen(true),
+ "filePreview.browser.more",
+ p.pending,
+ ) : null}
</View>
{p.notice ? (
<View
pointerEvents={p.onCancelNotice ? "box-none" : "none"}
- style={[styles.notice, { bottom: p.bottom + size + spacing.sm }]}
+ style={[styles.notice, { bottom: p.bottom + (p.document ? spacing.sm : size + spacing.sm) }]}
>
<View style={styles.noticePill}>
+ {p.onCancelNotice ? <ActivityIndicator color={colors.textTertiary} size="small" /> : null}
<Text
accessibilityLiveRegion="polite"
testID="filePreview.notice"
@@ -165,11 +177,11 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
</View>
</View>
) : null}
- <View
+ {!p.document ? <View
pointerEvents="box-none"
style={[styles.row, { bottom: p.bottom, left: p.left, right: p.right }]}
>
- <View style={styles.navigation}>
+ {!p.document ? <View style={styles.navigation}>
{button(
ChevronLeft,
t("files.preview.browserBack"),
@@ -184,7 +196,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
"filePreview.browser.forward",
!p.canGoForward,
)}
- </View>
+ </View> : null}
<View pointerEvents="none" style={styles.spacer} />
{button(
Share,
@@ -200,7 +212,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
"filePreview.browser.more",
p.pending,
)}
- </View>
+ </View> : null}
<SheetModal
nativePresentation
visible={menuOpen}
@@ -226,24 +238,31 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
</View>
<ScrollView>
<Text selectable style={styles.path}>
- {p.path}
+ {[p.meta, p.path].filter(Boolean).join('\n')}
</Text>
{[
- {
+ ...(p.document ? [{
+ id: "filePreview.share",
+ Icon: Share,
+ label: t("files.preview.a11yShare"),
+ action: p.onShare,
+ disabled: p.busy,
+ }] : []),
+ ...(p.onToggleSource ? [{
id: "filePreview.browser.source",
Icon: CodeXml,
label: t(
- p.website ? "files.preview.browserReturnToFile" : p.source
- ? "files.preview.browserShowPage"
+ website ? "files.preview.browserReturnToFile" : p.source
+ ? p.document ? "files.preview.browserShowDocument" : "files.preview.browserShowPage"
: "files.preview.browserShowSource",
),
action: p.onToggleSource,
disabled: false,
- },
+ }] : []),
{
id: "filePreview.copyPath",
Icon: Copy,
- label: t(p.website ? "files.preview.browserCopyAddress" : "files.preview.copyPath"),
+ label: t(website ? "files.preview.browserCopyAddress" : "files.preview.copyPath"),
action: p.onCopyPath,
disabled: p.busy,
},
@@ -254,7 +273,7 @@ export function HtmlBrowserChrome(p: HtmlBrowserChromeProps) {
action: p.onAddToTask,
disabled: p.busy,
},
- ].filter(item => !p.website || item.id !== "filePreview.sendToSession").map(({ id, Icon, label, action, disabled }) => (
+ ].filter(item => !website || item.id !== "filePreview.sendToSession").map(({ id, Icon, label, action, disabled }) => (
<Pressable
key={id}
accessibilityRole="button"
@@ -308,7 +327,9 @@ const makeStyles = (c: ThemeColors) =>
backgroundColor: c.surfaceElevated,
paddingLeft: spacing.lg,
},
- title: { flex: 1, color: c.textPrimary, fontSize: typeScale.footnote },
+ documentTitle: { paddingHorizontal: spacing.lg },
+ centeredTitle: { textAlign: "center" },
+ title: { flex: 1, color: c.textPrimary, fontSize: typeScale.footnote, lineHeight: lineHeight.caption },
addressTitle: {
flex: 1,
minWidth: 0,
diff --git a/apps/mobile/src/session/HtmlBrowserChrome.types.ts b/apps/mobile/src/session/HtmlBrowserChrome.types.ts
index c87df16e65..3ddbc9780d 100644
--- a/apps/mobile/src/session/HtmlBrowserChrome.types.ts
+++ b/apps/mobile/src/session/HtmlBrowserChrome.types.ts
@@ -1,34 +1,46 @@
/** File actions always refer to the entry file; WebView history stays inside its preview. */
-export interface HtmlBrowserChromeProps {
+export interface FilePreviewChromeProps {
title: string;
path: string;
- address: string;
- website?: boolean;
- /** False keeps the editor open; validation feedback is owned by the caller. */
- onNavigate(address: string): boolean;
+ /** File details belong in the menu, leaving the reading surface uncluttered. */
+ meta?: string;
top: number;
bottom: number;
left: number;
right: number;
- canGoBack: boolean;
- canGoForward: boolean;
- source: boolean;
+ source?: boolean;
busy: boolean;
- loading: boolean;
/** The file has not opened yet: address editing and the more menu stay disabled. */
pending?: boolean;
notice?: string | null;
/** Set while the notice describes a cancellable export: the notice shows a Cancel button. */
onCancelNotice?: () => void;
onClose(): void;
- onBack(): void;
- onForward(): void;
- onReload(): void;
onShare(): void;
onCopyPath(): void;
onAddToTask(): void;
+ onToggleSource?: () => void;
+}
+
+export interface HtmlBrowserChromeProps extends FilePreviewChromeProps {
+ document?: false;
+ address: string;
+ website?: boolean;
+ /** False keeps the editor open; validation feedback is owned by the caller. */
+ onNavigate(address: string): boolean;
+ canGoBack: boolean;
+ canGoForward: boolean;
+ source: boolean;
+ loading: boolean;
+ onBack(): void;
+ onForward(): void;
+ onReload(): void;
onToggleSource(): void;
}
+export interface DocumentPreviewChromeProps extends FilePreviewChromeProps {
+ document: true;
+}
+
// Native controls keep a 44pt hit target; the scroll insets also clear the outer spacing.
export const HTML_BROWSER_CONTROL_SIZE = 44;
diff --git a/apps/mobile/src/session/MarkdownFileReader.tsx b/apps/mobile/src/session/MarkdownFileReader.tsx
index e47dcc75c1..f26c376214 100644
--- a/apps/mobile/src/session/MarkdownFileReader.tsx
+++ b/apps/mobile/src/session/MarkdownFileReader.tsx
@@ -22,6 +22,8 @@ import type { ShouldStartLoadRequest } from 'react-native-webview/lib/WebViewTyp
import { buildSelectableMarkdownHtml } from '@/session/selectableMarkdownHtml';
import { MARKDOWN_FILE_PAGER_SCRIPT, parseMarkdownPageSwipe } from '@/session/markdownFilePager';
import { selectionQuoteMenuLabel } from '@/session/selectionQuote';
+import { useHtmlBrowserViewport } from '@/session/useHtmlBrowserViewport';
+import type { BrowserInsets } from '@/session/htmlBrowserViewport';
import { lineHeight, useTheme } from '@/theme';
import { spacing, typeScale } from '@/theme/tokens';
@@ -31,6 +33,7 @@ export function MarkdownFileReader({
onQuoteSelection,
targetLine,
testID,
+ viewportInsets,
}: {
markdown: string;
/** 由文件预览 pager 消费的明确横向翻页;纵向移动会让该手势失败给 WebView。 */
@@ -40,9 +43,13 @@ export function MarkdownFileReader({
/** 定位到源码行(1-based):加载后滚到覆盖该行的块并闪两下高亮(不驻留)。 */
targetLine?: number | null;
testID?: string;
+ viewportInsets?: BrowserInsets;
}) {
const { t } = useTranslation();
const { colors } = useTheme();
+ const { viewRef, measure, viewportStyle, obscuredContentInsets } = useHtmlBrowserViewport(
+ viewportInsets ?? { top: 0, bottom: 0, left: 0, right: 0 },
+ );
const quoteEnabled = !!onQuoteSelection;
// 菜单项在渲染时构造(而非模块常量):label 走 i18n;依赖 t 使语言切换后随重渲更新。
const quoteMenuItems = useMemo(
@@ -94,8 +101,12 @@ export function MarkdownFileReader({
}, [onPageSwipe]);
return (
- <View style={styles.fill} testID={testID}>
+ <View ref={viewRef} onLayout={measure} collapsable={false} style={[styles.fill, viewportStyle]} testID={testID}>
<WebView
+ automaticallyAdjustContentInsets={false}
+ contentInsetAdjustmentBehavior="never"
+ obscuredContentInsets={obscuredContentInsets}
+ contentInset={obscuredContentInsets}
injectedJavaScript={onPageSwipe ? MARKDOWN_FILE_PAGER_SCRIPT : undefined}
onMessage={onPageSwipe ? handleMessage : undefined}
menuItems={quoteEnabled ? quoteMenuItems : undefined}
diff --git a/docs/design-evidence/2026-10-17/mobile-file-reader/markdown-dark.png b/docs/design-evidence/2026-10-17/mobile-file-reader/markdown-dark.png
new file mode 100644
index 0000000000..83534da3d5
Binary files /dev/null and b/docs/design-evidence/2026-10-17/mobile-file-reader/markdown-dark.png differ
diff --git a/docs/design-evidence/2026-10-17/mobile-file-reader/menu-light.png b/docs/design-evidence/2026-10-17/mobile-file-reader/menu-light.png
new file mode 100644
index 0000000000..a185879fe7
Binary files /dev/null and b/docs/design-evidence/2026-10-17/mobile-file-reader/menu-light.png differ
diff --git a/docs/design-evidence/2026-10-17/mobile-file-reader/pdf-light.png b/docs/design-evidence/2026-10-17/mobile-file-reader/pdf-light.png
new file mode 100644
index 0000000000..509ce9cd02
Binary files /dev/null and b/docs/design-evidence/2026-10-17/mobile-file-reader/pdf-light.png differ