Scroll-to-top
Pre-alphaThe registry and the CLI are not published yet.Roadmap
Scroll

Scroll-to-top

A way back to the top of a long list, without scrolling all the way up.

Draft

Specified, not implemented yet. The API is described in useScrollToTop and may change.

After the user scrolls far down a long list, a button appears. Tapping it brings the list back to the top, then the button goes away.

News
Markets open higher after rate decision1 of 30 · 2 min read
A new bridge for the old harbour2 of 30 · 3 min read
The quiet return of the night train3 of 30 · 4 min read
Inside the lab growing coral reefs4 of 30 · 5 min read
Why cities are painting roofs white5 of 30 · 6 min read
Chess engines and the endgame6 of 30 · 7 min read
The last lighthouse keeper7 of 30 · 8 min read
A rover finds salt on Mars8 of 30 · 9 min read
How bakeries survive the heat9 of 30 · 10 min read
Libraries lend tools, not just books10 of 30 · 2 min read
The comeback of the paper map11 of 30 · 3 min read
Tracking whales with sound12 of 30 · 4 min read
A marathon at sea level13 of 30 · 5 min read
Rebuilding a 1960s synthesizer14 of 30 · 6 min read
Forests that plant themselves15 of 30 · 7 min read
The science of a perfect nap16 of 30 · 8 min read
Tiny homes, big waiting lists17 of 30 · 9 min read
The river that changed course18 of 30 · 10 min read
A museum for lost luggage19 of 30 · 2 min read
Why bees like blue20 of 30 · 3 min read
Fixing phones in the market square21 of 30 · 4 min read
The long history of the umbrella22 of 30 · 5 min read
Solar boats cross the lake23 of 30 · 6 min read
An orchestra of retired robots24 of 30 · 7 min read
The street with no cars25 of 30 · 8 min read
Saving seeds in the Arctic26 of 30 · 9 min read
The mathematics of queues27 of 30 · 10 min read
A school on a train28 of 30 · 2 min read
Night skies are getting brighter29 of 30 · 3 min read
The end of the list30 of 30 · 4 min read
offset 0 · visible false

Scroll past the dashed line, one screen down, and tap the button. Switch showOn to scroll-up to show it only when the user starts going back up.

When to use it

  • Long feeds, search results and catalogs, where going back up by hand takes several flicks.
  • Lists that load more pages as the user scrolls (pagination).

A button isn’t the only trigger. On iOS, tapping the status bar scrolls to the top, and on both platforms tapping the tab that is already selected does too. Support these in any case; add the button when the list is long enough to need a visible one.

Don’t add it to lists that fit in one or two screens, or on a screen that already has a floating action button in the same place.

How it works

When the button shows

The button appears only once the top of the list is out of reach. threshold defaults to one screen of content.

offset ≥ threshold ('scroll-up': and scrolling up)offset < thresholdscroll down ('scroll-up' only)hiddenshown

scroll-up keeps the content clear while the user reads down, and offers the button when they start looking for the top.

What a tap does

A long animated scroll feels slow and renders every row on the way. Far from the top, the list first jumps without animation, then animates the last screen:

offset 12 000 ──jump──► 800 (threshold) ──animate──► 0
offset    900 ─────────────────────animate─────────► 0

The return always takes the same short time, whatever the distance.

RuleWhy
Show past thresholdNear the top, the user can scroll back in one flick.
Hide while returningThe button did its job. It shouldn’t flash back on the way up.
Jump, then animateA 12 000pt animation is slow and renders every row on the way.
A user scroll cancels the returnThe user always wins over an animation in progress.
Tab press and status bar tap do the sameUsers expect them, and they work without a visible button.

Implementation

Axiom implements it with one hook, useScrollToTop. It tracks the offset and exposes visible and scrollToTop(). The button is yours.

LibraryUsed for
react-native-reanimatedThe offset as a shared value, read in useAnimatedScrollHandler. visible is derived on the UI thread and sent to React only when it changes.
React NativescrollToOffset / scrollTo through the list ref for the jump (animated: false) and the return (animated: true). scrollsToTop on iOS for the status bar tap.
@react-navigation/native (optional)Its useScrollToTop(ref) scrolls on a tab press. The hook calls it when React Navigation is present.

In a screen

Conceptual
const top = useScrollToTop();

<Animated.FlatList
	data={articles}
	renderItem={renderArticle}
	{...top.scrollProps}
/>;
{
	top.visible && (
		<Fab
			icon="arrow-up"
			accessibilityLabel="Scroll to top"
			onPress={top.scrollToTop}
		/>
	);
}

Installation, options and return value are documented in useScrollToTop.

Accessibility

  • Give the button a label: “Scroll to top”.
  • After the return, move screen reader focus to the first row or the screen title, so the user knows where they are.
  • With Reduce Motion on, jump straight to 0 without animating.
  • Don’t rely on the button alone: the tab press and the status bar tap work with a screen reader too.