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): 消息列表停在距底几行处松手不再被拽到最新 (#5795)

Dash5eaa958b9faa
diff --git a/apps/mobile/src/__tests__/messageScroll.test.ts b/apps/mobile/src/__tests__/messageScroll.test.ts
index 0ff81a39a9..eaf8ffb959 100644
--- a/apps/mobile/src/__tests__/messageScroll.test.ts
+++ b/apps/mobile/src/__tests__/messageScroll.test.ts
@@ -37,6 +37,7 @@ import {
mobileMessageListTopPadding,
mobileTopPaddingCompensationOffset,
MOBILE_FOLLOW_REPIN_DIRECTION_DEAD_ZONE,
+ MOBILE_FOLLOW_REPIN_END_TOLERANCE,
MOBILE_FOLLOW_UNPIN_DRAG_DEAD_ZONE,
MOBILE_MVCP_SETTLE_QUIET_MS,
resolveMobileNearBottomOnScroll,
@@ -425,7 +426,7 @@ describe('shouldUnpinMobileFollowOnDrag', () => {
describe('resolveMobileNearBottomOnScroll', () => {
// 阈值:96 + 132(无浮层)= 228。内容 2000,视口 800 → end offset 1200,
- // 阈值带 = offsetY > 972。
+ // 阈值带 = offsetY > 972(只用于判定「保持跟随」;恢复跟随要求距末端 ≤ 容差)。
const metricsAt = (offsetY: number) => ({ contentHeight: 2000, offsetY, viewportHeight: 800 });
it('距底超出阈值 + 明确上滑 / 已解除 → false(原有离底解除行为不变)', () => {
@@ -470,10 +471,31 @@ describe('resolveMobileNearBottomOnScroll', () => {
})).toBe(false);
});
- it('阈值带内 + 已解除 + 明确向下 → 恢复跟随', () => {
+ it('已解除 + 明确向下 + 真正到底 → 恢复跟随', () => {
expect(resolveMobileNearBottomOnScroll({
- wasNearBottom: false, metrics: metricsAt(1100), scrollDelta: 2,
+ wasNearBottom: false, metrics: metricsAt(1200), scrollDelta: 2,
})).toBe(true);
+ expect(resolveMobileNearBottomOnScroll({
+ wasNearBottom: false, metrics: metricsAt(1200 - MOBILE_FOLLOW_REPIN_END_TOLERANCE), scrollDelta: 2,
+ })).toBe(true);
+ // iOS 回弹越过末端同样算到底。
+ expect(resolveMobileNearBottomOnScroll({
+ wasNearBottom: false, metrics: metricsAt(1240), scrollDelta: 6,
+ })).toBe(true);
+ });
+
+ it('已解除 + 停在距底几行处的向下微调/抬手位移 → 保持解除(不在近底阈值带内恢复)', () => {
+ // 距末端约三行(~70px):仍在 228px 近底阈值带内,但不是「回到底部」。
+ expect(resolveMobileNearBottomOnScroll({
+ wasNearBottom: false, metrics: metricsAt(1130), scrollDelta: 3,
+ })).toBe(false);
+ expect(resolveMobileNearBottomOnScroll({
+ wasNearBottom: false, metrics: metricsAt(1200 - MOBILE_FOLLOW_REPIN_END_TOLERANCE - 1), scrollDelta: 2,
+ })).toBe(false);
+ // 恢复的距离口径与底部浮层高度无关:留白已计入 contentHeight。
+ expect(resolveMobileNearBottomOnScroll({
+ wasNearBottom: false, metrics: metricsAt(1000), scrollDelta: 3, bottomOverlayHeight: 400,
+ })).toBe(false);
});
it('bottomOverlayHeight 放大阈值(与 isNearMobileMessageListBottom 同口径)', () => {
diff --git a/apps/mobile/src/session/messageScroll.ts b/apps/mobile/src/session/messageScroll.ts
index 030190823a..67a63c2f49 100644
--- a/apps/mobile/src/session/messageScroll.ts
+++ b/apps/mobile/src/session/messageScroll.ts
@@ -64,8 +64,11 @@ export function mobileMessageListEndOffset(metrics: MessageScrollMetrics): numbe
// 距底仍在阈值带内 → 仍被判「近底」→ 下一帧内容增长又被拽回最底。触摸惯性
// 大多一次就滑出阈值,所以比桌面版难触发,但结构性竞态相同。
// 修复:「解除」看手势意图(拖动中向上位移超过死区,只有用户能产生),
-// 「恢复」保留距离判定但要求 scroll 方向明确向下——否则解除后紧跟着的上滑
-// scroll 事件(距底仍在阈值带内)会把刚解除的跟随立刻翻回去。
+// 「恢复」要求 scroll 方向明确向下——否则解除后紧跟着的上滑 scroll 事件
+// (距底仍在阈值带内)会把刚解除的跟随立刻翻回去。
+// 恢复的距离只认「真正到底」(MOBILE_FOLLOW_REPIN_END_TOLERANCE),不用 228px
+// 的近底阈值带:停在距底两三行时,手指微调或抬手那一下常有几 px 的向下位移,
+// 会被当成「滑回底部」恢复跟随,松手后的落底校验随即把列表拽到最新。
/**
* 拖动解除跟随的累计位移死区(px)。手指按住不动也有 ±2-3px 抖动,取 8px
@@ -80,6 +83,13 @@ export const MOBILE_FOLLOW_UNPIN_DRAG_DEAD_ZONE = 8;
*/
export const MOBILE_FOLLOW_REPIN_DIRECTION_DEAD_ZONE = 1;
+/**
+ * 已解除跟随时,恢复跟随允许的距底容差(px,相对内容末端 offset)。底部留白
+ * 已计入 contentHeight,到达末端即最后一条消息完整露出;容差约一行字,
+ * 吸收亚像素与回弹误差,但停在距底两三行处不会被判为「回到底部」。
+ */
+export const MOBILE_FOLLOW_REPIN_END_TOLERANCE = 24;
+
/** 容器「真的可滚」的最小内容富余(px),亚像素圆整内视为不可滚。 */
const MOBILE_FOLLOW_MIN_SCROLLABLE_PX = 1;
@@ -136,20 +146,21 @@ export interface MobileNearBottomResolveInput {
* assistant / 工具卡撑高不得把跟随掐死;
* - 阈值带内且原本在跟 → 保持 true(贴底期间程序化 scrollToEnd 产生的
* 向下增量、以及被动微小位移都不改变状态);
- * - 阈值带内且已解除 → 仅「明确向下」(增量 > 死区)才恢复跟随。**不能只看
- * 距离**:拖动解除后同一手势内继续到达的上滑 scroll 事件距底仍在阈值带内,
- * 无方向守卫会立即翻回跟随,解除失效(修复核心)。
+ * - 已解除 → 仅「明确向下」(增量 > 死区)且真正到底(距末端 ≤
+ * MOBILE_FOLLOW_REPIN_END_TOLERANCE)才恢复跟随。**不能只看距离**:拖动解除后
+ * 同一手势内继续到达的上滑 scroll 事件仍可能贴近末端,无方向守卫会立即翻回
+ * 跟随;**也不能用近底阈值带**:停在距底几行处的手指微调/抬手位移会误恢复。
*/
export function resolveMobileNearBottomOnScroll(input: MobileNearBottomResolveInput): boolean {
if (input.programmaticScrollInFlight) return input.wasNearBottom;
- const { contentHeight, viewportHeight } = input.metrics;
+ const { contentHeight, offsetY, viewportHeight } = input.metrics;
if (contentHeight <= viewportHeight) return true;
- if (!isNearMobileMessageListBottom(input.metrics, input.bottomOverlayHeight)) {
- if (!input.wasNearBottom) return false;
- return input.scrollDelta >= -MOBILE_FOLLOW_REPIN_DIRECTION_DEAD_ZONE;
+ if (!input.wasNearBottom) {
+ return input.scrollDelta > MOBILE_FOLLOW_REPIN_DIRECTION_DEAD_ZONE
+ && mobileMessageListEndOffset(input.metrics) - offsetY <= MOBILE_FOLLOW_REPIN_END_TOLERANCE;
}
- if (input.wasNearBottom) return true;
- return input.scrollDelta > MOBILE_FOLLOW_REPIN_DIRECTION_DEAD_ZONE;
+ if (isNearMobileMessageListBottom(input.metrics, input.bottomOverlayHeight)) return true;
+ return input.scrollDelta >= -MOBILE_FOLLOW_REPIN_DIRECTION_DEAD_ZONE;
}
export interface MobileHistoryBrowseIntentInput {