Components
ScrollView
Scroll content vertically or horizontally inside a bounded container.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import { Text, VStack } from '@swiftuijs/ui';
import { ScrollView } from '@swiftuijs/ui';
export default function Example() {
return ((<ScrollView style={{ height: '200px' }}>
<VStack spacing={10}>
{Array.from({ length: 20 }, (_, i) => (<Text key={i}>Item {i + 1}</Text>))}
</VStack>
</ScrollView>));
}Scroll Indicators
Hide scroll indicators if needed:
With Spacer
Use Spacer within ScrollView for flexible layouts:
Long Content
ScrollView handles long content efficiently:
Custom Styling
Apply custom styles to ScrollView:
Programmatic Position
Drive a scroll view from state and scroll to anchors with scrollPosition:
Usage and limitations
- Give the container a bounded height for vertical scrolling or width for horizontal scrolling; the bound may come from parent layout.
- Vertical scrolling is the default.
showsIndicators={false}hides indicators; ordinary React children are supported. scrollPositionreads/sets position or jumps to a ScrollTarget;onScrollPhaseChangedistinguishes scrolling from idle.- This does not virtualize children. Use LazyVStack/LazyHStack for large lists, and avoid nested scroll areas in the same direction.
- Keep scrolling reachable with the keyboard and test touch interaction; add a focusable labeled region when the surrounding composition needs it.
More examples
Vertical Scrolling
Horizontal Scrolling
Scroll Indicators
With Spacer
Long Content
Custom Styling
Programmatic Position
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
direction | 'horizontal' | 'vertical' | No | The scrollable axis of the scroll view. Default: 'vertical' |
showsIndicators | boolean | No | A Boolean value that indicates whether the scroll view displays the scroll indicators. Default: true |
scrollPosition | IScrollPosition | No | The current scroll position of the view. |
onScrollPositionChange | (position: IScrollPosition) => void | No | Called when the scroll position changes. |
onScrollPhaseChange | (phase: IScrollPhase) => void | No | Called when the scroll interaction phase changes. |
Inherits additional props from IBaseComponent.