Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 修复 Android 平板侧边栏被任务列表遮挡 (#5390)
Tsai Yuan9af1539b4779
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex 6cf047a82d..02604f7571 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -168,8 +168,8 @@ function NavigationGate() {/>) : null}<RemoteDesktopHost>- <ResidentHomeListProvider key={auth.accountGeneration}>- <RecentMessageHistoriesProvider>+ <RecentMessageHistoriesProvider key={auth.accountGeneration}>+ <ResidentHomeListProvider><Stackkey={auth.accountGeneration}screenOptions={{@@ -206,8 +206,8 @@ function NavigationGate() {options={{ animation: 'fade', gestureEnabled: false }}/></Stack>- </RecentMessageHistoriesProvider></ResidentHomeListProvider>+ </RecentMessageHistoriesProvider></RemoteDesktopHost>{auth.initialized && auth.isAuthenticated && !splashActive && <ClipboardSharedTaskPrompt accountName={auth.user?.name} />}</NavigationThemeProvider>diff --git a/apps/mobile/src/__tests__/recentMessageHistories.test.tsx b/apps/mobile/src/__tests__/recentMessageHistories.test.tsxindex 46749baba6..9238dfaa8e 100644--- a/apps/mobile/src/__tests__/recentMessageHistories.test.tsx+++ b/apps/mobile/src/__tests__/recentMessageHistories.test.tsx@@ -18,19 +18,36 @@ vi.mock('expo-router/react-navigation', () => ({ useIsFocused: () => state.focusNavigationContext: createContext(null), NavigationRouteContext: createContext(null) }));vi.mock('@/platform/AdaptiveWindowContext', () => ({usePaneViewport: () => ({ width: state.width, height: state.height }),+ useAdaptiveWindow: () => ({ width: state.width, height: state.height }),PaneViewportProvider: ({ children }: { children: ReactNode }) => children,}));+vi.mock('@/session/useHomeMode', () => ({ useHomeMode: () => ({ mode: 'tasks' }) }));+vi.mock('@/hooks/useReduceMotion', () => ({ useReduceMotionEnabled: () => true }));+vi.mock('@/session/sessionPaneLayout', () => ({ sessionPaneLayout: () => ({ persistent: true }) }));+vi.mock('@/session/remoteSessionStore', () => ({+ RemoteSessionStoreSubscriptionGate: ({ children }: { children: ReactNode }) => children,+}));+vi.mock('react-native-reanimated', () => ({+ default: {+ View: ({ children, pointerEvents, style }: { children: ReactNode; pointerEvents?: string; style?: unknown }) =>+ <div data-resident-host="true" data-input={pointerEvents} data-layout={JSON.stringify(style)}>{children}</div>,+ },+}));vi.mock('react-native', () => ({StyleSheet: { create: (styles: unknown) => styles },View: ({ children, pointerEvents, accessibilityElementsHidden, ref, style, onLayout }: {children: ReactNode; pointerEvents?: string; accessibilityElementsHidden?: boolean; ref: Ref<unknown>; style?: unknown; onLayout?: () => void;}) => {- useImperativeHandle(ref, () => ({ measureInWindow: (fn: (...args: number[]) => void) => fn(0, 0, state.width, state.height) }));+ useImperativeHandle(ref, () => ({+ measureInWindow: (fn: (...args: number[]) => void) => fn(0, 0, state.width, state.height),+ measureLayout: (_host: unknown, fn: (...args: number[]) => void) => fn(0, 0, state.width, state.height),+ }));useEffect(() => { onLayout?.(); }, [onLayout]);return <div data-input={pointerEvents} aria-hidden={accessibilityElementsHidden} data-layout={JSON.stringify(style)}>{children}</div>;},}));import { RecentMessageHistories, RecentMessageHistoriesProvider, MessageHistoryOverlay, useMessageHistoryActive, useMessageHistoryPositioning } from '@/session/RecentMessageHistories';+import { ResidentHomeList, ResidentHomeListProvider, useResidentHomeList } from '@/session/ResidentHomeList';import { recentTaskKey, rememberRecentTask } from '@/session/recentTasks';const key = (id: string) => recentTaskKey({ deviceId: 'pc', sessionId: id });const remember = (id: string) => rememberRecentTask({ pathname: '/sessions/[sessionId]', params: { deviceId: 'pc', deviceName: 'PC', sessionId: id } });@@ -50,6 +67,14 @@ describe('resident five-task message lists outside route lifetimes', () => {}, [id]);return <button data-task={id} data-active={active} data-positioning={positioning} onClick={() => setPosition(420)}>{text}:{position}</button>;}+ function DrawerHomeProbe() {+ const resident = useResidentHomeList();+ return <div data-drawer="true" data-resident-enabled={resident.enabled}>+ {resident.enabled ? <ResidentHomeList focused top={0} left={0} right={0}>+ <button data-drawer-task-list="true">Drawer tasks</button>+ </ResidentHomeList> : <button data-inline-task-list="true">Inline tasks</button>}+ </div>;+ }async function show(id: string | null, text = id ?? '', ready = true) {state.onTask = id !== null;await act(async () => {@@ -162,10 +187,35 @@ describe('resident five-task message lists outside route lifetimes', () => {const nodes = container.querySelectorAll('button');expect(nodes[0]?.dataset.task).toBe('a');expect(nodes[1]?.dataset.drawer).toBe('true');+ expect(nodes[1]?.closest('[data-layout]')?.getAttribute('data-layout')).toContain('"zIndex":40');await show(null);expect(container.querySelector('[data-drawer]')).toBeNull();expect(container.querySelector('[data-task="a"]')).not.toBeNull();});+ it('hosts route drawers after the outer resident task list on persistent layouts', async () => {+ remember('a');+ await act(async () => root.render(+ <RecentMessageHistoriesProvider>+ <ResidentHomeListProvider>+ <ResidentHomeList focused top={0} left={0} right={0}>+ <button data-resident-task-list="true">Tasks</button>+ </ResidentHomeList>+ <RecentMessageHistories activeKey={key('a')}>+ <History id="a" text="Messages" />+ </RecentMessageHistories>+ <MessageHistoryOverlay><DrawerHomeProbe /></MessageHistoryOverlay>+ </ResidentHomeListProvider>+ </RecentMessageHistoriesProvider>,+ ));+ const residentHost = container.querySelector('[data-resident-host="true"]')!;+ const drawer = container.querySelector('[data-drawer="true"]')!;+ expect(drawer.getAttribute('data-resident-enabled')).toBe('true');+ expect(container.querySelector('[data-inline-task-list="true"]')).toBeNull();+ expect(residentHost.querySelector('[data-drawer-task-list="true"]')).not.toBeNull();+ expect(residentHost.contains(drawer)).toBe(false);+ expect(residentHost.compareDocumentPosition(drawer) & Node.DOCUMENT_POSITION_FOLLOWING).not.toBe(0);+ expect(drawer.closest('[data-layout]')?.getAttribute('data-layout')).toContain('"zIndex":40');+ });it('does not keep the old route preloading mechanism alongside the resident host', () => {const home = readFileSync(resolve(process.cwd(), 'src/session/HomeSurface.tsx'), 'utf8');expect(home).not.toContain('useRecentTaskPreload');@@ -173,10 +223,17 @@ describe('resident five-task message lists outside route lifetimes', () => {const layout = readFileSync(resolve(process.cwd(), 'app/_layout.tsx'), 'utf8');// Source structure is independent of checkout line endings.for (const source of [layout.replace(/\r\n/g, '\n'), layout.replace(/\r?\n/g, '\r\n')]) {- const provider = source.indexOf('<RecentMessageHistoriesProvider>');+ const provider = source.search(/<RecentMessageHistoriesProvider(?:\s|>)/);+ const residentProvider = source.indexOf('<ResidentHomeListProvider>');const stack = source.search(/<Stack\s/);expect(provider).toBeGreaterThanOrEqual(0);+ expect(residentProvider).toBeGreaterThan(provider);expect(stack).toBeGreaterThan(provider);+ expect(stack).toBeGreaterThan(residentProvider);+ expect(source.indexOf('</ResidentHomeListProvider>')).toBeGreaterThan(stack);+ expect(source.indexOf('</RecentMessageHistoriesProvider>')).toBeGreaterThan(+ source.indexOf('</ResidentHomeListProvider>'),+ );}});it('clears all instances at an account boundary', async () => {diff --git a/apps/mobile/src/session/RecentMessageHistories.tsx b/apps/mobile/src/session/RecentMessageHistories.tsxindex c4a12ec6ee..c4bcb0eaa9 100644--- a/apps/mobile/src/session/RecentMessageHistories.tsx+++ b/apps/mobile/src/session/RecentMessageHistories.tsx@@ -5,6 +5,7 @@ import { NavigationContext, NavigationRouteContext, useIsFocused } from 'expo-roimport { PaneViewportProvider, usePaneViewport } from '@/platform/AdaptiveWindowContext';import { getRecentTasks, recentTaskKey, subscribeRecentTasks } from './recentTasks';import { NativeHistoryHost, NativeHistorySlot, needsResidentHistoryUpgrade } from './NativeResidentHistory';+import { useResidentHomeListContextBridge } from './ResidentHomeList';import { MessageHistoryActive, MessageHistoryPositioning } from './messageHistoryActivity';export { useMessageHistoryActive, useMessageHistoryPositioning } from './messageHistoryActivity';@@ -102,7 +103,7 @@ export function RecentMessageHistoriesProvider({ children }: { children: ReactNo</View>;})}{onTaskRoute ? [...overlays].map(([owner, content]) => <View key={owner}- pointerEvents="box-none" style={StyleSheet.absoluteFill}>{content}</View>) : null}+ pointerEvents="box-none" style={styles.overlay}>{content}</View>) : null}</View></Context.Provider>;}@@ -153,11 +154,18 @@ export function RecentMessageHistories({ activeKey, children, topInset = 0, bottpointerEvents={interactive && ready ? 'auto' : 'none'} style={StyleSheet.absoluteFill} /> : null}</View>;}-const styles = StyleSheet.create({ container: { flex: 1 }, clip: { position: 'absolute', overflow: 'hidden' } });+const styles = StyleSheet.create({+ container: { flex: 1 },+ clip: { position: 'absolute', overflow: 'hidden' },+ // Android confines a child's zIndex to its parent stacking context. Route+ // drawers therefore need their root host above resident histories/chrome too.+ overlay: { ...StyleSheet.absoluteFill, zIndex: 40 },+});/** Route-owned drawers must be above the root-owned histories, not beneath them. */export function MessageHistoryOverlay({ children }: { children: ReactNode }) {const context = useContext(Context);+ const residentChildren = useResidentHomeListContextBridge(children);if (!context) throw new Error('RecentMessageHistoriesProvider is missing');const { setOverlay } = context;const owner = useId();@@ -167,9 +175,9 @@ export function MessageHistoryOverlay({ children }: { children: ReactNode }) {useLayoutEffect(() => {if (NativeHistorySlot || needsResidentHistoryUpgrade) return;setOverlay(owner, focused ? <NavigationContext.Provider value={navigation}>- <NavigationRouteContext.Provider value={route}>{children}</NavigationRouteContext.Provider>+ <NavigationRouteContext.Provider value={route}>{residentChildren}</NavigationRouteContext.Provider></NavigationContext.Provider> : null);- }, [setOverlay, owner, focused, navigation, route, children]);+ }, [setOverlay, owner, focused, navigation, route, residentChildren]);useLayoutEffect(() => () => setOverlay(owner, null), [setOverlay, owner]);return NativeHistorySlot || needsResidentHistoryUpgrade ? children : null;}diff --git a/apps/mobile/src/session/ResidentHomeList.tsx b/apps/mobile/src/session/ResidentHomeList.tsxindex f4570ac58d..a3d86c2ea3 100644--- a/apps/mobile/src/session/ResidentHomeList.tsx+++ b/apps/mobile/src/session/ResidentHomeList.tsx@@ -23,6 +23,18 @@ export function useResidentHomeList() {return { enabled: context?.enabled ?? false, mounted: context?.mounted };}+/** Preserve the resident-list owner when route content is re-hosted above this+ * provider. React context follows the render destination, so an explicit bridge+ * is required for Android root overlays that otherwise fall back to an inline+ * Home list. */+export function useResidentHomeListContextBridge(children: ReactNode) {+ const context = useContext(Context);+ return useMemo(+ () => <Context.Provider value={context}>{children}</Context.Provider>,+ [children, context],+ );+}+/** The list lives above route lifetimes. Owners only supply its frame and props;* never key the host by route, session, or presentation width. */export function ResidentHomeListProvider({ children }: { children: ReactNode }) {