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。

fix(mobile): 分享图片沿用聊天面板的可读宽度

Dash5e65679a5535
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 2d74ff7a02..4b9b6810a3 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -181,6 +181,7 @@ import {
} from '@/session/ConversationShareSvg';
import {
buildConversationShareHtml,
+ buildConversationShareContentWidth,
type ConversationShareMessage,
type ConversationShareWebViewColors,
} from '@/session/conversationShareWebViewHtml';
@@ -6175,6 +6176,7 @@ function SessionScreenContent() {
() => resolveMobileUserBubbleColors(userBubblePreference, mode, colors),
[colors, mode, userBubblePreference],
);
+ const conversationShareWidth = buildConversationShareContentWidth(detailViewport);
const conversationShareColors = useMemo<ConversationShareWebViewColors>(() => ({
background: colors.surface,
border: colors.border,
@@ -6229,11 +6231,11 @@ function SessionScreenContent() {
allShareableIds,
characterSrc: shareCharacterSrc ?? undefined,
colors: conversationShareColors,
- contentWidth: windowDimensions.width,
+ contentWidth: conversationShareWidth,
logoSrc: shareLogoSrc ?? undefined,
selectedMessages: messages,
}),
- width: windowDimensions.width,
+ width: conversationShareWidth,
});
if (nativeBase64) {
console.info('[conversation-share] native webview export succeeded');
@@ -6246,7 +6248,7 @@ function SessionScreenContent() {
const svg = conversationShareSvgRef.current;
if (!svg) throw new Error('conversation share svg renderer is unavailable');
return svg.exportPng();
- }, [shareImages.prepare, allShareableIds, conversationShareColors, mode, shareCharacterSrc, shareLogoSrc, windowDimensions.width]);
+ }, [shareImages.prepare, allShareableIds, conversationShareColors, conversationShareWidth, mode, shareCharacterSrc, shareLogoSrc]);
const shareSelectedConversation = useCallback(async () => {
if (
conversationShareBusy
@@ -10708,7 +10710,7 @@ function SessionScreenContent() {
colors={conversationShareColors}
messages={shareImages.messages}
ref={conversationShareSvgRef}
- width={windowDimensions.width}
+ width={conversationShareWidth}
/>
) : null}
<SessionTransientNotice
diff --git a/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts b/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts
index 206f0b4d5a..c6ea13aafe 100644
--- a/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts
+++ b/apps/mobile/src/__tests__/conversationShareWebViewHtml.test.ts
@@ -4,6 +4,7 @@ import { describe, expect, it } from "vitest";
import {
buildConversationShareHtml,
+ buildConversationShareContentWidth,
type ConversationShareWebViewColors,
} from "@/session/conversationShareWebViewHtml";
import { i18n } from "@/i18n";
@@ -51,6 +52,28 @@ function buildRichConversationHtml(): string {
}
describe("buildConversationShareHtml 富内容导出", () => {
+ it.each([
+ { width: 390, height: 844, expectedWidth: 390 },
+ { width: 660, height: 390, expectedWidth: 564 },
+ { width: 1024, height: 1366, expectedWidth: 760 },
+ // 双栏右侧面板的宽度;不可用整个窗口宽度代替。
+ { width: 704, height: 768, expectedWidth: 608 },
+ ])("两条出图路径使用聊天可读宽度($width × $height)", ({ width, height, expectedWidth }) => {
+ const contentWidth = buildConversationShareContentWidth({ width, height });
+ expect(contentWidth).toBe(expectedWidth);
+ const messages = [{ clientId: "user", kind: "user" as const, body: "正文 ".repeat(200) }];
+ const html = buildConversationShareHtml({
+ allShareableIds: ["user"], colors, contentWidth, selectedMessages: messages,
+ });
+ const svg = buildConversationShareSvgLayout({
+ allShareableIds: ["user"], colors, width: contentWidth, messages,
+ });
+ expect(html).toMatch(new RegExp(`#xdt-content\\.share-stage \\{[^}]*width: ${expectedWidth}px`));
+ expect(svg.width).toBe(expectedWidth);
+ expect(svg.bubbles[0]!.width).toBe(Math.round((expectedWidth - 32) * 0.86));
+ expect(svg.bubbles[0]!.x + svg.bubbles[0]!.width).toBe(expectedWidth - 16);
+ });
+
it.each([
{ contentWidth: 360, dark: false },
{ contentWidth: 360, dark: true },
diff --git a/apps/mobile/src/session/conversationShareWebViewHtml.ts b/apps/mobile/src/session/conversationShareWebViewHtml.ts
index 383273fc02..9ccd61b4e4 100644
--- a/apps/mobile/src/session/conversationShareWebViewHtml.ts
+++ b/apps/mobile/src/session/conversationShareWebViewHtml.ts
@@ -8,6 +8,7 @@ import {
type SelectableMarkdownHtmlOptions,
} from "@/session/selectableMarkdownHtml";
import { buildMessageContentLayout } from "@/session/messageContentLayout";
+import { buildMobileReadableViewportLayout } from "@/session/responsiveViewportLayout";
import { collectMobileMarkdownImages } from "@/session/messageMarkdown";
import { lineHeight, radius, spacing, typeScale } from "@/theme/tokens";
@@ -72,6 +73,14 @@ export const CONVERSATION_SHARE_PADDING_Y = spacing.xl;
/** 气泡与 chip 描边对应聊天里的 StyleSheet.hairlineWidth。 */
export const CONVERSATION_SHARE_HAIRLINE = 0.5;
+/** 使用聊天面板的视口(双栏时不是整个窗口),两种出图路径共用可读宽度。 */
+export function buildConversationShareContentWidth(viewport: { width: number; height: number }): number {
+ return Math.max(280, Math.round(buildMobileReadableViewportLayout({
+ screenWidth: viewport.width,
+ screenHeight: viewport.height,
+ }).contentWidth));
+}
+
export function buildConversationShareHtml({
allShareableIds,
characterSrc,