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): preserve resident list ownership and interrupt drawer rebound

DavidShen171cc7df9334
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 79a70a5448..21ad3b4de0 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -10761,8 +10761,9 @@ function SessionScreenContent() {
onDismiss={dismissTransientNotice}
top={Math.max(topOverlayHeight, insets.top + 44) + spacing.sm}
/>
- <MessageHistoryOverlay>
- {/* Keep the drawer above resident histories, including its closing animation. */}
+ <MessageHistoryOverlay enabled={!paneLayout.persistent || sessionListDrawerOverlayMounted}>
+ {/* The persistent panel stays below the shared resident list. Only modal
+ drawers cover resident histories, including their closing animation. */}
<SessionListDrawer
newSessionActionRef={homeNewSessionActionRef}
newSessionInSystemBar={paneLayout.persistent && Platform.OS === 'ios' && adaptiveWindow.barEdge !== 'none'}
diff --git a/apps/mobile/src/__tests__/recentMessageHistories.test.tsx b/apps/mobile/src/__tests__/recentMessageHistories.test.tsx
index 4042ff97a4..e5bc56b3af 100644
--- a/apps/mobile/src/__tests__/recentMessageHistories.test.tsx
+++ b/apps/mobile/src/__tests__/recentMessageHistories.test.tsx
@@ -46,7 +46,7 @@ vi.mock('react-native', () => ({
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>;
},
@@ -216,7 +216,7 @@ describe('resident five-task message lists outside route lifetimes', () => {
const clip = history.closest<HTMLElement>('[data-layout*="zIndex"]');
expect(clip?.dataset.layout).toContain('"zIndex":1');
});
- it('hosts route drawers after the outer resident task list on persistent layouts', async () => {
+ it('hosts modal drawers after the outer resident task list', async () => {
remember('a');
await act(async () => root.render(
<RecentMessageHistoriesProvider>
@@ -240,6 +240,49 @@ describe('resident five-task message lists outside route lifetimes', () => {
expect(residentHost.compareDocumentPosition(drawer) & Node.DOCUMENT_POSITION_FOLLOWING).not.toBe(0);
expect(drawer.closest('[data-layout]')?.getAttribute('data-layout')).toContain('"zIndex":40');
});
+ it('keeps one scrolled list above the persistent panel through home, task switches and back', async () => {
+ let mounts = 0;
+ const List = ({ task }: { task: string }) => {
+ const [offset, setOffset] = useState(0);
+ useEffect(() => { mounts++; }, []);
+ return <button data-shared-list onClick={() => setOffset(240)}>{task}:{offset}</button>;
+ };
+ const Scene = ({ task }: { task: string }) => <RecentMessageHistoriesProvider>
+ <ResidentHomeListProvider>
+ {task === 'home' ? <ResidentHomeList focused top={0} left={0} right={0}>
+ <List task={task} />
+ </ResidentHomeList> : <MessageHistoryOverlay enabled={false}>
+ <div data-panel>
+ <span data-panel-title>Tasks</span>
+ <ResidentHomeList focused top={0} left={0} right={0}><List task={task} /></ResidentHomeList>
+ </div>
+ </MessageHistoryOverlay>}
+ </ResidentHomeListProvider>
+ </RecentMessageHistoriesProvider>;
+ state.onTask = false;
+ await act(async () => root.render(<Scene task="home" />));
+ const list = container.querySelector('[data-shared-list]') as HTMLButtonElement;
+ await act(async () => list.click());
+ for (const task of ['a', 'b', 'home']) {
+ state.onTask = task !== 'home';
+ await act(async () => root.render(<Scene task={task} />));
+ expect(container.querySelectorAll('[data-shared-list]')).toHaveLength(1);
+ expect(container.querySelector('[data-shared-list]')).toBe(list);
+ expect(list.textContent).toBe(task + ':240');
+ expect(mounts).toBe(1);
+ if (state.onTask) {
+ const title = container.querySelector('[data-panel-title]')!;
+ const host = list.closest('[data-resident-host]')!;
+ expect(title.compareDocumentPosition(host) & Node.DOCUMENT_POSITION_FOLLOWING).not.toBe(0);
+ expect(title.closest('[data-layout*="zIndex"]')).toBeNull();
+ }
+ }
+ const home = readFileSync(resolve(process.cwd(), 'src/session/HomeSurface.tsx'), 'utf8');
+ expect(home).toContain('{residentList.enabled ? (');
+ expect(home).not.toContain('residentList.enabled && !embedded');
+ const route = readFileSync(resolve(process.cwd(), 'app/sessions/[sessionId].tsx'), 'utf8');
+ expect(route).toContain('<MessageHistoryOverlay enabled={!paneLayout.persistent || sessionListDrawerOverlayMounted}>');
+ });
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');
diff --git a/apps/mobile/src/__tests__/sessionListDrawerUpdates.test.tsx b/apps/mobile/src/__tests__/sessionListDrawerUpdates.test.tsx
index 814cd7a20f..983a6a1254 100644
--- a/apps/mobile/src/__tests__/sessionListDrawerUpdates.test.tsx
+++ b/apps/mobile/src/__tests__/sessionListDrawerUpdates.test.tsx
@@ -8,7 +8,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { SessionListDrawer } from '@/session/SessionListDrawer';
import { motionDuration } from '@/theme/tokens';
import type { MobileHomeProps } from '@/session/HomeSurface';
-const native = vi.hoisted(() => ({ home: null as MobileHomeProps | null, mounts: 0, unmounts: 0, reduceMotion: true }));
+const native = vi.hoisted(() => ({ home: null as MobileHomeProps | null, mounts: 0, unmounts: 0, reduceMotion: true,
+ values: [] as { value: number }[], gesture: {} as Record<string, (event?: any) => void>, cancel: vi.fn() }));
vi.mock('@/session/HomeSurface', async () => {
const { useEffect } = await import('react');
return { MobileHome: (props: MobileHomeProps) => {
@@ -72,10 +73,14 @@ vi.mock("react-native-reanimated", async () => {
const { View } = await import("react-native");
return {
default: { View },
- useSharedValue: (value: number) => useRef({ value }).current,
+ useSharedValue: (value: number) => {
+ const ref = useRef({ value });
+ if (!native.values.includes(ref.current)) native.values.push(ref.current);
+ return ref.current;
+ },
useAnimatedStyle: () => ({}),
Easing: { bezier: () => undefined },
- cancelAnimation() {},
+ cancelAnimation: native.cancel,
runOnJS: (fn: unknown) => fn,
withRepeat: (value: number) => value,
withTiming: (value: number) => value,
@@ -90,8 +95,9 @@ vi.mock("@/platform/gestureHandler", () => ({
activeOffsetX: () => chain,
failOffsetX: () => chain,
failOffsetY: () => chain,
- onUpdate: () => chain,
- onEnd: () => chain,
+ onStart: (callback: () => void) => { native.gesture.start = callback; return chain; },
+ onUpdate: (callback: (event: any) => void) => { native.gesture.update = callback; return chain; },
+ onEnd: (callback: (event: any) => void) => { native.gesture.end = callback; return chain; },
};
return chain;
},
@@ -125,12 +131,40 @@ describe('shared Home drawer host', () => {
beforeEach(() => {
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
native.home = null; native.mounts = 0; native.unmounts = 0;
+ native.values = []; native.gesture = {};
native.reduceMotion = true;
vi.clearAllMocks();
vi.useFakeTimers();
container = document.createElement('div'); document.body.appendChild(container); root = createRoot(container);
});
afterEach(async () => { await act(async () => root.unmount()); container.remove(); vi.useRealTimers(); });
+ it('takes over an unfinished rebound on horizontal activation and still closes a full left swipe', async () => {
+ native.reduceMotion = false;
+ await act(async () => root.render(<SessionListDrawer {...props} />));
+ const [progress, dragX] = native.values;
+ native.gesture.start!();
+ native.gesture.update!({ translationX: -40 });
+ native.gesture.end!({ translationX: -40, velocityX: 0 });
+ expect(props.onClose).not.toHaveBeenCalled();
+ expect(dragX!.value).toBe(0);
+ // The UI thread is halfway through that return when a second pan activates.
+ progress!.value = 0.9;
+ native.cancel.mockClear();
+ native.gesture.start!();
+ expect(native.cancel).toHaveBeenCalledWith(progress);
+ expect(native.cancel).toHaveBeenCalledWith(dragX);
+ expect(progress!.value).toBe(0.9);
+ native.gesture.update!({ translationX: -24 });
+ expect((progress!.value - 1) * props.width + dragX!.value).toBeCloseTo(-56);
+ native.gesture.end!({ translationX: -24, velocityX: 0 });
+ expect(progress!.value).toBe(1);
+ expect(dragX!.value).toBe(0);
+ expect(props.onClose).not.toHaveBeenCalled();
+ native.gesture.start!();
+ native.gesture.update!({ translationX: -160 });
+ native.gesture.end!({ translationX: -160, velocityX: 0 });
+ expect(props.onClose).toHaveBeenCalledOnce();
+ });
it('unmounts the invisible blocker even when the animation never calls completion', async () => {
native.reduceMotion = false;
await act(async () => root.render(<SessionListDrawer {...props} />));
diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsx
index 826ec51f05..a1e8558067 100644
--- a/apps/mobile/src/session/HomeSurface.tsx
+++ b/apps/mobile/src/session/HomeSurface.tsx
@@ -3265,7 +3265,7 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
) : null}
</View>
- {residentList.enabled && !embedded ? (
+ {residentList.enabled ? (
<ResidentHomeList focused={screenFocused && active} top={chromeHeight}
left={embedded ? 0 : edgePadding.paddingLeft} right={embedded ? 0 : edgePadding.paddingRight}>
<ActiveHomeSession.Provider value={activeHomeSession}>
diff --git a/apps/mobile/src/session/RecentMessageHistories.tsx b/apps/mobile/src/session/RecentMessageHistories.tsx
index 6b7c3d2dec..60cd932a07 100644
--- a/apps/mobile/src/session/RecentMessageHistories.tsx
+++ b/apps/mobile/src/session/RecentMessageHistories.tsx
@@ -174,7 +174,7 @@ const styles = StyleSheet.create({
});
/** Route-owned drawers must be above the root-owned histories, not beneath them. */
-export function MessageHistoryOverlay({ children }: { children: ReactNode }) {
+export function MessageHistoryOverlay({ children, enabled = true }: { children: ReactNode; enabled?: boolean }) {
const context = useContext(Context);
const residentChildren = useResidentHomeListContextBridge(children);
if (!context) throw new Error('RecentMessageHistoriesProvider is missing');
@@ -185,10 +185,10 @@ export function MessageHistoryOverlay({ children }: { children: ReactNode }) {
const route = useContext(NavigationRouteContext);
useLayoutEffect(() => {
if (NativeHistorySlot || needsResidentHistoryUpgrade) return;
- setOverlay(owner, focused ? <NavigationContext.Provider value={navigation}>
+ setOverlay(owner, enabled && focused ? <NavigationContext.Provider value={navigation}>
<NavigationRouteContext.Provider value={route}>{residentChildren}</NavigationRouteContext.Provider>
</NavigationContext.Provider> : null);
- }, [setOverlay, owner, focused, navigation, route, residentChildren]);
+ }, [setOverlay, owner, enabled, focused, navigation, route, residentChildren]);
useLayoutEffect(() => () => setOverlay(owner, null), [setOverlay, owner]);
- return NativeHistorySlot || needsResidentHistoryUpgrade ? children : null;
+ return !enabled || NativeHistorySlot || needsResidentHistoryUpgrade ? children : null;
}
diff --git a/apps/mobile/src/session/SessionListDrawer.tsx b/apps/mobile/src/session/SessionListDrawer.tsx
index 0f9eb5408e..17735497ff 100644
--- a/apps/mobile/src/session/SessionListDrawer.tsx
+++ b/apps/mobile/src/session/SessionListDrawer.tsx
@@ -140,6 +140,13 @@ export function SessionListDrawer({ currentSessionId, persistent = false, newSes
.activeOffsetX(-16)
.failOffsetX(16)
.failOffsetY([-16, 16])
+ .onStart(() => {
+ 'worklet';
+ // A new horizontal drag takes over from the current rebound position.
+ // Do not stop it on touch-down: vertical scrolling must leave it running.
+ cancelAnimation(progress);
+ cancelAnimation(dragX);
+ })
.onUpdate((event) => {
'worklet';
dragX.value = Math.min(0, event.translationX);
@@ -164,7 +171,7 @@ export function SessionListDrawer({ currentSessionId, persistent = false, newSes
});
}
}),
- [closeFromGesture, dragX, panelWidth, persistent],
+ [closeFromGesture, dragX, panelWidth, persistent, progress],
);
const scrimStyle = useAnimatedStyle(() => ({