@expo/ui: programmatic scroll control (scroll to top) for ScrollView, Column and LazyColumn
Bilal Bentoumi
The
@expo/ui
scrolling components don't let JavaScript control the scroll position, so common behavior like "scroll to top when the active tab is pressed again" isn't possible without workarounds.Affected components
- ScrollView(universal)
- Jetpack Compose LazyColumnandLazyRow
- ColumnandRowwith theverticalScroll()andhorizontalScroll()modifiers
What's missing
- ScrollViewhas noref.
- LazyColumnhas no ref or list-state handle.
- verticalScroll()keepsrememberScrollState()internal.
- Other components do expose native methods through a ref, such as HorizontalPager(scrollToPage,animateScrollToPage),ModalBottomSheetandTextField.
Use case
NativeTabs
in Expo Router scrolls to top on a repeated tab press, but only on iOS. On Android the app needs something to call on the scrollable. The only workaround today is remounting the ScrollView
with a changing key
, which gives an instant jump with no animation and resets state inside the content.Proposed API
```tsx
const ref = useRef<ScrollViewRef>(null);
ref.current?.scrollTo({ x: 0, y: 0, animated: true });
// or
ref.current?.scrollToTop({ animated: true });
<ScrollView ref={ref}>...</ScrollView>
```
For
LazyColumn
, add scrollToItem(index, { animated })
. If the ref also implements scrollTo
or scrollToOffset
, it would work directly with useScrollToTop
from expo-router
.Environment
@expo/ui
~58.0.29, expo
~58.0.26, Android dev build. I haven't tested the SwiftUI side.