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): Android「选择文字」面板按内容定高,资料页开关补分组标题

zqchris7d1be9130ba6
diff --git a/apps/mobile/docs/mobile-design-guide.md b/apps/mobile/docs/mobile-design-guide.md
index b10a44b8f9..be8c6caf34 100644
--- a/apps/mobile/docs/mobile-design-guide.md
+++ b/apps/mobile/docs/mobile-design-guide.md
@@ -264,7 +264,7 @@ iOS 新增与改造界面遵循 [iOS 原生界面规范](../../../docs/design-ru
新建任务的设备、工作区和远程目录选择复用 RN `NewTaskSelectionRow`;设备使用原生底部弹层,
目录仍在同一兼容弹层内逐级返回,盘符通过原生菜单切换,继续调用被控端目录接口。
开关和普通文本输入原本已是原生控件;富文本编辑器不属于此次迁移。
-- **Android 交互跟随 iOS**(2026-09-27 产品裁决):入口位置、顺序、分组、显示哪些信息与输入校验以 iOS 为准;外观保持 Android 平台实现,不照搬玻璃。贴着控件弹出的菜单统一走 `NativePullDownMenu`,Android 通过 `AnchoredPullDownMenu.android` 使用现有 Expo UI 的 Material `DropdownMenu`,保留分组标题、勾选、禁用、危险操作、子菜单返回行及 `keepPresented`。弹出定位、滚动、焦点及动画交给系统;外部点击和系统返回收起原生菜单。触发器整块是一个读屏按钮,触发控件禁用时不挂菜单。自绘实现保留用于兼容,不使用能力不足的基础 PopupMenu 替代。
+- **Android 交互跟随 iOS**(2026-09-27 产品裁决):入口位置、顺序、分组、显示哪些信息与输入校验以 iOS 为准;外观保持 Android 平台实现,不照搬玻璃。贴着控件弹出的菜单统一走 `NativePullDownMenu`,Android 通过 `AnchoredPullDownMenu.android` 使用现有 Expo UI 的 Material `DropdownMenu`,保留分组标题、勾选、禁用、危险操作、子菜单返回行及 `keepPresented`。弹出定位、滚动、焦点及动画交给系统;外部点击和系统返回收起原生菜单。触发器整块是一个读屏按钮,触发控件禁用时不挂菜单。例外是伙伴私聊气泡的长按菜单:气泡里有引用、链接和横向滚动,菜单不能接管整块触摸,改由调用方用同一个 RNGH 长按手势识别后,以受控方式(`open` / `onOpenChange`)打开 `AnchoredPullDownMenu`。自绘实现保留用于兼容,不使用能力不足的基础 PopupMenu 替代。
原生菜单首次使用时创建 Compose 容器,随后随触发器复用;收起只修改 `expanded`,保留系统关闭动画,避免每次点击重建整棵原生树。锚点的 RN 外层使用 `pointerEvents="none"`,防止关闭后的容器挡住触发器;弹出窗口独立接收菜单点击。验收必须覆盖关闭后再次打开、外部点击和菜单项选择,不能只验证首次呈现。
可勾选菜单项在原生弹出窗口中使用 `RNHostView` 承载一个 RN `menuitem`,通过 `accessibilityState.checked` 表达选中、未选中和半选,禁用态与整行点击共用同一节点;勾号只是装饰,不能代替无障碍语义。现有 Compose modifier 未提供完整三态设置,不增加第二个可点击复选框。回归见 `androidMaterialMenu.test.tsx`,模拟器须核验真实节点。
diff --git a/apps/mobile/src/session/CompanionProfileSheet.tsx b/apps/mobile/src/session/CompanionProfileSheet.tsx
index e6cacabfa8..56262a16d3 100644
--- a/apps/mobile/src/session/CompanionProfileSheet.tsx
+++ b/apps/mobile/src/session/CompanionProfileSheet.tsx
@@ -387,6 +387,7 @@ function CompanionProfileSheetContent(props: CompanionProfileSheetProps) {
<View style={styles.group}>{row('profile', Info)}{row('memory', Brain)}{row('models', Sparkles)}{row('skills', Settings2)}</View>
{/* Device preference for every teammate's chat, not part of this teammate's host profile. */}
<View style={styles.field}>
+ <Text accessibilityRole="header" style={styles.groupLabel}>{t('devices.companionProfile.chat')}</Text>
<View style={styles.group}><View style={styles.inline}>
<Text style={styles.switchLabel}>{t('devices.companionProfile.showReplyTarget')}</Text>
<NativeSwitch accessibilityLabel={t('devices.companionProfile.showReplyTarget')} value={showReplyTargets}
@@ -626,6 +627,8 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
note: { fontSize: typeScale.footnote, lineHeight: lineHeight.caption, color: colors.textSecondary },
body: { fontSize: typeScale.body, lineHeight: lineHeight.body, color: colors.textPrimary },
heading: { fontSize: typeScale.body, lineHeight: lineHeight.body, color: colors.textPrimary, fontWeight: fontWeight.medium },
+ // Mobile design guide 「分组小标签」, aligned with the group's inner padding (iOS Section title).
+ groupLabel: { fontSize: typeScale.footnote, lineHeight: lineHeight.caption, fontWeight: fontWeight.semibold, color: colors.textTertiary, paddingHorizontal: spacing.lg },
switchLabel: { flex: 1, fontSize: typeScale.body, lineHeight: lineHeight.body, color: colors.textPrimary },
group: { backgroundColor: colors.surfaceElevated, borderColor: colors.border, borderWidth: StyleSheet.hairlineWidth, borderRadius: radius.container, overflow: 'hidden', paddingHorizontal: spacing.lg },
groupText: { paddingVertical: spacing.md },
diff --git a/apps/mobile/src/session/CompanionSelectTextSheet.tsx b/apps/mobile/src/session/CompanionSelectTextSheet.tsx
index 3bb35306db..941440dc29 100644
--- a/apps/mobile/src/session/CompanionSelectTextSheet.tsx
+++ b/apps/mobile/src/session/CompanionSelectTextSheet.tsx
@@ -1,29 +1,50 @@
/**
* 伙伴私聊长按菜单的「选择文字」:长按交给系统菜单后,正文改在这里用系统文字选择挑一部分复制。
* 挂载即打开;关闭先播完系统收起,再由 onClose 卸载,不叠第二个面板。iOS 用 UITextView,可只选一部分。
+ * Android 用按内容定高的面板:短消息不留大片空白,长消息在面板内滚动。不用原生底部面板:它打开时把
+ * 焦点交给可选文字,Android 会在正文上画一条默认焦点高亮。
*/
import { useState } from 'react';
-import { Platform, StyleSheet, View } from 'react-native';
+import { Platform, ScrollView, StyleSheet, View, useWindowDimensions } from 'react-native';
import { UITextView } from 'react-native-uitextview';
import { useTranslation } from 'react-i18next';
+import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { Text } from '@/components/AppText';
-import { useThemedStyles, type ThemeColors } from '@/theme';
-import { lineHeight, spacing, typeScale } from '@/theme/tokens';
+import { radius, useThemedStyles, type ThemeColors } from '@/theme';
+import { fontWeight, lineHeight, spacing, typeScale } from '@/theme/tokens';
import { CompanionSheet } from './CompanionSheet';
+import { SheetModal } from './SheetModal';
+import { SheetGrabber } from './SheetSurface';
import { selectableMessageText } from './selectableMessageText';
export function CompanionSelectTextSheet({ text, onClose }: { text: string; onClose: () => void }) {
const { t } = useTranslation();
const styles = useThemedStyles(makeStyles);
+ const insets = useSafeAreaInsets();
+ const window = useWindowDimensions();
const [visible, setVisible] = useState(true);
+ const title = t('message.renderer.selectText');
+ const close = () => setVisible(false);
+ if (Platform.OS === 'android') {
+ return (
+ <SheetModal visible={visible} onRequestClose={close} onBackdropPress={close} onClosed={onClose}>
+ <View style={[styles.androidCard, { maxHeight: window.height * 0.8, paddingBottom: spacing.lg + insets.bottom }]}
+ testID="companion.selectTextSheet">
+ <SheetGrabber />
+ <Text accessibilityRole="header" numberOfLines={1} style={styles.title}>{title}</Text>
+ {/* Sized by its text inside the content-height sheet; scrolls once it reaches the cap. */}
+ <ScrollView style={styles.scroll}>
+ <Text selectable style={styles.text}>{selectableMessageText(text)}</Text>
+ </ScrollView>
+ </View>
+ </SheetModal>
+ );
+ }
return (
- <CompanionSheet visible={visible} title={t('message.renderer.selectText')} onClose={() => setVisible(false)}
- onClosed={onClose} testID="companion.selectTextSheet">
+ <CompanionSheet visible={visible} title={title} onClose={close} onClosed={onClose} testID="companion.selectTextSheet">
<View style={styles.content}>
{/* iOS RN Text can only copy the whole block; UITextView gives system handles for part of it. */}
- {Platform.OS === 'ios'
- ? <UITextView selectable uiTextView style={styles.text}>{selectableMessageText(text)}</UITextView>
- : <Text selectable style={styles.text}>{selectableMessageText(text)}</Text>}
+ <UITextView selectable uiTextView style={styles.text}>{selectableMessageText(text)}</UITextView>
</View>
</CompanionSheet>
);
@@ -31,5 +52,15 @@ export function CompanionSelectTextSheet({ text, onClose }: { text: string; onCl
const makeStyles = (colors: ThemeColors) => StyleSheet.create({
content: { paddingBottom: spacing.lg },
+ // Same surface, corners and padding as the other teammate sheets (SheetSurface).
+ androidCard: {
+ backgroundColor: colors.surfaceElevated,
+ borderTopLeftRadius: radius.container,
+ borderTopRightRadius: radius.container,
+ paddingHorizontal: 20,
+ paddingTop: spacing.sm,
+ },
+ scroll: { flexGrow: 0 },
+ title: { color: colors.textPrimary, fontSize: typeScale.body, lineHeight: lineHeight.body, fontWeight: fontWeight.semibold, textAlign: 'center', paddingBottom: spacing.md },
text: { color: colors.textPrimary, fontSize: typeScale.bodyLarge, lineHeight: lineHeight.bodyLarge },
});