Skip to content

feat(mobile): jump between questions in the chat transcript - #811

Merged
huichen merged 3 commits into
mainfrom
feat/question-nav
Sep 24, 2026
Merged

huichen merged 3 commits into
mainfrom
feat/question-nav

Conversation

@huichen

@huichen huichen commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

问题

长回答会把它的提问顶出屏幕。流式输出结束后想回到"本轮提问的开头",要往上滑很长时间;而聊天的所有滚动手段都是单向的(只能回最新,不能按"提问"跳)。

做法

视口离开最新之后,聊天右缘出现一组圆钮(采纳样式表中的 A 形态):

  • ↑ 上一个提问 —— 离视口顶边最近、往上的那个提问起点,也就是正在读的这一轮的提问,正是"翻回本问题开头"要落的地方;
  • ↓ 下一个提问 —— 离视口顶边最近、往下的那个提问起点。

两枚 44×44(layout.touchTarget)圆形按钮,间距 8px,右缘距屏幕边 16px(layout.gutter),底边离输入框 16px;不压输入框、不压发送键、不压消息列。没有目标的方向置灰但不消失,所以另一个钮不会因为状态变化在拇指底下移动。

定位与对齐

  • 方向键是一把梯子:落点那一行不会再成为下一次的目标,所以每按一次只走一个提问,↑/↓ 严格互为逆操作(有一条测试专门走完整个梯子再走回来)。
  • 落点对齐在列表顶边下 12px,和列表自身行间距同一个数;提问在第一行,回答从下面接着排。跳转是直接切过去(不做长距离动画),落点那行加一层淡蓝底亮 1.4 秒,否则换一屏后找不到落点。
  • 倒序列表有个反直觉处(已写进注释并有测试钉住):单元格把行间距排在行上方(column-reverse),所以 viewPosition: 1 对齐单元格后 viewOffset 是"间距 − 目标内缩",不是内缩本身。
  • 锚点来自列表自己上报的可见行(部分可见 + 完全可见两个 viewability 配置),而不是行 onLayout 的 y——那个坐标是相对虚拟化单元格的,拿不到全篇位置。
  • "正在读历史"取两个来源的并集:原生拖拽信号(useChatScroll 已有)+ 实测滚动偏移。web 侧永远不上报拖拽(react-native-web 没有 onScrollBeginDrag 的等价物),原生侧拖拽时还没有偏移。
  • 目标行在测量窗口外时,先用平均行高估个位置把它渲染出来,再对刚测到的真实框重新跳一次;尝试次数有上限,不会死循环。

改动

产品代码:questionNav.ts(纯逻辑:提问索引、梯子、落点)、useQuestionNav.ts(锚点/跳转/落点高亮)、QuestionNavControl.tsx(A 形态控件)、ChatScreen.tsx 接线、i18n 两个 key、两个测试文件(16 + 7 条)。

截图工装:?multiTurn=1 加了一段多轮演示对话(原来只有一轮,没有可跳的东西),两个场景覆盖行为与对齐:

  • qn-jump-states:滚动后 / 按 ↑ 后 / 按 ↓ 后三格,并用 aria-disabled 读数断言每格的可用性;
  • qn-align-check:把对齐写成可失败的数值断言(落点行距列表顶边 12px ±2,且必须落在预期那个提问上)。

验证

  • npx tsc --noEmit、npx eslint .、移动端 jest 全量:1893 passed / 125 suites(在 merge 了 origin/main 的树上跑的)。
  • qn-align-check 实测 {"inset":12,"question":"把 Dreher"};该场景的 eval 断言失败会让截图非零退出(不是"点了没反应"式假通过)。
  • 只改了 mobile/ 与 scripts/screenshots/,未触碰 Rust/desktop。

范围与已知项

  • 不含"把回到最新并进这组圆钮"的方案(已决定不做),因此输入框上方那枚胶囊保持原样。
  • 未验证真机拖拽路径(harness 是 web,抓不到 onScrollBeginDrag);该路径靠 useChatScroll 现有行为 + 平移量兜底。

A long answer pushes its question out of reach, so reading back to the start of
the turn you are in meant a long scroll. Once the viewport leaves the tail, the
chat now shows a stack of two round buttons on the right edge — ↑ to the closest
question start above the reading position, ↓ to the closest below. The landed
question sits 12px under the list's top edge and is marked for a moment so the
eye can find what moved. The shape is option A of the four on the style sheet
(44px circles, the platform's minimum touch target, clear of the composer and of
the reading column).

The two directions are one ladder, so each press moves exactly one question and
the landed question is never its own target again. The anchor is derived from
what the list reports as viewable (partly and fully visible rows) rather than
from row geometry, because a row's `onLayout` `y` is relative to its own
virtualized cell. Reading state is the union of the native drag signal owned by
`useChatScroll` and the measured offset: a web build never reports a drag, and a
native build reports a drag before any offset exists.

The jump is exact rather than approximate: `viewPosition: 1` aligns the target's
cell, and an inverted cell lays the list's own row gap out above its row, so the
delivered inset is that gap plus the passed offset. A row outside the measured
window falls back to an average-height estimate and is re-issued once it has been
rendered.

Harness: `?multiTurn=1` adds a several-turn demo conversation (there was nothing
to jump between with one exchange), and three scenarios cover the shape
(`qn-nav-variants`, with the two still-open additions as proposal panels), the
states after each press (`qn-jump-states`) and the alignment as a numeric
assertion (`qn-align-check`: 12px ±2, plus which question the jump must land on).
@huichen
huichen enabled auto-merge (squash) September 24, 2026 02:12
@huichen huichen closed this Sep 24, 2026
auto-merge was automatically disabled September 24, 2026 02:14

Pull request was closed

@huichen huichen reopened this Sep 24, 2026
@huichen
huichen enabled auto-merge (squash) September 24, 2026 02:14
@huichen
huichen merged commit e1521f1 into main Sep 24, 2026
12 checks passed
@huichen
huichen deleted the feat/question-nav branch September 24, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant