Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 添加图片后展开新建任务输入框并支持上传中预览
Dash5eaf6ac5a43d
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsxindex ec19ed5f79..0b568a6172 100644--- a/apps/mobile/app/sessions/new.tsx+++ b/apps/mobile/app/sessions/new.tsx@@ -2097,7 +2097,20 @@ export default function NewRemoteSessionScreen() {armed: composerVoiceHoldArmed,draftText: draft.firstMessage,});+ const composerIncomingImageCount = pendingUploads.filter((item) => item.kind === 'image').length + pastePlaceholderCount;+ const composerImageCount = attachments.filter((item) => item.category === 'image').length + composerIncomingImageCount;+ const previousComposerIncomingImageCount = useRef(0);+ const [composerImagesCollapsed, setComposerImagesCollapsed] = useState(false);+ useEffect(() => {+ // Only incoming images reopen a manually collapsed tray. Completed uploads+ // can briefly appear in both lists and must not count as another addition.+ if (composerIncomingImageCount > previousComposerIncomingImageCount.current || composerImageCount === 0) {+ setComposerImagesCollapsed(false);+ }+ previousComposerIncomingImageCount.current = composerIncomingImageCount;+ }, [composerImageCount, composerIncomingImageCount]);const composerCardActive = firstMessageInputFocused || composerPillOpen.opening+ || (composerImageCount > 0 && !composerImagesCollapsed)|| modelSheetOpen|| permissionSheetOpen|| voiceStartPending@@ -2107,6 +2120,7 @@ export default function NewRemoteSessionScreen() {// 下拉收起 = 退出聚焦激活态(模型浮窗已是独立 Modal,拖拽手势够不到它,无需在此关闭)。// 语音结束 hold 态未聚焦,blur 是 no-op,需显式解除 hold 才能收回简洁态。const handleComposerSnapToAuto = useCallback(() => {+ setComposerImagesCollapsed(true);setComposerVoiceHoldArmed(false);firstMessageInputRef.current?.blur();}, []);diff --git a/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx b/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsxindex 75186b6044..f78b52b4a8 100644--- a/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx+++ b/apps/mobile/src/__tests__/composerAttachmentTrayOverlayColor.test.tsx@@ -25,15 +25,21 @@ vi.mock("react-native", async () => {children,style,testID,+ onPress,+ disabled,}: {children?: ReactNode;style?: unknown;testID?: string;+ onPress?: () => void;+ disabled?: boolean;}) =>createElement(tag,{"data-testid": testID,+ onClick: onPress,+ disabled,"data-color": flatten(typeof style === "function" ? style({ pressed: false }) : style,).color,@@ -54,6 +60,19 @@ vi.mock("@/components/AppText", async () => ({}));vi.mock("@/components/FileTypeIcon", () => ({ FileTypeIcon: () => null }));vi.mock("expo-image", () => ({ Image: () => null }));+vi.mock("@/session/ImageLightbox", () => ({+ ImageLightbox: ({+ images,+ onClose,+ }: {+ images: { url: string }[];+ onClose(): void;+ }) => (+ <button data-testid="lightbox" onClick={onClose}>+ {images[0].url}+ </button>+ ),+}));vi.mock("lucide-react-native", async () => {const { createElement } = await import("react");const icon =@@ -110,6 +129,87 @@ const colorOf = (selector: string) =>host.querySelector(selector)?.getAttribute("data-color");describe("composer attachment tray overlay foreground", () => {+ // 用户反馈:在途图片只能看缩略图。既有颜色测试不覆盖点击;unit 层用一张+ // 上传中图片验证真实托盘打开本地预览,并在上传完成后仍保持查看器。+ it("previews an uploading image and keeps it open after upload completes", () => {+ const render = (uploading: boolean) =>+ act(() =>+ root.render(+ <ComposerAttachmentTray+ attachments={uploading ? [] : [attachment("done")]}+ previews={{ done: "file:///uploading.jpg" }}+ onRemove={() => {}}+ onPreview={() => {}}+ pendingUploads={uploading ? [pending("uploading")] : []}+ testIDPrefix="t"+ />,+ ),+ );+ render(true);+ const preview = host.querySelector<HTMLButtonElement>(+ '[data-testid="t.attachmentPendingPreviewButton"]',+ );+ expect(preview).not.toBeNull();+ act(() => preview!.click());+ expect(host.querySelector('[data-testid="lightbox"]')?.textContent).toBe(+ "file:///uploading.jpg",+ );+ render(false);+ expect(host.querySelector('[data-testid="lightbox"]')?.textContent).toBe(+ "file:///uploading.jpg",+ );+ act(() =>+ host+ .querySelector<HTMLButtonElement>('[data-testid="lightbox"]')!+ .click(),+ );+ expect(host.querySelector('[data-testid="lightbox"]')).toBeNull();+ });++ it("keeps unresolved images disabled and retry/cancel separate from preview", () => {+ const retry = vi.fn();+ const cancel = vi.fn();+ act(() =>+ root.render(+ <ComposerAttachmentTray+ attachments={[]}+ previews={{}}+ onRemove={() => {}}+ onPreview={() => {}}+ pendingUploads={[+ { ...pending("unresolved"), previewUri: "" },+ pending("failed", true),+ ]}+ onRetryPending={retry}+ onRemovePending={cancel}+ testIDPrefix="t"+ />,+ ),+ );+ const preview = host.querySelector<HTMLButtonElement>(+ '[data-testid="t.attachmentPendingPreviewButton"]',+ )!;+ expect(preview.disabled).toBe(true);+ act(() => preview.click());+ act(() =>+ host+ .querySelector<HTMLButtonElement>(+ '[data-testid="t.attachmentPendingRetryButton"]',+ )!+ .click(),+ );+ act(() =>+ host+ .querySelector<HTMLButtonElement>(+ '[data-testid="t.attachmentPendingRemoveButton"]',+ )!+ .click(),+ );+ expect(retry).toHaveBeenCalledWith("failed");+ expect(cancel).toHaveBeenCalledWith("unresolved");+ expect(host.querySelector('[data-testid="lightbox"]')).toBeNull();+ });+// 遮罩 scrim 两种模式都是深色:前景必须恒白,不能跟着主题反相成近黑。it.each(["light", "dark"])("keeps spinner, retry and +N readable on the dark scrim in %s mode",diff --git a/apps/mobile/src/session/ComposerAttachmentTray.tsx b/apps/mobile/src/session/ComposerAttachmentTray.tsxindex 38aa5e9301..84e5dd55f7 100644--- a/apps/mobile/src/session/ComposerAttachmentTray.tsx+++ b/apps/mobile/src/session/ComposerAttachmentTray.tsx@@ -12,12 +12,16 @@ import { FileTypeIcon } from '@/components/FileTypeIcon';*/import { Pen, RefreshCw, X } from 'lucide-react-native';import { Image } from 'expo-image';+import { useState } from 'react';import { useTranslation } from 'react-i18next';import { ActivityIndicator, Pressable, StyleSheet, View } from 'react-native';import { Text } from '@/components/AppText';import type { RemoteSerializedAttachment } from '@/session/types';import type { PendingLocalAttachmentUpload } from '@/session/mobileLocalAttachmentUpload';import { attachmentDisplayLabel, pendingUploadDisplayLabel } from '@/session/attachments';+import { ImageLightbox } from '@/session/ImageLightbox';+import { buildMediaPayload } from '@/session/messagePayload';+import type { MobileMessageGalleryImage } from '@/session/messageGallery';import { fontWeight, iconSize, iconStroke, lineHeight, radius, spacing, typeScale, useTheme, useThemedStyles, type ThemeColors } from '@/theme';/** 输入卡内的缩略图为正方形(产品决策,不用横长方)。 */@@ -63,6 +67,15 @@ export function ComposerAttachmentTray({const { t } = useTranslation();const styles = useThemedStyles(makeTrayStyles);const { colors } = useTheme();+ // Keep the opened local image stable when the upload becomes a formal attachment.+ const [pendingPreview, setPendingPreview] = useState<MobileMessageGalleryImage[] | null>(null);+ const previewPending = (pending: PendingLocalAttachmentUpload) => {+ if (!pending.previewUri) return;+ const payload = buildMediaPayload({ kind: 'image', previewable: true, title: pending.name, url: pending.previewUri }, pending.name);+ if (payload.kind === 'media') {+ setPendingPreview([{ key: pending.localId, payload, title: pending.name, url: pending.previewUri }]);+ }+ };if (attachments.length === 0 && pendingUploads.length === 0 && pastePlaceholderCount === 0) return null;return (<View style={styles.tray} testID={`${testIDPrefix}.attachmentTray`}>@@ -144,9 +157,16 @@ export function ComposerAttachmentTray({<Text style={styles.thumbFailedText}>{t('composer.attachments.retry')}</Text></Pressable>) : (- <View style={styles.thumbBusyOverlay}>+ <Pressable+ accessibilityLabel={t('composer.attachments.viewImage', { name: pending.name })}+ accessibilityRole="button"+ disabled={!pending.previewUri}+ onPress={() => previewPending(pending)}+ style={({ pressed }) => [styles.thumbBusyOverlay, pressed && styles.pressed]}+ testID={`${testIDPrefix}.attachmentPendingPreviewButton`}+ ><ActivityIndicator color={colors.swipeActionText} size="small" />- </View>+ </Pressable>)}</View><Pressable@@ -210,6 +230,9 @@ export function ComposerAttachmentTray({</View></View>))}+ {pendingPreview ? (+ <ImageLightbox images={pendingPreview} initialUrl={pendingPreview[0].url} onClose={() => setPendingPreview(null)} />+ ) : null}</View>);}