Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 安卓消息列表不再被 composer 手势桥拖出字符选中
Zhang Yunjin524bf19abf2d
diff --git a/apps/mobile/src/__tests__/composerPullThroughAttach.test.ts b/apps/mobile/src/__tests__/composerPullThroughAttach.test.tsnew file mode 100644index 0000000000..9a16494322--- /dev/null+++ b/apps/mobile/src/__tests__/composerPullThroughAttach.test.ts@@ -0,0 +1,53 @@+import { describe, expect, it, vi } from 'vitest';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';++vi.mock('react-native', () => ({+ Animated: { ScrollView: {} },+ Platform: { OS: 'android' },+}));+vi.mock('react-native-reanimated', () => ({+ measure: () => null,+ runOnJS: (fn: unknown) => fn,+ useAnimatedReaction: () => undefined,+ useAnimatedRef: () => ({ current: null }),+ useSharedValue: (initial: unknown) => ({ value: initial }),+}));+vi.mock('@/platform/gestureHandler', () => ({+ Gesture: {},+ GestureDetector: () => null,+}));++import { resolvePullThroughAttach } from '@/session/composerPullThrough';++// 回归锁:runOnJS 的返回值若被保存进变量再在 worklet 里调用,会序列化成不可直接+// 调用的 RemoteFunction 代理,UI 线程一调就报 Tried to synchronously call a Remote+// Function(Greptile P1)。必须保持 reaction 内联调用写法。+const composerPullThroughSource = readFileSync(+ resolve(process.cwd(), 'src/session/composerPullThrough.tsx'), 'utf8',+).replace(/\r\n/g, '\n');++expect(composerPullThroughSource).toContain('runOnJS(setAttach)(');+expect(composerPullThroughSource).not.toMatch(/=\s*runOnJS\(setAttach\)/);++describe('composer pull-through gesture attach gate', () => {+ it('android keeps RNGH off the message list while the composer is idle', () => {+ // RNGH 编排器接管触摸流会让 Android selectable 正文一拖就进选区、列表不滚。+ expect(resolvePullThroughAttach({ android: true, armed: false, busy: false })).toBe(false);+ });++ it('android attaches while the composer is expanded', () => {+ expect(resolvePullThroughAttach({ android: true, armed: true, busy: false })).toBe(true);+ });++ it('android stays attached while a handoff is in flight even after collapse', () => {+ // armed 会在拖动收起输入框时翻 false;busy 期间必须保持 enabled,+ // 否则 tracker 的 end() 不跑,被 setFrozen(true) 冻住的滚动无法恢复。+ expect(resolvePullThroughAttach({ android: true, armed: false, busy: true })).toBe(true);+ expect(resolvePullThroughAttach({ android: true, armed: true, busy: true })).toBe(true);+ });++ it('ios keeps the always-attached behavior unchanged', () => {+ expect(resolvePullThroughAttach({ android: false, armed: false, busy: false })).toBe(true);+ });+});diff --git a/apps/mobile/src/__tests__/composerPullThroughGateWiring.test.tsx b/apps/mobile/src/__tests__/composerPullThroughGateWiring.test.tsxnew file mode 100644index 0000000000..dddad0482c--- /dev/null+++ b/apps/mobile/src/__tests__/composerPullThroughGateWiring.test.tsx@@ -0,0 +1,122 @@+// @vitest-environment jsdom+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import type { ComposerPullThroughBridge } from '@/session/composerPullThrough';++// 门控接线测试:armed/busy 翻转 → reaction → setAttach → .enabled 的完整链路。+// 守护的不变量:接手进行中(busy)即使 armed 翻 false 也必须保持 enabled,+// 否则 tracker 的 end() 不跑,被 setFrozen(true) 冻住的列表滚动无法恢复。+const runtime = vi.hoisted(() => ({+ reactions: new Set<() => void>(),+ enabledLog: new Array<{ gesture: string; enabled: boolean }>(),+}));++vi.mock('react-native', () => ({+ Animated: { ScrollView: function AnimatedScrollView() { return null; } },+ Platform: { OS: 'android' },+}));++// 真 reanimated 的 reaction 在输入 shared value 每次被写时都跑 react worklet+// (不比较 mapper 返回值,见 lib/module/mappers.js),previous 靠第二参传入。+// mock 按同语义实现:每次 flush 都调 react,previous 为上次值(首次 undefined)。+vi.mock('react-native-reanimated', async () => {+ const { useRef } = await import('react');+ return {+ measure: () => null,+ runOnJS: (fn: unknown) => fn,+ useAnimatedReaction: (prepare: () => unknown, react: (value: unknown, previous: unknown) => void) => {+ const latest = useRef({ prepare, react, previous: undefined as unknown, started: false, job: null as (() => void) | null });+ latest.current.prepare = prepare;+ latest.current.react = react;+ if (!latest.current.job) {+ const state = latest.current;+ state.job = () => {+ const value = state.prepare();+ const previous = state.started ? state.previous : undefined;+ state.started = true;+ state.previous = value;+ state.react(value, previous);+ };+ runtime.reactions.add(state.job);+ }+ },+ useAnimatedRef: () => ({ current: null }),+ useSharedValue: (initial: unknown) => useRef({ value: initial }).current,+ };+});++vi.mock('@/platform/gestureHandler', () => {+ const makeGesture = (name: string) => {+ const gesture: Record<string, unknown> = {+ enabled(enabled: boolean) {+ runtime.enabledLog.push({ gesture: name, enabled });+ return gesture;+ },+ };+ for (const method of ['onTouchesDown', 'onTouchesMove', 'onTouchesUp', 'onTouchesCancelled', 'onFinalize']) {+ gesture[method] = () => gesture;+ }+ return gesture;+ };+ return {+ Gesture: {+ Manual: () => makeGesture('manual'),+ Native: () => makeGesture('native'),+ Simultaneous: (...gestures: unknown[]) => ({ gestures }),+ },+ GestureDetector: ({ children }: { children: React.ReactNode }) => children,+ };+});++import { ComposerPullThroughScrollView, useComposerPullThroughBridge } from '@/session/composerPullThrough';++Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });+let root: Root;+const bridgeRef: { current: ComposerPullThroughBridge | null } = { current: null };+const flushFrame = () => act(() => { for (const job of [...runtime.reactions]) job(); });+const enabledSequence = () => runtime.enabledLog.map(({ gesture, enabled }) => `${gesture}:${enabled ? 1 : 0}`);++beforeEach(() => {+ runtime.reactions.clear();+ runtime.enabledLog.length = 0;+ root = createRoot(document.createElement('div'));+});+afterEach(() => act(() => root.unmount()));++function Harness() {+ const bridge = useComposerPullThroughBridge();+ bridgeRef.current = bridge;+ return <ComposerPullThroughScrollView bridge={bridge} />;+}++describe('composer pull-through gesture gate wiring', () => {+ it('keeps the gesture enabled through a mid-handoff collapse and only releases it when the handoff settles', () => {+ act(() => root.render(<Harness />));+ // 初始(android idle):手势构造成 disabled。+ expect(enabledSequence()).toEqual(['manual:0', 'native:0']);+ // 首帧 reaction 同值:不触发重建。+ flushFrame();+ expect(enabledSequence()).toEqual(['manual:0', 'native:0']);++ // 展开卡片态:armed → enabled。+ act(() => { bridgeRef.current!.armed.value = true; });+ flushFrame();+ expect(enabledSequence()).toEqual(['manual:0', 'native:0', 'manual:1', 'native:1']);++ // 接手进行中收起输入框:armed 翻 false 但 busy=true,必须保持 enabled。+ act(() => {+ bridgeRef.current!.armed.value = false;+ bridgeRef.current!.event.value = { id: 1, active: true, startY: 800, y: 900, successful: false };+ });+ flushFrame();+ expect(enabledSequence()).toEqual(['manual:0', 'native:0', 'manual:1', 'native:1']);++ // 接手收尾(end() 已在同帧解冻滚动):busy 落 false 才允许摘除。+ act(() => {+ bridgeRef.current!.event.value = { id: 1, active: false, startY: 800, y: 900, successful: true };+ });+ flushFrame();+ expect(enabledSequence()).toEqual(['manual:0', 'native:0', 'manual:1', 'native:1', 'manual:0', 'native:0']);+ });+});diff --git a/apps/mobile/src/session/composerPullThrough.tsx b/apps/mobile/src/session/composerPullThrough.tsxindex c8b6271b4d..b2e9c2be24 100644--- a/apps/mobile/src/session/composerPullThrough.tsx+++ b/apps/mobile/src/session/composerPullThrough.tsx@@ -1,6 +1,6 @@-import { useCallback, useMemo, useRef, type Ref } from 'react';-import { Animated, type ScrollView, type ScrollViewProps, type View } from 'react-native';-import { measure, runOnJS, useAnimatedRef, useSharedValue, type AnimatedRef, type SharedValue } from 'react-native-reanimated';+import { useCallback, useMemo, useRef, useState, type Ref } from 'react';+import { Animated, Platform, type ScrollView, type ScrollViewProps, type View } from 'react-native';+import { measure, runOnJS, useAnimatedReaction, useAnimatedRef, useSharedValue, type AnimatedRef, type SharedValue } from 'react-native-reanimated';import { Gesture, GestureDetector } from '@/platform/gestureHandler';/**@@ -53,6 +53,16 @@ export function composerPullTranslation(input: { y: number; startY: number }): nreturn Math.max(0, input.y - input.startY);}+/**+ * 手势是否应挂在列表上。RNGH 编排器一旦接管列表触摸流,Android 上正文 selectable+ * 文本一拖就进选区、列表不滚(2026-10-16 模拟器 A/B 实测)。因此 Android 只在+ * 真正可能接手时挂手势;iOS 触摸管线没有这个问题,保持常挂(#5946 行为不变)。+ */+export function resolvePullThroughAttach(input: { android: boolean; armed: boolean; busy: boolean }): boolean {+ 'worklet';+ return !input.android || input.armed || input.busy;+}+const PHASE_IDLE = 0;const PHASE_TRACKING = 1;const PHASE_HANDED_OFF = 2;@@ -65,9 +75,16 @@ type PullThroughScrollViewProps = ScrollViewProps & {/*** 聊天记录列表的滚动容器(LegendList renderScrollComponent)。*- * 原生滚动照常进行:Native 手势只让列表加入 RNGH 编排;Manual 追踪手势永不激活,- * 只读触摸位置,不认领手势、不取消行内点击。接手时把列表滚动关掉(输入框接管这次拖动,- * 两边不同时动);抬手后恢复。追踪不依赖 Native 手势存活——关掉滚动会让原生滚动手势取消。+ * 原生滚动照常进行:Manual 追踪手势永不激活,只读触摸位置;接手时把列表滚动关掉+ * (输入框接管这次拖动,两边不同时动);抬手后恢复。追踪不依赖 Native 手势存活——+ * 关掉滚动会让原生滚动手势取消。+ *+ * 但 RNGH 编排器接管触摸流本身有代价:Android 上正文 selectable 文本一拖就进选区、+ * 列表不滚(2026-10-16 模拟器 A/B 实测,详见 PR)。所以手势只在接手窗口内启用:+ * Android 限展开卡片态(armed)或接手进行中(busy——armed 会在拖动收起输入框时翻+ * false,半途摘手势会让 frozen 滚动没机会被 end() 恢复);iOS 无此问题,保持常挂。+ * shortcut: armed 态下拖列表仍会触发 Android 选中问题,待 RNGH/上游修复后撤掉这层门;+ * 另外编排器只在起手(ACTION_DOWN)时认领手势,拖动中途 armed 才变 true 的那次拖动不会接手。*/export function ComposerPullThroughScrollView({ bridge, ref, ...props }: PullThroughScrollViewProps) {const scrollRef = useRef<ScrollView | null>(null);@@ -85,6 +102,23 @@ export function ComposerPullThroughScrollView({ bridge, ref, ...props }: PullThrconst phase = useSharedValue(PHASE_IDLE);const previousY = useSharedValue(0);const composerTop = useSharedValue(0);+ const android = Platform.OS === 'android';+ // bridge.armed(展开卡片态)与 event.active(接手进行中)是 UI 线程真相;镜像成+ // 「手势是否启用」的 JS 态。reaction 的输入在接手期间每帧都被写,react 里必须用+ // previous 挡掉同值,否则每帧都跨线程回 JS。runOnJS(setAttach) 必须内联调用:+ // 它的返回值若存进变量再被 worklet 捕获,会序列化成不可直接调用的 RemoteFunction+ // 代理,UI 线程一调就报 Tried to synchronously call a Remote Function。+ const [attach, setAttach] = useState(+ resolvePullThroughAttach({ android, armed: bridge.armed.value === true, busy: bridge.event.value.active === true }),+ );+ useAnimatedReaction(+ () => ({ armed: bridge.armed.value === true, busy: bridge.event.value.active === true }),+ (next, previous) => {+ if (previous && next.armed === previous.armed && next.busy === previous.busy) return;+ runOnJS(setAttach)(resolvePullThroughAttach({ android, armed: next.armed, busy: next.busy }));+ },+ [bridge, android],+ );const gesture = useMemo(() => {const { armed, event, grabberRef } = bridge;const end = (y: number, successful: boolean) => {@@ -100,6 +134,7 @@ export function ComposerPullThroughScrollView({ bridge, ref, ...props }: PullThr// interactive-pop recognizer waits for that pending pan, so even an unarmed// composer blocks edge-back. Manual observes touches without a competing pan.const tracker = Gesture.Manual()+ .enabled(attach).onTouchesDown((touches) => {'worklet';phase.value = PHASE_IDLE;@@ -145,8 +180,8 @@ export function ComposerPullThroughScrollView({ bridge, ref, ...props }: PullThr// 被其它手势挤掉时不会再收到抬手:按取消收尾,输入框回到原高度。end(NaN, false);});- return Gesture.Simultaneous(Gesture.Native(), tracker);- }, [bridge, composerTop, phase, previousY, setFrozen]);+ return Gesture.Simultaneous(Gesture.Native().enabled(attach), tracker);+ }, [attach, android, bridge, composerTop, phase, previousY, setFrozen]);return (<GestureDetector gesture={gesture}>