Skip to content

fix(chat): keep the scroll position when a message arrives while reading older ones - #381

Open
alexxg20 wants to merge 8 commits into
mainfrom
fix/conversation-scroll-position
Open

alexxg20 wants to merge 8 commits into
mainfrom
fix/conversation-scroll-position

Conversation

@alexxg20

@alexxg20 alexxg20 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #320. The conversation now follows a new message only while the user is at the end of the conversation. If they have scrolled up, the list stays where it is and a "New message" hint takes them down when tapped. The user's own messages and photos still scroll down.

What

  • messageListChange (next to conversationBody) classifies each change in the list:
    • Follow: the first load, a photo the user starts sending, or the user's own new message.
    • Their message arrived: MessageList follows it if the previous bottom item's bottom edge was on screen; otherwise it keeps its place and shows the hint.
    • Nothing: a photo finishing its upload (its message takes the place of its bubble), a deleted newest message, a failure, a retry or a discard.
  • "Was on screen" is checked by the previous bottom item's key, so the answer is the same whether or not the list has laid out the new message yet. Checking the bottom edge means someone reading the start of a long message is not pulled down.
  • The list follows with requestScrollToItem(0), which takes no scroll lock, so a finger already on the list cannot cancel it.
  • The hint is a small pill over the bottom of the list. Tapping it animates down. It goes away once the newest message, or a photo being sent under it, is in view. It is a polite live region, so TalkBack announces it.
  • The hint and what the list last showed are saved like the list's position. After a rotation the user keeps their reading position; before, the list jumped to the newest message.
  • No ViewModel change: scroll position is view state.

Why

Every new message scrolled the list to the bottom, so a user reading older messages lost their place each time the other person wrote. The photo messages from #373 and #374 had the same problem, plus a jump whenever an upload finished.

Validation

  • ./gradlew ktfmtCheck: passed.
  • ./gradlew check: passed (unit tests, lint).
  • MessageListChangeTest covers each kind of change. Robolectric tests in ConversationScreenTest cover: following at the end, keeping the place with the hint, the hint going away, the user's own messages and photos, uploads finishing, deletions, a drag in progress, a long newest message, and recreation. Each rule was checked to fail its tests when broken.
  • Not checked with TalkBack on a device.

Follow-ups

AI use

Claude Code (Claude Opus 5.5) drafted the plan, implemented it with its tests, resolved the merge with the photo messages, and ran adversarial reviews. The reviews found that a drag cancelled the scroll, that a long newest message pulled the reader down, and that photo uploads and deletions still moved the list; all are fixed and covered by tests.

🤖 Generated with Claude Code

… reading older ones

Follow a new message only on the first load, for the user's own message, or while the previous newest one's bottom edge is on screen. Otherwise keep the place and show a "New message" hint that scrolls down when tapped.
@alexxg20
alexxg20 marked this pull request as ready for review November 18, 2026 16:46
Mamel0uk
Mamel0uk previously approved these changes Nov 18, 2026

@Mamel0uk Mamel0uk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, could you open an issue for the two nitpicks below?

Comment thread app/src/main/res/values/strings.xml Resolved
Photos the user is sending count as their own messages and are followed; the hint and the bottom-edge rule now use the list's bottom item, a pending photo or the newest message.
…st message goes away

A photo's message that was pending takes the place of its bubble, and a deleted newest message is not an arrival, so neither scrolls the list nor shows the hint. The hint clears once the newest message or a photo under it is in view.
@alexxg20
alexxg20 requested a review from Mamel0uk November 19, 2026 03:24

@Mamel0uk Mamel0uk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice move pulling the decision into messageListChange, every case is easy to read and test now. One question and one nitpick below.

The hint goes once the newest message or a photo being sent under it is on screen, looked up by key, so it holds whether or not the new message has been laid out when the hint is set.
@alexxg20
alexxg20 requested a review from Mamel0uk November 19, 2026 19:13

@peng-0110 peng-0110 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud

Copy link
Copy Markdown

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.

Keep the conversation's scroll position when a message arrives while reading older ones

3 participants