Skip to main content

follow

Function follow 

Source
pub fn follow(handle: &ScrollHandle, state: &FollowState) -> AnyElement
Expand description

Keep handle pinned to the bottom of its content while the user leaves it there, and get out of the way the moment they scroll up.

Drop it in beside scrollbar, over the same container:

div().relative()
    .child(div().id("log").size_full().overflow_y_scroll().track_scroll(&self.scroll).child(rows))
    .child(scroll::follow(&self.scroll, &self.follow))
    .child(scroll::scrollbar("log-bar", &self.scroll, &self.bar))

Telling appended content from a user scroll is the whole problem, and neither is an event this can subscribe to — both surface as the same handle reading differently than last frame. The overflow is what separates them: if it changed, the content grew and the pin is left as the user last set it; if it did not, the offset moved because the user moved it, and being at the end is what re-pins. So scrolling up releases, and scrolling back down re-attaches, with no gesture to hook.

The correction lands a frame late — the scrolling div was laid out with the old offset before this runs — which is why it asks for that frame. At a streaming cadence it is invisible, and it converges rather than spinning: once pinned and at the end, nothing is requested.