Skip to main content

ScrollView

A box that scrolls on one axis. It renders an overflow <div> with your content in a View inside.

import { ScrollView, Text } from 'react-native'

export function Feed({ posts }) {
return (
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 16, gap: 12 }}>
{posts.map((post) => (
<Text key={post.id}>{post.title}</Text>
))}
</ScrollView>
)
}

A ScrollView scrolls its own box, not the document. On a phone, the address bar of the browser doesn't hide as you scroll it.

Scroll events​

EventOn the web
onScrollOne event per frame. nativeEvent is the DOM event with contentOffset, contentSize, layoutMeasurement, contentInset (zeros), and zoomScale (1) added. There's no velocity.
onScrollBeginDrag, onScrollEndDragA scroll while a pointer is down is a drag: a finger, or a mouse on the scrollbar. The drag ends when the pointer comes up.
onMomentumScrollBegin, onMomentumScrollEndA scroll after the release is momentum. So is a scroll with no pointer down: the wheel, the keyboard, or scrollTo.
onContentSizeChangeGets the width and height of the content, after mount and after each change.
onKeyboardDidShow, onKeyboardDidHideFollow the Keyboard events: they fire when the on-screen keyboard of a phone or a tablet shows, changes its height, or hides. onKeyboardWillShow and onKeyboardWillHide never fire, as on Android.

The scroll ends at the browser's scrollend event. A browser without scrollend ends it 150 ms after the last scroll event. A scroll with the mouse wheel ends when no wheel event comes for 150 ms. So a quick spin of the wheel is one scroll.

scrollEventThrottle isn't needed: the browser already sends one scroll event per frame.

Props​

PropOn the web
horizontalScrolls on the x axis.
contentContainerStyleThe style of the content View.
scrollEnabledfalse hides the overflow, so nothing scrolls.
contentOffsetSets the scroll position on mount, and again when it changes.
centerContentCenters content that is smaller than the box.
snapToInterval, snapToOffsets, pagingEnabledSnap as on native. With a finger, a pen, or the mouse wheel, the browser's own scroll snap stops the scroll on a snap offset, so a fling ends on one. After a keyboard scroll, a drag of the scrollbar, or scrollTo, the list snaps when the scroll settles, with a smooth scroll. That scroll is instant when the user asks for reduced motion. snapToOffsets with snapToStart={false} or snapToEnd={false} always snaps when the scroll settles, because the browser's scroll snap can't leave a part of the content free.
snapToAlignment, snapToStart, snapToEndAs on native. snapToStart and snapToEnd apply to snapToOffsets.
disableIntervalMomentumWith a finger, a pen, or the mouse wheel, the scroll stops at the next snap offset.
showsVerticalScrollIndicator, showsHorizontalScrollIndicatorfalse on the scroll axis hides the scrollbar.
stickyHeaderIndicesThose children stick to the top. Vertical only, as on native.
stickyHeaderHiddenOnScrollThe sticky header slides out on a scroll down and comes back on a scroll up.
StickyHeaderComponentRenders each sticky header in place of the default one, as on native. It gets React Native's props: scrollAnimatedValue (the vertical scroll offset), nextHeaderLayoutY, onLayout, inverted, hiddenOnScroll, and, with invertStickyHeaders, scrollViewHeight. Its ref gets setNextHeaderY calls. The component places the header itself, for example with a translateY from scrollAnimatedValue. The default header sticks with CSS position: sticky. Use the ScrollViewStickyHeaderProps type for its props.
invertStickyHeadersThe headers stick to the bottom.
keyboardShouldPersistTapsFor a touch or a pen tap while a text field has the focus, as on native: 'never' (the default) lets the tap take the focus from the field, so the keyboard hides. 'handled' keeps the focus when a pressable or a responder takes the tap. 'always' keeps it. One difference: with 'never', the tap also reaches what it lands on, where native uses the first tap only to hide the keyboard.
keyboardDismissModeon-drag blurs the focused field when a drag starts. interactive has no web effect.
maintainVisibleContentPositionWhen the content changes, the scroll offset moves as far as the first visible child at or after minIndexForVisible moved, so that child stays in place, as on native. With autoscrollToTopThreshold, an offset that was within the threshold of the start scrolls to the start. A sticky child is never the anchor. With this prop, the browser's own scroll anchoring is off. Without it, the browser's own scroll anchoring applies, where the browser has it.
refreshControlWraps the scroller and owns the pull. It gets the style props that place the box, and the scroller fills it. See RefreshControl.
View propsAs on View.
The responder propsonMoveShouldSetResponder, onResponderGrant, onResponderMove, onResponderRelease, and the others work as on View. onStartShouldSetResponder, onStartShouldSetResponderCapture, onResponderTerminationRequest, and onResponderReject do nothing: the ScrollView sets them itself, as on native.

These native-only props are accepted and ignored: bounces, alwaysBounceHorizontal, alwaysBounceVertical, contentInset, contentInsetAdjustmentBehavior, decelerationRate, directionalLockEnabled, indicatorStyle, nestedScrollEnabled, overScrollMode, scrollsToTop, the zoom props, and the other iOS and Android props.

Ref​

The ref is the scroll element with the React Native methods added, and the measure methods of View:

MethodOn the web
scrollTo({ x, y, animated })As on native. animated defaults to true. The DOM forms scrollTo(x, y) and scrollTo({ left, top }) work too.
scrollToEnd({ animated })Scrolls to the end of the content.
getScrollableNode(), getNativeScrollRef(), getScrollResponder()The scroll element.
getInnerViewNode()The content element.
flashScrollIndicators()Does nothing. The browser has no API for it.

The old positional form scrollTo(y, x) doesn't work, because the DOM scrollTo(x, y) takes the same arguments in the other order.

Context​

ScrollView.Context is a React context, as in React Native. A component inside a ScrollView reads { horizontal } from it. Outside a ScrollView, it reads null.