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): 同步抽屉退场与设置页默认转场 (#5843)

Kirozeng468a07111844
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx
index 05bbf10d42..5a3186898c 100644
--- a/apps/mobile/app/_layout.tsx
+++ b/apps/mobile/app/_layout.tsx
@@ -202,8 +202,6 @@ function NavigationGate() {
<Stack.Screen name="sessions/new" options={({ route }) => ({
animation: readComposerEntry((route.params as { composerMorph?: string } | undefined)?.composerMorph) ? 'none' : 'default',
})} />
- {/* 设置从左侧抽屉进入:接着抽屉方向从左边推出,不要默认从右边盖上来。 */}
- <Stack.Screen name="settings" options={{ animation: 'slide_from_left' }} />
<Stack.Screen
name="add-account"
options={{ animation: 'fade', gestureEnabled: false }}
diff --git a/apps/mobile/src/__tests__/homeChromeDrawer.test.tsx b/apps/mobile/src/__tests__/homeChromeDrawer.test.tsx
index 92726d68ce..7468dce79e 100644
--- a/apps/mobile/src/__tests__/homeChromeDrawer.test.tsx
+++ b/apps/mobile/src/__tests__/homeChromeDrawer.test.tsx
@@ -33,9 +33,21 @@ vi.mock('react-native', async () => {
testID?: string;
onPress?: () => void;
accessibilityState?: { busy?: boolean; disabled?: boolean };
+ pointerEvents?: string;
+ accessibilityElementsHidden?: boolean;
+ importantForAccessibility?: string;
};
- const View = ({ children, testID, onPress }: Props) =>
- createElement('div', { 'data-testid': testID, onClick: onPress }, children);
+ const View = ({ children, testID, onPress, pointerEvents, accessibilityElementsHidden, importantForAccessibility }: Props) =>
+ createElement('div', {
+ 'data-testid': testID,
+ 'data-pointer-events': pointerEvents,
+ 'aria-hidden': accessibilityElementsHidden,
+ 'data-important-for-accessibility': importantForAccessibility,
+ // Model the native subtree hit-testing boundary; jsdom ignores pointerEvents.
+ onClick: (event: { currentTarget: HTMLElement }) => {
+ if (!event.currentTarget.closest('[data-pointer-events="none"]')) onPress?.();
+ },
+ }, children);
return {
View,
Pressable: View,
@@ -216,4 +228,41 @@ describe('Android home drawer window and close lifecycle', () => {
// onClosed 只在窗口真正卸载后触发一次:调用方的延后动作以此为信号执行。
expect(props.onClosed).toHaveBeenCalledOnce();
});
+
+ it.each(['android', 'ios'] as const)('ignores backdrop and menu taps during %s exit without cancelling the queued action', async platform => {
+ h.platform.OS = platform;
+ const completed = vi.fn();
+ let pending: (() => void) | null = null;
+ const props = drawerProps({
+ onOpenSearch: vi.fn(() => { pending = completed; }),
+ onClose: vi.fn(() => { pending = null; }),
+ onClosed: vi.fn(() => { const action = pending; pending = null; action?.(); }),
+ });
+ const click = async (id: string) => {
+ await act(async () => (container.querySelector(`[data-testid="${id}"]`) as HTMLElement).click());
+ };
+ await act(async () => root.render(<HomeChromeDrawer {...props} />));
+ await click('home.chromeDrawer.search');
+ expect(props.onOpenSearch).toHaveBeenCalledOnce();
+ await act(async () => root.render(<HomeChromeDrawer {...props} open={false} />));
+ const overlay = container.querySelector('[data-testid="home.chromeDrawer"]')!;
+ expect(overlay.getAttribute('data-pointer-events')).toBe('none');
+ expect(overlay.getAttribute('aria-hidden')).toBe('true');
+ expect(overlay.getAttribute('data-important-for-accessibility')).toBe('no-hide-descendants');
+ for (const id of ['home.chromeMenu.backdrop', 'home.chromeDrawer.search', 'home.chromeDrawer.accounts', 'home.chromeDrawer.devices', 'devices.settingsButton', 'home.chromeDrawer.logout']) {
+ await click(id);
+ }
+ expect(props.onClose).not.toHaveBeenCalled();
+ expect(props.onOpenSearch).toHaveBeenCalledOnce();
+ expect(props.onOpenAccounts).not.toHaveBeenCalled();
+ expect(props.onOpenDevices).not.toHaveBeenCalled();
+ expect(props.onOpenSettings).not.toHaveBeenCalled();
+ expect(props.onLogout).not.toHaveBeenCalled();
+ expect(completed).not.toHaveBeenCalled();
+ await finishTiming();
+ expect(completed).toHaveBeenCalledOnce();
+ await act(async () => root.render(<HomeChromeDrawer {...props} />));
+ await click('home.chromeDrawer.accounts');
+ expect(props.onOpenAccounts).toHaveBeenCalledOnce();
+ });
});
diff --git a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
index 6821b4df94..368c5d4e30 100644
--- a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
@@ -270,11 +270,17 @@ describe('mobile home desktop-first surface', () => {
expect(chromeDrawer).toContain('GestureHandlerRootView');
expect(chromeDrawer).not.toContain('remoteSettings');
expect(source).toContain("guardedPush('/settings')");
- expect(source).toContain('setChromeMenuCloseInstant(true)');
- expect(source).not.toContain("pendingMenuActionRef.current = () => guardedPush('/settings')");
+ expect(source).not.toContain('setChromeMenuCloseInstant');
+ expect(source).toContain('onClosed={handleChromeMenuClosed}');
+ for (const route of ['/settings', '/devices/manage', '/plugins']) {
+ expect(source).not.toContain(`pendingMenuActionRef.current = () => guardedPush('${route}')`);
+ expect(source).toContain(`setChromeMenuOpen(false);\n guardedPush('${route}');`);
+ }
+ const teammateHome = readSource('src/session/TeammateHomeScreen.tsx');
+ expect(teammateHome).toContain("onOpenSettings={() => openDrawerPage('/settings')}");
+ expect(teammateHome).toContain("onOpenAccounts={() => afterDrawer(() => setAccounts(true))}");
const rootLayout = readSource('app/_layout.tsx');
- expect(rootLayout).toContain('name="settings"');
- expect(rootLayout).toContain("animation: 'slide_from_left'");
+ expect(rootLayout).not.toContain("animation: 'slide_from_left'");
expect(source).toContain("label={t('devices.list.allConversations')}");
// 显示菜单只有一份菜单模型(homeChromeMenus),原生下拉 / 自绘兜底都消费它,不再有平行的自绘面板。
expect(source).toContain('homeDisplayActionPatch(id, displayMenuState)');
diff --git a/apps/mobile/src/session/HomeChromeDrawer.tsx b/apps/mobile/src/session/HomeChromeDrawer.tsx
index 6ee3e9ecef..a23f9a9249 100644
--- a/apps/mobile/src/session/HomeChromeDrawer.tsx
+++ b/apps/mobile/src/session/HomeChromeDrawer.tsx
@@ -280,8 +280,11 @@ export function HomeChromeDrawer({
const overlay = (
<View
- accessibilityViewIsModal
- pointerEvents="auto"
+ accessibilityViewIsModal={open}
+ accessibilityElementsHidden={!open}
+ importantForAccessibility={open ? 'auto' : 'no-hide-descendants'}
+ // Keep the exit animation mounted without accepting a second menu/backdrop action.
+ pointerEvents={open ? 'auto' : 'none'}
style={styles.overlay}
testID="home.chromeDrawer"
>
diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsx
index d84cc1246e..0f96309435 100644
--- a/apps/mobile/src/session/HomeSurface.tsx
+++ b/apps/mobile/src/session/HomeSurface.tsx
@@ -628,7 +628,6 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
const [deviceMenuOpen, setDeviceMenuOpen] = useState(false);
const [chromeMenuOpen, setChromeMenuOpen] = useState(false);
const [accountSwitcherOpen, setAccountSwitcherOpen] = useState(false);
- const [chromeMenuCloseInstant, setChromeMenuCloseInstant] = useState(false);
const [loggingOut, setLoggingOut] = useState(false);
// 菜单关闭动画完成(Modal 卸载)后要执行的动作。iOS 上两个兄弟 Modal 重叠时,第二个 Modal
// 是叠在菜单 Modal 的 VC 上 present 的,菜单淡出后卸载会把它连带 dismiss 掉——所以从菜单里
@@ -1669,7 +1668,6 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
const openChromeMenu = useCallback(() => {
pendingMenuActionRef.current = null;
setDeviceMenuOpen(false);
- setChromeMenuCloseInstant(false);
setChromeMenuOpen(true);
}, []);
@@ -3317,48 +3315,39 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
mode="tasks"
onModeChange={onModeChange ? (next) => {
pendingMenuActionRef.current = () => onModeChange(next);
- setChromeMenuCloseInstant(false);
setChromeMenuOpen(false);
} : undefined}
- closeInstant={chromeMenuCloseInstant}
loggingOut={loggingOut}
onClose={() => {
- setChromeMenuCloseInstant(false);
+ pendingMenuActionRef.current = null;
setChromeMenuOpen(false);
}}
- onClosed={() => {
- setChromeMenuCloseInstant(false);
- handleChromeMenuClosed();
- }}
+ onClosed={handleChromeMenuClosed}
onOpenSearch={() => {
// 搜索框 autoFocus 要等菜单窗口完全卸载(onClosed)后再挂载:Android 的
// Dialog 还在退场时底层 Activity 没有窗口焦点,首次聚焦和软键盘请求会丢。
pendingMenuActionRef.current = () => setSearchOpen(true);
- setChromeMenuCloseInstant(false);
setChromeMenuOpen(false);
}}
onOpenAccounts={() => {
pendingMenuActionRef.current = () => setAccountSwitcherOpen(true);
- setChromeMenuCloseInstant(false);
setChromeMenuOpen(false);
}}
onOpenPlugins={() => {
pendingMenuActionRef.current = null;
- guardedPush('/plugins');
- setChromeMenuCloseInstant(true);
setChromeMenuOpen(false);
+ guardedPush('/plugins');
}}
onOpenDevices={() => {
pendingMenuActionRef.current = null;
- guardedPush('/devices/manage');
- setChromeMenuCloseInstant(true);
setChromeMenuOpen(false);
+ guardedPush('/devices/manage');
}}
onOpenSettings={() => {
+ // 页面转场与抽屉退场同步开始;搜索和账号浮层仍等待 onClosed。
pendingMenuActionRef.current = null;
- guardedPush('/settings');
- setChromeMenuCloseInstant(true);
setChromeMenuOpen(false);
+ guardedPush('/settings');
}}
// 抽屉内部先确认(confirmLogout)再调 onLogout,这里不重复确认。
hasRunningTasks={runningSessionIds.size > 0}
diff --git a/apps/mobile/src/session/TeammateHomeScreen.tsx b/apps/mobile/src/session/TeammateHomeScreen.tsx
index c41fd851d3..744a85fdd2 100644
--- a/apps/mobile/src/session/TeammateHomeScreen.tsx
+++ b/apps/mobile/src/session/TeammateHomeScreen.tsx
@@ -62,6 +62,11 @@ export function TeammateHomeScreen({ active = true }: { active?: boolean }) {
if (id === 'tasks') void navigation.chooseMode('tasks');
};
const afterDrawer = (action: () => void) => { pending.current = action; setDrawer(false); };
+ const openDrawerPage = (href: Parameters<typeof push>[0]) => {
+ pending.current = null;
+ setDrawer(false);
+ push(href);
+ };
const finishOverlay = () => { const action = pending.current; pending.current = null; action?.(); };
useEffect(() => {
mounted.current = true;
@@ -121,9 +126,9 @@ export function TeammateHomeScreen({ active = true }: { active?: boolean }) {
onModeChange={(mode) => afterDrawer(() => { void navigation.setMode(mode); })}
onClose={() => { pending.current = null; setDrawer(false); }} onClosed={finishOverlay}
onOpenSearch={() => afterDrawer(() => setSearchEpoch((epoch) => epoch + 1))}
- onOpenPlugins={() => afterDrawer(() => push('/plugins'))}
- onOpenDevices={() => afterDrawer(() => push('/devices/manage'))}
- onOpenSettings={() => afterDrawer(() => push('/settings'))}
+ onOpenPlugins={() => openDrawerPage('/plugins')}
+ onOpenDevices={() => openDrawerPage('/devices/manage')}
+ onOpenSettings={() => openDrawerPage('/settings')}
onOpenAccounts={() => afterDrawer(() => setAccounts(true))}
// 抽屉内部已 confirmLogout;成功后与设置页一致直接回登录页,不依赖外层自动跳转的时序。
onLogout={() => {
diff --git a/docs/design-rules/ios-native-design.md b/docs/design-rules/ios-native-design.md
index 3386eb3673..6ec9f64d58 100644
--- a/docs/design-rules/ios-native-design.md
+++ b/docs/design-rules/ios-native-design.md
@@ -12,6 +12,7 @@
## 2. 顶部导航
+- 设置页与其他普通页面统一使用系统默认转场,不因入口位于左侧抽屉而反转方向。从任务首页或伙伴首页抽屉进入设置、设备管理或插件页面时,抽屉退场(含遮罩淡出)与系统页面转场同步开始,不先等抽屉关完,也不额外叠加整页淡入。搜索与账号面板仍等待抽屉关闭回调,避免浮层重叠及键盘焦点丢失。实现见 `apps/mobile/app/_layout.tsx` 与 `HomeSurface`、`TeammateHomeScreen`。
- 首页与任务页导航内容的垂直位置保持一致;安全区只计入一次。对齐的是返回按钮、标题和操作的实际中心,不是容器外框高度。
- 任务顶部整体透明,与中部内容保持连续背景,不另铺一条不一致的底色。
- 标题只显示任务名称,不叠 Harness 图标或第二排元信息;完整信息进入任务详情。长标题截断,不挤压两侧操作。