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 横屏任务抽屉点击崩溃 (#1390)

Chris Zhang267f0a00108f
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index ed7e312eac..6ddad7fa6d 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -32,12 +32,14 @@ import {
requestRecordingPermissionsAsync,
setAudioModeAsync,
} from 'expo-audio';
-import { useFocusEffect, useLocalSearchParams, useRouter } from 'expo-router';
+import { useFocusEffect, useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
import { forwardRef, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode, type RefObject, type SetStateAction } from 'react';
import {
ActivityIndicator,
+ AccessibilityInfo,
Alert,
AppState,
+ BackHandler,
Keyboard,
KeyboardAvoidingView,
Linking,
@@ -46,6 +48,7 @@ import {
ScrollView,
StyleSheet,
View,
+ findNodeHandle,
useWindowDimensions,
type GestureResponderEvent,
type LayoutChangeEvent,
@@ -747,6 +750,7 @@ export default function SessionScreen() {
const visualFocusComposer = MOBILE_VISUAL_MOCK_ENABLED && readRouteParam(params.visualFocusComposer) === '1';
const visualOpenSearch = MOBILE_VISUAL_MOCK_ENABLED && readRouteParam(params.visualOpenSearch) === '1';
const visualSearchQuery = MOBILE_VISUAL_MOCK_ENABLED ? readRouteParam(params.visualSearchQuery) : null;
+ const navigation = useNavigation();
const router = useRouter();
const auth = useAuth();
const windowDimensions = useWindowDimensions();
@@ -1930,21 +1934,77 @@ export default function SessionScreen() {
windowWidth: windowDimensions.width,
}), [windowDimensions.height, windowDimensions.width]);
const [sessionListDrawerOpen, setSessionListDrawerOpen] = useState(false);
- // 三条杠按钮 ref:抽屉关闭后读屏焦点归还的锚点(SessionListDrawer.returnFocusRef)。
+ // 父级镜像 overlay 的真实存续期:打开时立即 true,退场动画完成 + native 子树卸载后的
+ // onClosed 才 false。它同时保证退场期 TalkBack 背景隔离,以及旋转/收窄退出宽屏时
+ // 不会提前卸载 Drawer 而吞掉 pending 导航。
+ const [sessionListDrawerOverlayMounted, setSessionListDrawerOverlayMounted] = useState(false);
+ // 退出宽屏后 layout.drawerWidth 会变 0;退场期间继续用最后一个有效宽度,避免面板几何跳变。
+ const sessionListDrawerWidthRef = useRef(wideSessionNav.drawerWidth);
+ if (wideSessionNav.enabled) sessionListDrawerWidthRef.current = wideSessionNav.drawerWidth;
+ // 抽屉里的导航动作必须等退场动画结束、GestureDetector/Reanimated overlay 真正
+ // 卸载后再执行。Android 原生 Screen 换页与该子树卸载同帧存在 native crash 竞态。
+ const pendingDrawerNavigationRef = useRef<(() => void) | null>(null);
+ // pending 只能拦住「首击本身就是导航」的连点;遮罩/back/左滑/当前任务先关闭时 pending
+ // 仍为空。closing 从任一关闭入口同步置 true,完整覆盖退场 commit 前的快速二次点击。
+ const sessionListDrawerClosingRef = useRef(false);
+ // 非导航关闭的焦点归还必须晚于父级 overlayMounted=false commit:否则按钮仍在
+ // no-hide-descendants 子树里,VoiceOver/TalkBack 会忽略聚焦并丢失焦点。
+ const returnDrawerFocusAfterCloseRef = useRef(false);
const sessionListButtonRef = useRef<View>(null);
+ const closeSessionListDrawer = useCallback(() => {
+ if (sessionListDrawerClosingRef.current) return;
+ sessionListDrawerClosingRef.current = true;
+ setSessionListDrawerOpen(false);
+ }, []);
// 旋转 / 分屏收窄回到窄屏形态时,抽屉没有入口也没有意义,直接关掉。
useEffect(() => {
- if (!wideSessionNav.enabled) setSessionListDrawerOpen(false);
- }, [wideSessionNav.enabled]);
+ if (!wideSessionNav.enabled && sessionListDrawerOverlayMounted) closeSessionListDrawer();
+ }, [closeSessionListDrawer, sessionListDrawerOverlayMounted, wideSessionNav.enabled]);
+ // 抽屉打开时由 SessionListDrawer 消费 Android back 并发起关闭;open=false 后该监听会
+ // 卸载,但 overlay 仍要退场约 motionDuration.exit。这个窗口临时吞掉 back,避免原生
+ // Screen 返回与 GestureDetector/Reanimated 子树卸载再次挤进同一帧。onClosed 提交
+ // overlayMounted=false 后自动移除,正常返回链(含 useGuardedBack)随即恢复。
+ useEffect(() => {
+ if (Platform.OS !== 'android' || !sessionListDrawerOverlayMounted || sessionListDrawerOpen) return;
+ const subscription = BackHandler.addEventListener('hardwareBackPress', () => true);
+ return () => subscription.remove();
+ }, [sessionListDrawerOpen, sessionListDrawerOverlayMounted]);
const openSessionListDrawer = useCallback(() => {
+ pendingDrawerNavigationRef.current = null;
+ sessionListDrawerClosingRef.current = false;
+ returnDrawerFocusAfterCloseRef.current = false;
Keyboard.dismiss();
+ setSessionListDrawerOverlayMounted(true);
setSessionListDrawerOpen(true);
}, []);
- const closeSessionListDrawer = useCallback(() => setSessionListDrawerOpen(false), []);
+ const queueDrawerNavigation = useCallback((action: () => void) => {
+ // closing 覆盖所有关闭来源,包括 pending 为空的纯关闭;首个意图获胜。
+ if (sessionListDrawerClosingRef.current || pendingDrawerNavigationRef.current) return;
+ sessionListDrawerClosingRef.current = true;
+ pendingDrawerNavigationRef.current = action;
+ setSessionListDrawerOpen(false);
+ }, []);
+ const handleSessionListDrawerClosed = useCallback(() => {
+ const action = pendingDrawerNavigationRef.current;
+ sessionListDrawerClosingRef.current = false;
+ if (!action) returnDrawerFocusAfterCloseRef.current = true;
+ setSessionListDrawerOverlayMounted(false);
+ if (!action) return;
+ pendingDrawerNavigationRef.current = null;
+ action();
+ }, []);
+ useEffect(() => {
+ if (sessionListDrawerOverlayMounted || !returnDrawerFocusAfterCloseRef.current) return;
+ returnDrawerFocusAfterCloseRef.current = false;
+ // 导航型关闭不会登记归还请求;外部导航已让本页失焦时也不抢新屏焦点。
+ if (!navigation.isFocused()) return;
+ const returnNode = sessionListButtonRef.current ? findNodeHandle(sessionListButtonRef.current) : null;
+ if (returnNode != null) AccessibilityInfo.setAccessibilityFocus(returnNode);
+ }, [navigation, sessionListDrawerOverlayMounted]);
const handleDrawerSelectSession = useCallback((item: RemoteSessionListItem) => {
const targetSession = item.session as RemoteSession;
if (targetSession.id === sessionId) {
- setSessionListDrawerOpen(false);
+ closeSessionListDrawer();
return;
}
// 可达优先,与首页 openSession 同口径:被认领的 stale 会话优先 canonicalDeviceId,
@@ -1958,30 +2018,31 @@ export default function SessionScreen() {
Alert.alert(t('devices.list.error.sessionDeviceNotFound'));
return;
}
- setSessionListDrawerOpen(false);
// replace 而非 push:抽屉是「原地切换」语义,栈保持 [主页, 会话],返回手势仍回主页。
- router.replace({
- pathname: '/sessions/[sessionId]',
- params: {
- deviceId: targetDeviceId,
- deviceName: targetSession.deviceLinkDeviceName ?? targetDeviceId,
- sessionId: targetSession.id,
- },
+ queueDrawerNavigation(() => {
+ router.replace({
+ pathname: '/sessions/[sessionId]',
+ params: {
+ deviceId: targetDeviceId,
+ deviceName: targetSession.deviceLinkDeviceName ?? targetDeviceId,
+ sessionId: targetSession.id,
+ },
+ });
});
- }, [router, sessionId, t]);
+ }, [closeSessionListDrawer, queueDrawerNavigation, router, sessionId, t]);
// 前进导航防连点:快速双击「新建」会把 /sessions/new 压栈两层(返回要退两次),
// 与首页各入口同一把 guardedPush 锁。
const guardedPush = useGuardedPush();
const handleDrawerNewSession = useCallback(() => {
- setSessionListDrawerOpen(false);
- guardedPush({ pathname: '/sessions/new', params: { deviceId, deviceName } });
- }, [deviceId, deviceName, guardedPush]);
+ queueDrawerNavigation(() => {
+ guardedPush({ pathname: '/sessions/new', params: { deviceId, deviceName } });
+ });
+ }, [deviceId, deviceName, guardedPush, queueDrawerNavigation]);
// 抽屉「主页」是显式的去处承诺,不是「返回」:从设备详情/自动化页进来时 back 只退一层,
// 会落在中间页。dismissTo 沿当前栈一路退到根页,栈里没有根页(深链冷启动)则推入。
const handleDrawerGoHome = useCallback(() => {
- setSessionListDrawerOpen(false);
- router.dismissTo('/');
- }, [router]);
+ queueDrawerNavigation(() => router.dismissTo('/'));
+ }, [queueDrawerNavigation, router]);
// 聚焦 / 面板打开 / 语音中呈现卡片形态(输入区全宽 + 底部工具排),其余保持单行简洁态。
// 注意不看 composerLayout.density:有草稿 / 会话运行中未聚焦时也应收回简洁态,
// 否则「拖回单行退出激活态」永远收不回去。
@@ -7597,9 +7658,9 @@ export default function SessionScreen() {
// 抽屉开着时把背后内容从读屏树里摘掉:iOS 用 accessibilityElementsHidden
// (与抽屉侧 accessibilityViewIsModal 配对),Android 用 importantForAccessibility
// ——后者才对 TalkBack 生效(与 ComposerRichInput 的双平台配对惯例一致)。
- accessibilityElementsHidden={sessionListDrawerOpen}
+ accessibilityElementsHidden={sessionListDrawerOverlayMounted}
behavior={nativeShellLayout.keyboardAvoidingBehavior}
- importantForAccessibility={sessionListDrawerOpen ? 'no-hide-descendants' : 'auto'}
+ importantForAccessibility={sessionListDrawerOverlayMounted ? 'no-hide-descendants' : 'auto'}
keyboardVerticalOffset={nativeShellLayout.keyboardVerticalOffset}
style={styles.keyboard}
>
@@ -8418,18 +8479,19 @@ export default function SessionScreen() {
</View>
</View>
</KeyboardAvoidingView>
- {wideSessionNav.enabled ? (
+ {wideSessionNav.enabled || sessionListDrawerOverlayMounted ? (
// 树内 overlay(zIndex 40)盖住顶部 chrome 与底部 composer;树内层叠而非 Modal 的
- // 取舍见 SessionListDrawer 头注释。
+ // 取舍见 SessionListDrawer 头注释。退出宽屏时也保留到 onClosed,否则退场期旋转/
+ // 收窄会直接卸载组件并吞掉已登记的导航动作。
<SessionListDrawer
currentSessionId={sessionId}
onClose={closeSessionListDrawer}
+ onClosed={handleSessionListDrawerClosed}
onGoHome={handleDrawerGoHome}
onNewSession={handleDrawerNewSession}
onSelectSession={handleDrawerSelectSession}
open={sessionListDrawerOpen}
- returnFocusRef={sessionListButtonRef}
- width={wideSessionNav.drawerWidth}
+ width={sessionListDrawerWidthRef.current}
/>
) : null}
</View>
diff --git a/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts
index 6c19c4c2fe..3953fbd0b1 100644
--- a/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts
@@ -86,16 +86,48 @@ describe('mobile session header desktop-first surface', () => {
expect(source).toContain("pathname: '/sessions/[sessionId]'");
expect(source).toContain('const handleDrawerSelectSession = useCallback((item: RemoteSessionListItem) => {');
expect(source).toContain('router.replace({');
+ // Android 原生换屏必须等 drawer overlay 完整卸载;三个导航入口共用同一延后队列。
+ expect(source).toContain('const pendingDrawerNavigationRef = useRef<(() => void) | null>(null);');
+ expect(source).toContain('const sessionListDrawerClosingRef = useRef(false);');
+ expect(source).toContain('const [sessionListDrawerOverlayMounted, setSessionListDrawerOverlayMounted] = useState(false);');
+ expect(source).toContain('const queueDrawerNavigation = useCallback((action: () => void) => {');
+ // 纯关闭(遮罩/back/左滑/当前任务)的 pending 仍为空,必须由独立 closing 闸门
+ // 同步锁住约 200ms 退场期;快速二次导航不能登记或改写首次关闭意图。
+ expect(source).toContain('if (sessionListDrawerClosingRef.current || pendingDrawerNavigationRef.current) return;');
+ expect(source).toContain('sessionListDrawerClosingRef.current = true;\n pendingDrawerNavigationRef.current = action;');
+ expect(source).toContain('const closeSessionListDrawer = useCallback(() => {\n if (sessionListDrawerClosingRef.current) return;\n sessionListDrawerClosingRef.current = true;');
+ expect(source).toContain('if (targetSession.id === sessionId) {\n closeSessionListDrawer();');
+ expect(source).toContain('onClosed={handleSessionListDrawerClosed}');
+ expect(source).toContain('const action = pendingDrawerNavigationRef.current;\n sessionListDrawerClosingRef.current = false;\n if (!action) returnDrawerFocusAfterCloseRef.current = true;\n setSessionListDrawerOverlayMounted(false);');
+ expect(source).toContain('pendingDrawerNavigationRef.current = null;\n action();');
+ expect(source).toContain('queueDrawerNavigation(() => {\n router.replace({');
+ expect(source).toContain('queueDrawerNavigation(() => {\n guardedPush({');
+ expect(source).toContain("queueDrawerNavigation(() => router.dismissTo('/'));");
// 旋转 / 分屏收窄回窄屏时抽屉必须自动收起(没有入口的悬空 overlay)。
- expect(source).toContain('if (!wideSessionNav.enabled) setSessionListDrawerOpen(false);');
+ expect(source).toContain('if (!wideSessionNav.enabled && sessionListDrawerOverlayMounted) closeSessionListDrawer();');
+ // Android 退场期(open=false 但 overlay 仍 mounted)必须临时吞掉系统返回;
+ // onClosed 解除 mounted 后 effect cleanup 恢复 useGuardedBack 等正常返回链。
+ expect(source).toContain("if (Platform.OS !== 'android' || !sessionListDrawerOverlayMounted || sessionListDrawerOpen) return;");
+ expect(source).toContain("BackHandler.addEventListener('hardwareBackPress', () => true)");
+ expect(source).toContain('}, [sessionListDrawerOpen, sessionListDrawerOverlayMounted]);');
// 打开抽屉先收键盘(树内 overlay 盖不住键盘)。
- expect(source).toContain('Keyboard.dismiss();\n setSessionListDrawerOpen(true);');
+ expect(source).toContain('Keyboard.dismiss();\n setSessionListDrawerOverlayMounted(true);\n setSessionListDrawerOpen(true);');
// 读屏模态语义双平台配对:iOS accessibilityElementsHidden + Android importantForAccessibility
- // (accessibilityViewIsModal 只对 iOS 生效,安卓优先发布不能漏 TalkBack)。
- expect(source).toContain('accessibilityElementsHidden={sessionListDrawerOpen}');
- expect(source).toContain("importantForAccessibility={sessionListDrawerOpen ? 'no-hide-descendants' : 'auto'}");
+ // (accessibilityViewIsModal 只对 iOS 生效,安卓优先发布不能漏 TalkBack);必须覆盖完整退场期。
+ expect(source).toContain('accessibilityElementsHidden={sessionListDrawerOverlayMounted}');
+ expect(source).toContain("importantForAccessibility={sessionListDrawerOverlayMounted ? 'no-hide-descendants' : 'auto'}");
+ // 非导航关闭的焦点归还必须由父级在背景隔离解除后的 commit effect 执行;
+ // 导航型关闭及页面已失焦时都不能把焦点抢回旧页面。
+ expect(source).toContain('if (sessionListDrawerOverlayMounted || !returnDrawerFocusAfterCloseRef.current) return;');
+ expect(source).toContain('if (!navigation.isFocused()) return;');
+ expect(source).toContain('AccessibilityInfo.setAccessibilityFocus(returnNode)');
+ // 退场期间旋转/折叠/收窄不能直接卸载 Drawer:保留到 onClosed,三类 pending 导航
+ // 才都能执行;宽屏 layout 失效后 drawerWidth=0,退场继续用最后有效宽度。
+ expect(source).toContain('{wideSessionNav.enabled || sessionListDrawerOverlayMounted ? (');
+ expect(source).toContain('if (wideSessionNav.enabled) sessionListDrawerWidthRef.current = wideSessionNav.drawerWidth;');
+ expect(source).toContain('width={sessionListDrawerWidthRef.current}');
// 选任务失败路径:校验先于关闭动画——先关再弹 Alert 会让焦点归还抢走弹窗焦点。
- expect(source).toContain("Alert.alert(t('devices.list.error.sessionDeviceNotFound'));\n return;\n }\n setSessionListDrawerOpen(false);");
+ expect(source).toContain("Alert.alert(t('devices.list.error.sessionDeviceNotFound'));\n return;\n }\n // replace");
});
it('keeps pending history access as a lightweight control without message counters', () => {
diff --git a/apps/mobile/src/__tests__/sessionListDrawer.test.ts b/apps/mobile/src/__tests__/sessionListDrawer.test.ts
index 2bdf349835..bea7718d91 100644
--- a/apps/mobile/src/__tests__/sessionListDrawer.test.ts
+++ b/apps/mobile/src/__tests__/sessionListDrawer.test.ts
@@ -92,13 +92,14 @@ describe('mobile session list drawer', () => {
]) {
expect(text).toContain(`testID="${testId}"`);
}
- expect(text).toContain('accessibilityViewIsModal={open}');
+ expect(text).toContain('accessibilityViewIsModal={mounted}');
expect(text).toContain("t('home.drawer.closeA11y')");
- // 读屏焦点管理(review #1328):打开移焦到面板首控件,关闭归还三条杠;
- // 导航型关闭(本屏已失焦)不归还,不抢新屏焦点。
+ // 打开时把读屏焦点移到面板首控件;关闭后的背景焦点归还由父级在解除
+ // accessibility 隔离后的 commit effect 负责。
expect(text).toContain('AccessibilityInfo.setAccessibilityFocus(node)');
- expect(text).toContain('AccessibilityInfo.setAccessibilityFocus(returnNode)');
expect(text).toContain('ref={newSessionButtonRef}');
- expect(text).toContain('if (!navigation.isFocused()) return;');
+ // 导航动作必须等 overlay 的 mounted=false commit 后执行,不能与 Android 原生换屏同帧。
+ expect(text).toContain('onClosedRef.current?.();');
+ expect(text).not.toContain('returnFocusRef');
});
});
diff --git a/apps/mobile/src/session/SessionListDrawer.tsx b/apps/mobile/src/session/SessionListDrawer.tsx
index 283fd2ec43..44378ed712 100644
--- a/apps/mobile/src/session/SessionListDrawer.tsx
+++ b/apps/mobile/src/session/SessionListDrawer.tsx
@@ -6,8 +6,9 @@
*
* 结构取舍:
* - **树内 overlay 而非 RN Modal**:会话页已有多个 sheet Modal,iOS 同级双 Modal
- * 有 present/dismiss 竞态(见 SheetSurface 头注释);树内层叠没有这些约束,选中任务
- * 后可立即导航(replace 卸载整屏,无需等 Modal 关闭动画)。代价是盖不住原生弹层,
+ * 有 present/dismiss 竞态(见 SheetSurface 头注释);树内层叠没有这些约束。导航动作
+ * 仍必须等 overlay 退场并真正卸载后执行:Android 原生 Screen 换页若与
+ * GestureDetector/Reanimated 子树卸载挤在同一帧存在崩溃竞态。代价是盖不住原生弹层,
* 但抽屉打开前页面会先收键盘,且其它 sheet 与抽屉互斥(都由页面状态驱动)。
* - **数据直读全局 remoteSessionStore**:与首页同一份 store(进会话页前已水合,
* 设备订阅继续推增量),经共享层 buildMobileHomePresentation 复用首页的排序 /
@@ -16,7 +17,7 @@
* (useReduceMotionEnabled === false 才播)。
*/
import { House, LoaderCircle, SquarePen } from 'lucide-react-native';
-import { memo, useCallback, useEffect, useMemo, useRef, useState, type RefObject } from 'react';
+import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
AccessibilityInfo,
BackHandler,
@@ -36,7 +37,6 @@ import Animated, {
withTiming,
} from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
-import { useNavigation } from 'expo-router';
import { useTranslation } from 'react-i18next';
import { Text } from '@/components/AppText';
import { Gesture, GestureDetector } from '@/platform/gestureHandler';
@@ -79,21 +79,21 @@ const DRAWER_CLOSE_VELOCITY = -800;
export function SessionListDrawer({
currentSessionId,
onClose,
+ onClosed,
onGoHome,
onNewSession,
onSelectSession,
open,
- returnFocusRef,
width,
}: {
currentSessionId: string;
onClose(): void;
+ /** 关闭动画完成、overlay 真正卸载后触发。 */
+ onClosed?(): void;
onGoHome(): void;
onNewSession(): void;
onSelectSession(item: RemoteSessionListItem): void;
open: boolean;
- /** 关闭后读屏焦点归还的触发钮(左上角三条杠);切任务导航整屏卸载时不消费。 */
- returnFocusRef?: RefObject<View | null>;
width: number;
}) {
const styles = useThemedStyles(makeStyles);
@@ -114,19 +114,23 @@ export function SessionListDrawer({
// progress 0→1 = 收起→展开;dragX(≤0)是手势拖拽的临时位移,松手后归零或并入 progress。
const progress = useSharedValue(open ? 1 : 0);
const dragX = useSharedValue(0);
- // 关闭收尾统一走这里(动画完成回调 / reduce-motion 直跳两条路径):卸载 overlay 并把
- // 读屏焦点还给触发钮——三条杠在抽屉打开期间被遮罩挡住,不还焦点会落在任意节点。
- const navigation = useNavigation();
+ // 关闭收尾统一走这里(动画完成回调 / reduce-motion 直跳两条路径):先只卸载 overlay。
+ // onClosed 必须等 mounted=false 的 commit 完成,否则导航会和 GestureDetector/
+ // Reanimated 子树卸载挤进同一帧(Android 原生 Screen 存在崩溃竞态)。背景焦点归还
+ // 则由父级在 accessibility 隔离解除后的 commit effect 中完成。
const finishClose = useCallback(() => {
if (openRef.current) return;
setMounted(false);
- // 只有「原地关闭」(本屏仍聚焦)才归还焦点:导航型关闭(新建 push / 深链下
- // dismissTo 推入主页)收尾时本屏已失焦,把读屏焦点拉回背景页的三条杠会抢走
- // 新屏焦点。isFocused 是确定性信号,不用枚举关闭原因。
- if (!navigation.isFocused()) return;
- const returnNode = returnFocusRef?.current ? findNodeHandle(returnFocusRef.current) : null;
- if (returnNode != null) AccessibilityInfo.setAccessibilityFocus(returnNode);
- }, [navigation, returnFocusRef]);
+ }, []);
+ const onClosedRef = useRef(onClosed);
+ onClosedRef.current = onClosed;
+ const wasMountedRef = useRef(mounted);
+ useEffect(() => {
+ const wasMounted = wasMountedRef.current;
+ wasMountedRef.current = mounted;
+ if (!wasMounted || mounted) return;
+ onClosedRef.current?.();
+ }, [mounted]);
// 打开后把读屏焦点移进面板首控件(新建任务):背后内容已按模态摘出读屏树,不移焦
// VoiceOver/TalkBack 会停在已隐藏的节点上。延到入场动画结束再移,避免读出滑动中的几何。
const newSessionButtonRef = useRef<View>(null);
@@ -310,7 +314,7 @@ export function SessionListDrawer({
return (
<View
// iOS VoiceOver:抽屉开着时按模态处理,不让焦点跑到被遮住的会话内容上。
- accessibilityViewIsModal={open}
+ accessibilityViewIsModal={mounted}
// mounted 期间恒拦截(含 200ms 关闭动画):此时 scrim 仍半透明盖着内容,放行
// 点击会穿透误触;落在 scrim 上的点击只是幂等地再触发一次 onClose。
pointerEvents="auto"