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): 消息文本选中高亮回归系统默认 (#1427)

unclecloudtxy4db672a46f40
diff --git a/apps/mobile/src/__tests__/messageSelectionHighlight.test.ts b/apps/mobile/src/__tests__/messageSelectionHighlight.test.ts
new file mode 100644
index 0000000000..da6e1c1ea4
--- /dev/null
+++ b/apps/mobile/src/__tests__/messageSelectionHighlight.test.ts
@@ -0,0 +1,24 @@
+import { readFile } from 'node:fs/promises';
+import { resolve } from 'node:path';
+import { describe, expect, it } from 'vitest';
+
+/**
+ * 病因留档(PR #1427):消息正文的选中高亮曾逐 view 覆写 selectionColor ——
+ * 先是 surfaceChip(不透明近白,浅色主题下选区对底色仅 1.04:1,选了看不见);
+ * 改稿换 inputCaret(不透明品牌蓝,选中文字对比度跌到 2.6:1,看得见但读不了)。
+ * 不透明覆写两头都讨不到好,而 Android 不传 selectionColor 时回落 Activity 主题的
+ * textColorHighlight(accent 色 ~26% 透明度的半透明 tint),选区可见性与文字可读性
+ * 天然兼得,与 iOS 路径(UITextView 用系统高亮)同构。
+ *
+ * 结论:消息渲染器一律不覆写 selectionColor,选中高亮交还系统。本守卫锁住该决定;
+ * 若未来要品牌化选中色,正路是原生主题层设 accent(会改 fingerprint、走冷更门),
+ * 不是回到逐 view 覆写。composer 输入框的 TextInput selectionColor(光标/手柄)
+ * 是另一语义,不受本守卫约束。
+ */
+describe('mobile message text selection highlight', () => {
+ it('never overrides the platform selection highlight in the message renderer', async () => {
+ const source = await readFile(resolve(process.cwd(), 'src/session/MessageRenderer.tsx'), 'utf8');
+
+ expect(source).not.toMatch(/selectionColor=/);
+ });
+});
diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsx
index 8d76e7aa88..d732460786 100644
--- a/apps/mobile/src/session/MessageRenderer.tsx
+++ b/apps/mobile/src/session/MessageRenderer.tsx
@@ -350,9 +350,14 @@ const stylesStatic = StyleSheet.create({
* (部分选择做不到,facebook/react-native#13938)。换用 react-native-uitextview
* (Bluesky 开源,真 UITextView):长按出系统手柄、支持块内部分选择,嵌套 span 样式与 onPress 保留。
* - Android:RN Text selectable 本身就有系统选择手柄,维持 AppText(带全局字体缩放限幅)。
- * selectionColor 只在 RN Text 路径生效(UITextView 原生 spec 无此 prop,剥掉避免 Fabric 告警)。
+ * 选中高亮双端都刻意**不**覆写 selectionColor,交给系统:iOS UITextView 本就用系统高亮;
+ * Android 不传则回落 Activity 主题的 textColorHighlight(accent 色 ~26% 透明度的半透明
+ * tint),选区可见性与选中文字可读性天然兼得。历史教训(#1427):曾逐 view 覆写不透明
+ * token —— surfaceChip 近白,浅色主题选区与底色仅 1.04:1,选了看不见;换 inputCaret 纯蓝,
+ * 选中文字对比度跌到 2.6:1,看得见但读不了 —— 不透明覆写两头都讨不到好。props 类型
+ * Omit 掉 selectionColor 挡编译期,messageSelectionHighlight.test.ts 锁文件级不再覆写。
*/
-type MarkdownSelectableTextProps = ComponentProps<typeof Text> & {
+type MarkdownSelectableTextProps = Omit<ComponentProps<typeof Text>, 'selectionColor'> & {
/**
* iOS 是否使用可部分选中的 UITextView。超长展开正文禁用它并回退 RN Text:
* UITextView 在折叠→展开时骤增为超高复用视图会偶发只留下巨高空白容器。
@@ -363,7 +368,6 @@ type MarkdownSelectableTextProps = ComponentProps<typeof Text> & {
function MarkdownSelectableText({
allowIosUITextView = true,
selectable,
- selectionColor,
...rest
}: MarkdownSelectableTextProps) {
// chat-text-quote:宿主(MessageRenderer)启用采集时,给 iOS UITextView 传
@@ -407,7 +411,7 @@ function MarkdownSelectableText({
/>
);
}
- return <Text selectable={selectable} selectionColor={selectionColor} {...rest} />;
+ return <Text selectable={selectable} {...rest} />;
}
/**
@@ -3403,7 +3407,6 @@ function MarkdownBody({
allowIosUITextView={allowIosUITextView}
key={group.key}
selectable={runSelectable}
- selectionColor={colors.surfaceChip}
style={styles.messageText}
testID="message.markdownTextRun"
>
@@ -3495,7 +3498,6 @@ function MarkdownBody({
allowIosUITextView={allowIosUITextView}
language={block.language}
selectable={selectable === true}
- selectionColor={colors.surfaceChip}
styles={styles}
text={block.text}
/>
@@ -3514,7 +3516,6 @@ function MarkdownBody({
allowIosUITextView={allowIosUITextView}
key={block.key}
selectable={headingSelectable}
- selectionColor={colors.surfaceChip}
style={headingStyle}
testID="message.markdownHeading"
>
@@ -3528,7 +3529,6 @@ function MarkdownBody({
<MarkdownSelectableText
allowIosUITextView={allowIosUITextView}
selectable={inlinesSelectable(block.inlines)}
- selectionColor={colors.surfaceChip}
style={[styles.messageText, styles.markdownQuoteText]}
>
{renderInlines(block.inlines, spanFor(inlinesSelectable(block.inlines)))}
@@ -3554,7 +3554,6 @@ function MarkdownBody({
<MarkdownSelectableText
allowIosUITextView={allowIosUITextView}
selectable={inlinesSelectable(block.inlines)}
- selectionColor={colors.surfaceChip}
style={[styles.messageText, styles.markdownListText]}
>
{renderInlines(block.inlines, spanFor(inlinesSelectable(block.inlines)))}
@@ -3584,7 +3583,6 @@ function MarkdownBody({
allowIosUITextView={allowIosUITextView}
key={`${block.key}:th:${index}`}
selectable={inlinesSelectable(cell)}
- selectionColor={colors.surfaceChip}
style={[
styles.markdownTableCell,
{ width: columnWidth },
@@ -3605,7 +3603,6 @@ function MarkdownBody({
allowIosUITextView={allowIosUITextView}
key={`${row.key}:td:${index}`}
selectable={inlinesSelectable(cell)}
- selectionColor={colors.surfaceChip}
style={[styles.markdownTableCell, { width: columnWidth }]}
>
{renderInlines(cell, spanFor(inlinesSelectable(cell)))}
@@ -3623,7 +3620,6 @@ function MarkdownBody({
allowIosUITextView={allowIosUITextView}
key={block.key}
selectable={inlinesSelectable(block.inlines)}
- selectionColor={colors.surfaceChip}
style={styles.messageText}
>
{renderInlines(block.inlines, spanFor(inlinesSelectable(block.inlines)))}
@@ -5802,7 +5798,6 @@ function HighlightedCodeText({
allowIosUITextView,
language,
selectable,
- selectionColor,
styles,
text,
}: {
@@ -5810,7 +5805,6 @@ function HighlightedCodeText({
allowIosUITextView: boolean;
language: string | undefined;
selectable: boolean;
- selectionColor: string;
styles: ReturnType<typeof makeStyles>;
text: string;
}) {
@@ -5819,7 +5813,6 @@ function HighlightedCodeText({
<MarkdownSelectableText
allowIosUITextView={allowIosUITextView}
selectable={selectable}
- selectionColor={selectionColor}
style={styles.markdownCodeText}
>
{tokens.map((token, index) => (