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): 深色模式下输入框附件的上传转圈与重试改为恒白,避免看不见 (#5822)

Dashbe9b5fa37f69
diff --git a/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx b/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx
new file mode 100644
index 0000000000..75186b6044
--- /dev/null
+++ b/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx
@@ -0,0 +1,156 @@
+// @vitest-environment jsdom
+import { act, type ReactNode } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import {
+ ComposerAttachmentCollapsedBadge,
+ ComposerAttachmentTray,
+} from "@/session/ComposerAttachmentTray";
+import { i18n } from "@/i18n";
+import type { RemoteSerializedAttachment } from "@/session/types";
+import type { PendingLocalAttachmentUpload } from "@/session/mobileLocalAttachmentUpload";
+
+const theme = vi.hoisted(() => ({ mode: "light" }));
+vi.mock("react-native", async () => {
+ const { createElement } = await import("react");
+ const flatten = (style: unknown): Record<string, unknown> =>
+ Array.isArray(style)
+ ? Object.assign({}, ...style.map(flatten))
+ : style && typeof style === "object"
+ ? (style as Record<string, unknown>)
+ : {};
+ const view =
+ (tag: string) =>
+ ({
+ children,
+ style,
+ testID,
+ }: {
+ children?: ReactNode;
+ style?: unknown;
+ testID?: string;
+ }) =>
+ createElement(
+ tag,
+ {
+ "data-testid": testID,
+ "data-color": flatten(
+ typeof style === "function" ? style({ pressed: false }) : style,
+ ).color,
+ },
+ children,
+ );
+ return {
+ View: view("div"),
+ Pressable: view("button"),
+ Text: view("span"),
+ ActivityIndicator: ({ color }: { color: string }) =>
+ createElement("i", { "data-testid": "spinner", "data-color": color }),
+ StyleSheet: { create: (value: unknown) => value, hairlineWidth: 1 },
+ };
+});
+vi.mock("@/components/AppText", async () => ({
+ Text: (await import("react-native")).Text,
+}));
+vi.mock("@/components/FileTypeIcon", () => ({ FileTypeIcon: () => null }));
+vi.mock("expo-image", () => ({ Image: () => null }));
+vi.mock("lucide-react-native", async () => {
+ const { createElement } = await import("react");
+ const icon =
+ (name: string) =>
+ ({ color }: { color: string }) =>
+ createElement("i", { "data-testid": name, "data-color": color });
+ return { Pen: icon("pen"), RefreshCw: icon("retry-icon"), X: icon("x") };
+});
+vi.mock("@/theme", async () => {
+ const tokens = await import("@/theme/tokens");
+ const colors = () =>
+ theme.mode === "light" ? tokens.lightColors : tokens.darkColors;
+ return {
+ ...tokens,
+ useTheme: () => ({ colors: colors(), mode: theme.mode }),
+ useThemedStyles: (make: (value: typeof tokens.lightColors) => unknown) =>
+ make(colors()),
+ };
+});
+
+let root: Root;
+let host: HTMLDivElement;
+beforeEach(async () => {
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
+ await i18n.changeLanguage("zh-CN");
+ host = document.createElement("div");
+ root = createRoot(host);
+});
+afterEach(() => {
+ act(() => root.unmount());
+});
+
+const pending = (
+ localId: string,
+ failed?: boolean,
+): PendingLocalAttachmentUpload => ({
+ localId,
+ kind: "image",
+ previewUri: `file:///${localId}.jpg`,
+ name: `${localId}.jpg`,
+ size: 1,
+ failed,
+});
+const attachment = (id: string): RemoteSerializedAttachment => ({
+ id,
+ name: `${id}.jpg`,
+ path: `/tmp/${id}.jpg`,
+ ext: "jpg",
+ size: 1,
+ category: "image",
+ mimeType: "image/jpeg",
+});
+const colorOf = (selector: string) =>
+ host.querySelector(selector)?.getAttribute("data-color");
+
+describe("composer attachment tray overlay foreground", () => {
+ // 遮罩 scrim 两种模式都是深色:前景必须恒白,不能跟着主题反相成近黑。
+ it.each(["light", "dark"])(
+ "keeps spinner, retry and +N readable on the dark scrim in %s mode",
+ async (mode) => {
+ theme.mode = mode;
+ const { darkColors, lightColors } = await import("@/theme/tokens");
+ const colors = mode === "light" ? lightColors : darkColors;
+ act(() =>
+ root.render(
+ <>
+ <ComposerAttachmentTray
+ attachments={[]}
+ previews={{}}
+ onRemove={() => {}}
+ onPreview={() => {}}
+ pendingUploads={[pending("uploading"), pending("failed", true)]}
+ testIDPrefix="t"
+ />
+ <ComposerAttachmentCollapsedBadge
+ attachments={[attachment("a"), attachment("b")]}
+ previews={{ a: "file:///a.jpg" }}
+ onPress={() => {}}
+ />
+ </>,
+ ),
+ );
+ expect(colorOf('[data-testid="spinner"]')).toBe(colors.swipeActionText);
+ expect(colorOf('[data-testid="retry-icon"]')).toBe(
+ colors.swipeActionText,
+ );
+ const retryText = [...host.querySelectorAll("span")].find(
+ (node) => node.textContent === i18n.t("composer.attachments.retry"),
+ );
+ expect(retryText?.getAttribute("data-color")).toBe(
+ colors.swipeActionText,
+ );
+ const plusN = [...host.querySelectorAll("span")].find(
+ (node) => node.textContent === "+1",
+ );
+ expect(plusN?.getAttribute("data-color")).toBe(colors.swipeActionText);
+ expect(colors.swipeActionText).not.toBe(darkColors.ctaText);
+ },
+ );
+});
diff --git a/apps/mobile/src/session/ComposerAttachmentTray.tsx b/apps/mobile/src/session/ComposerAttachmentTray.tsx
index fb90fe55ff..998309c1f4 100644
--- a/apps/mobile/src/session/ComposerAttachmentTray.tsx
+++ b/apps/mobile/src/session/ComposerAttachmentTray.tsx
@@ -138,12 +138,12 @@ export function ComposerAttachmentTray({
style={({ pressed }) => [styles.thumbBusyOverlay, pressed && styles.pressed]}
testID={`${testIDPrefix}.attachmentPendingRetryButton`}
>
- <RefreshCw color={colors.ctaText} size={iconSize.md} strokeWidth={iconStroke.bold} />
+ <RefreshCw color={colors.swipeActionText} size={iconSize.md} strokeWidth={iconStroke.bold} />
<Text style={styles.thumbFailedText}>{t('composer.attachments.retry')}</Text>
</Pressable>
) : (
<View style={styles.thumbBusyOverlay}>
- <ActivityIndicator color={colors.ctaText} size="small" />
+ <ActivityIndicator color={colors.swipeActionText} size="small" />
</View>
)}
</View>
@@ -308,7 +308,8 @@ function makeTrayStyles(colors: ThemeColors) {
backgroundColor: colors.surfaceChip,
justifyContent: 'center' as const,
},
- // 上传中遮罩:深色 scrim 让缩略图「在但未就绪」,转圈用 ctaText(浅色主题为白)。
+ // 上传中遮罩:深色 scrim 让缩略图「在但未就绪」。scrim 两种模式都是深色,转圈用恒白
+ // swipeActionText;ctaText 在深色模式反相为近黑,压在深 scrim 上看不见。
thumbBusyOverlay: {
alignItems: 'center' as const,
backgroundColor: colors.overlay,
@@ -320,9 +321,9 @@ function makeTrayStyles(colors: ThemeColors) {
right: 0,
top: 0,
},
- // 失败态遮罩上的「重试」文字(与转圈同用 ctaText,深 scrim 上跨主题可读)。
+ // 失败态遮罩上的「重试」文字(与转圈同用恒白 swipeActionText)。
thumbFailedText: {
- color: colors.ctaText,
+ color: colors.swipeActionText,
fontSize: typeScale.micro,
lineHeight: lineHeight.micro,
fontWeight: fontWeight.semibold,
@@ -411,9 +412,9 @@ function makeTrayStyles(colors: ThemeColors) {
right: 0,
top: 0,
},
- // 与 thumbBusyOverlay 同精神:深色 scrim 上用 ctaText(浅色主题为白)。
+ // 与 thumbBusyOverlay 同精神:深色 scrim 上用恒白 swipeActionText。
collapsedBadgeOverlayText: {
- color: colors.ctaText,
+ color: colors.swipeActionText,
fontSize: typeScale.micro,
lineHeight: lineHeight.micro,
fontWeight: fontWeight.semibold,