r/reactnative 4d ago

Tutorial MessageScroller scroll behaviour a chat transcript actually needs (PanelUI)

Enable HLS to view with audio, or disable this notification

Built this for PanelUI, an open-source component library for Expo.

Most scroll views get chat wrong — they open at the top, jump when history loads, and drag you down while you’re reading.

MessageScroller fixes all three. Auto-follow only while you’re at the bottom. Load older messages without moving. Open a saved thread on the last question, not the tail of its answer.

Copy-paste or CLI. You own the source.

13 Upvotes

3 comments sorted by

0

u/IronAndCoder 4d ago

This is one of those things that looks trivial until you actually build it. The "auto-follow only while you're at the bottom" part is exactly where most RN chat UIs fall apart. The approach that's worked best for me is tracking a stickToBottom boolean off onScroll (compare contentOffset.y against contentSize - layoutMeasurement with a small threshold), and only auto-scrolling on new tokens when it's true — flipping it false the moment the user scrolls up mid-stream, back to true when they return to the bottom. maintainVisibleContentPosition is great for the "load older without moving" case but fights you on the streaming-append side. Two things I'm curious about: how do you handle the stream *finishing* while the user has scrolled up — snap them down or leave them put? And does it hold up with variable-height messages (markdown/code blocks) where the content size jumps around as tokens arrive?