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): 开着读屏时伙伴私聊保留操作行

zqchris0248568363a2
diff --git a/apps/mobile/src/__tests__/messageSourceLabelsRender.test.tsx b/apps/mobile/src/__tests__/messageSourceLabelsRender.test.tsx
index 5f620d2c0a..301f9b77a6 100644
--- a/apps/mobile/src/__tests__/messageSourceLabelsRender.test.tsx
+++ b/apps/mobile/src/__tests__/messageSourceLabelsRender.test.tsx
@@ -12,6 +12,8 @@ vi.mock('@/platform/gestureHandler', () => {
});
vi.mock('expo-modules-core', () => ({ requireOptionalNativeModule: () => null }));
+// Screen reader toggle and the system action menu availability, for the companion menu case.
+const a11y = vi.hoisted(() => ({ screenReader: null as null | ((enabled: boolean) => void), systemMenu: false }));
const viewportHarness = vi.hoisted(() => ({
list: null as any,
finishReveal: null as any,
@@ -73,7 +75,13 @@ vi.mock("react-native", async () => {
hairlineWidth: 1,
},
Easing: { linear: (n: number) => n, bezier: () => (n: number) => n },
- AccessibilityInfo: {},
+ AccessibilityInfo: {
+ isScreenReaderEnabled: () => Promise.resolve(false),
+ addEventListener: (_event: string, listener: (enabled: boolean) => void) => {
+ a11y.screenReader = listener;
+ return { remove() {} };
+ },
+ },
Alert: {},
Linking: {},
StatusBar: {},
@@ -210,7 +218,7 @@ vi.mock("@/platform/chrome", () => ({
NativePullDownMenu: ({ children }: any) => children,
showActionMenu: vi.fn(),
usesNativePullDownMenu: () => false,
- usesSystemActionMenu: () => false,
+ usesSystemActionMenu: () => a11y.systemMenu,
}));
vi.mock("@/session/MobileComposerInputRow", () => ({
MobileComposerInputRow: () => null,
@@ -238,7 +246,11 @@ vi.mock("@/session/AuthorizationMessageCard", () => ({
AuthorizationMessageCard: () => null,
}));
vi.mock("@/session/CompanionMessageActions", () => ({
- CompanionMessageActions: () => null,
+ CompanionMessageActions: ({ actions, onAction }: any) =>
+ createElement("div", { "data-testid": "companion.messageActions" },
+ actions.some((action: any) => action.id === "add-to-chat")
+ ? createElement("button", { "data-testid": "companion.messageReply", onClick: () => onAction("add-to-chat") })
+ : null),
}));
vi.mock("@/session/CompanionMessageCard", () => ({
CompanionMessageCard: () => null,
@@ -586,3 +598,32 @@ describe('private group reply source', () => {
expect(render([{ ...msg('ordinary', 'Private', null), role: 'assistant' }])).not.toContain('message.groupSource');
});
});
+
+// VoiceOver / TalkBack cannot perform the bubble's long-press gesture, so the companion menu
+// falls back to the action row, whose Reply quotes the message like the menu does.
+describe("companion menu with a screen reader", () => {
+ it("keeps the action row and quotes on Reply while a screen reader is on", () => {
+ a11y.systemMenu = true;
+ const onQuote = vi.fn();
+ const props = {
+ companion: true,
+ companionQuote: { names: { owner: "你", companion: "Vela" }, showReplyTargets: false, onQuote, onLocate: vi.fn(), onSelectText: vi.fn() },
+ onAddMessageToComposer: vi.fn(),
+ };
+ const h = mount([{ ...msg("r1", "Done", { turnCompleted: true }), role: "assistant" }], props);
+ try {
+ expect(h.host.querySelector('[data-testid="companion.messageMenu"]')).not.toBeNull();
+ expect(h.host.querySelector('[data-testid="companion.messageActions"]')).toBeNull();
+ act(() => a11y.screenReader?.(true));
+ expect(h.host.querySelector('[data-testid="companion.messageMenu"]')).toBeNull();
+ const reply = h.host.querySelector('[data-testid="companion.messageReply"]')!;
+ act(() => reply.dispatchEvent(new MouseEvent("click", { bubbles: true })));
+ expect(onQuote).toHaveBeenCalledExactlyOnceWith({ clientId: "r1", role: "assistant", excerpt: "Done" });
+ expect(props.onAddMessageToComposer).not.toHaveBeenCalled();
+ } finally {
+ act(() => a11y.screenReader?.(false));
+ a11y.systemMenu = false;
+ h.unmount();
+ }
+ });
+});
diff --git a/apps/mobile/src/hooks/useScreenReaderEnabled.ts b/apps/mobile/src/hooks/useScreenReaderEnabled.ts
new file mode 100644
index 0000000000..4867f1333e
--- /dev/null
+++ b/apps/mobile/src/hooks/useScreenReaderEnabled.ts
@@ -0,0 +1,30 @@
+/**
+ * 系统读屏(VoiceOver / TalkBack)是否开启。模块级单一订阅,消息列表等高频组件读同一份值,
+ * 不按行各自查询。查询前按 false 处理:读屏用户的首帧可能先看到长按入口,结果到达后立即切换。
+ */
+import { useSyncExternalStore } from 'react';
+import { AccessibilityInfo } from 'react-native';
+
+let enabled = false;
+const listeners = new Set<() => void>();
+const notify = () => listeners.forEach(listener => listener());
+const update = (next: boolean) => {
+ if (next === enabled) return;
+ enabled = next;
+ notify();
+};
+
+// Hosts without the API (web, test stubs) keep the default.
+if (typeof AccessibilityInfo?.isScreenReaderEnabled === 'function') {
+ void AccessibilityInfo.isScreenReaderEnabled().then(update, () => undefined);
+ AccessibilityInfo.addEventListener('screenReaderChanged', update);
+}
+
+const subscribe = (listener: () => void) => {
+ listeners.add(listener);
+ return () => { listeners.delete(listener); };
+};
+
+export function useScreenReaderEnabled(): boolean {
+ return useSyncExternalStore(subscribe, () => enabled, () => false);
+}
diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsx
index f8e3a5ce81..32b82de712 100644
--- a/apps/mobile/src/session/MessageRenderer.tsx
+++ b/apps/mobile/src/session/MessageRenderer.tsx
@@ -21,6 +21,7 @@ import type { ChatReplyQuote } from '@cindy/maker-shared/chat-reply-quote';
import type { NativePullDownAction } from '@/platform/chrome/NativePullDownMenu';
import { AnchoredPullDownMenu } from '@/platform/chrome/AnchoredPullDownMenu';
import { Gesture, GestureDetector } from '@/platform/gestureHandler';
+import { useScreenReaderEnabled } from '@/hooks/useScreenReaderEnabled';
import { useMessageHistoryActive, useMessageHistoryPositioning } from './messageHistoryActivity';
import { usePaneViewport } from '@/platform/AdaptiveWindowContext';
import { messageReadingPosition } from './messageReadingPosition';
@@ -680,6 +681,8 @@ interface MessageActions {
onRetryImageDelivery?: (imageId: string) => Promise<void>;
companion?: boolean;
companionQuoteActions?: CompanionQuoteActions;
+ /** VoiceOver / TalkBack on: the long-press menu has no screen-reader entry, keep the action row. */
+ screenReaderEnabled?: boolean;
onCompanionReadThrough?: (at: number) => void;
onOpenCompanionSettings?: (page: 'memory' | 'capabilities') => void;
companionWorkingLabel?: string | null;
@@ -1825,9 +1828,11 @@ export function MessageRenderer({
isLastReplyFor: (assistantClientId) => lastReplies.has(assistantClientId),
};
}, [companion, companionQuote, lastCompanionReplyKey]);
+ const screenReaderEnabled = useScreenReaderEnabled();
const actions: MessageActions & { firstUserMessageClientId?: string } = useMemo(() => ({
companion,
companionQuoteActions,
+ screenReaderEnabled,
companionWorkingLabel,
onOpenCompanionSettings,
companionAvatar,
@@ -1871,6 +1876,7 @@ export function MessageRenderer({
}), [
companion,
companionQuoteActions,
+ screenReaderEnabled,
companionWorkingLabel,
onOpenCompanionSettings,
companionAvatar,
@@ -3696,9 +3702,10 @@ function MessageBubble({
// 伙伴私聊:长按消息弹出系统菜单(对应桌面悬停时的「回复」等按钮),消息下方不再常驻图标。
// iOS 用系统操作表(MenuView 的长按预览在新架构下抬不起气泡,不改原生代码时不用它);
// Android 由同一个长按手势打开贴着气泡的下拉菜单(菜单不包住气泡,气泡里的点按照常可用)。
- // 都不可用时退回原来的操作行。长按交给菜单后正文不再就地选字,改由「选择文字」打开。
+ // 都不可用、或开着读屏(长按手势没有读屏入口)时退回原来的操作行,其中「回复」同样放引用。
+ // 长按交给菜单后正文不再就地选字,改由「选择文字」打开。
const companionQuote = actions.companionQuoteActions;
- const companionMenuEnabled = !!(actions.companion && hasActions
+ const companionMenuEnabled = !!(actions.companion && hasActions && !actions.screenReaderEnabled
&& (Platform.OS === 'ios' ? usesSystemActionMenu() : usesNativePullDownMenu()));
const bubbleTextSelectable = canSelectVisibleText && !companionMenuEnabled;
const replyQuote = companionQuote && item.message.kind === 'user' ? item.message.replyQuote : undefined;
@@ -4191,7 +4198,8 @@ function MessageBubble({
...(absoluteTime ? [{ id: 'time', title: t('message.renderer.sentTime', { time: absoluteTime }), disabled: true }] : []),
]}
onAction={id => {
- if (id === 'copy') selectControlAction(id);
+ if (id === 'add-to-chat' && companionQuote) selectCompanionMenuAction('reply');
+ else if (id === 'copy') selectControlAction(id);
else if (id === 'share') actions.onEnterShareSelection?.(clientId);
else if (messageMenu.some(item => item.id === id)) selectMenuAction(id as MobileMessageMenuActionId);
}} /> : hasActions ? (
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 35cb897f6c..11867d5e00 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -93,7 +93,7 @@ Chris:「私聊话题和群聊话题,要真的能把独立事件隔离到独
伙伴回复的引用块与摘要按用户看到的文字(组件内容转成可读文字),不显示组件源码。
- **手机端(2026-10-22)**:长按私聊气泡打开消息菜单(iOS 为系统操作表,标题是准确时间;Android 为贴着气泡弹出的下拉菜单,菜单不包住气泡,气泡里的引用、链接与横向滚动照常可点),
依次是回复、复制、选择文字、分享,以及原有的消息链接、回到这里与删除。两端长按都只用 RNGH LongPress(450ms,手指一动
- 即失败),表格和代码块照旧横向滚动;因此私聊气泡正文不再就地选择,改由「选择文字」面板做部分选择(iOS 用
+ 即失败),表格和代码块照旧横向滚动;读屏(VoiceOver / TalkBack)开启时长按手势没有读屏入口,改为显示原来的操作行,其中「回复」同样放引用;因此私聊气泡正文不再就地选择,改由「选择文字」面板做部分选择(iOS 用
UITextView,去掉 Markdown 记号,代码块与行内代码保持原文)。回复在输入框上方放同一种待发引用(卡片底色,× 取消),随普通发送、离线发件箱
与排队编辑一起保留在信封 `replyQuote` 里;待发、已发气泡顶部都显示引用块(只发附件时也显示),点击定位原消息;没有正文气泡的消息(纯附件、错误)保留原操作行。信封解析与摘要和
Desktop 共用 `@cindy/maker-shared/chat-reply-quote`。实现见 Mobile `companionReplyQuote.ts`、