Command palette

@yasinsensoy/native

React Native · Components

BackToTop

"Back to top" button (same behavior as web): appears in the corner once the list is scrolled threshold far, and scrolls smoothly to the top on press.

3 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Scroll the page down; the button appears in the corner and its ring shows how much you've read.

Code

import { BackToTop } from "@yasinsensoy/native";

<BackToTop threshold={200} />

Events

  1. Events appear here when you interact with the preview.

Import

import { BackToTop } from "@yasinsensoy/native";

BackToTop

component

"Back to top" button (same behavior as web): appears in the corner once the list is scrolled threshold far, and scrolls smoothly to the top on press. For long lists, feeds and document screens.

  • Progress: the ring around it fills with the read part of the list (progress={false} turns it off). Only this button re-renders; the list and screen do not.
  • On scroll up: with showOnScrollUp it appears only while scrolling up.
  • Accessibility: hidden from screen readers while hidden; "Back to top" is announced after scrolling up. With reduced motion scrolling is instant.

Place it as a sibling of the scroll component, in the view wrapping the screen.

BackToTop({ scroll, threshold, position, progress, showOnScrollUp, offset, icon, label, children, tooltip, onPress, style, }: BackToTopProps): JSX.Element

Examples

const scroll = useScrollTracker();
<View style={{ flex: 1 }}>
  <FlatList ref={scroll.ref} onScroll={scroll.onScroll} scrollEventThrottle={16} … />
  <BackToTop scroll={scroll} />
</View>

Button placement (same as web).

type BackToTopPosition = "bottom-right" | "bottom-left" | "bottom-center"

Props of the BackToTop component.

NameTypeDefaultDescription
scrollScrollTrackerThe tracked list (useScrollTracker); position, progress and scrolling to top come from it.
threshold?number400Distance that must be scrolled for the button to appear (dp).
position?BackToTopPosition"bottom-right"Button placement.
progress?booleantrueShow reading progress in the ring?
showOnScrollUp?booleanfalseShow only while scrolling up? Does not cover the content while reading down.
offset?number16Distance from the edges (dp); the safe area inset is added.
icon?IconPropup arrowButton icon.
label?stringthe `backToTop` text ("Başa dön")Screen reader name and tooltip.
children?ReactNodeText shown next to the icon; when given, the button becomes a pill.
tooltip?TooltipProp | falseTooltip. Defaults to label; false turns it off.
onPress?() => voidCalled after scrolling to the top.
style?ViewStyleButton style (e.g. { bottom: 72 } for a bottom tab bar).