Command palette

@yasinsensoy/native

React Native · Components

ScrollView

Scroll view connected to the gesture arbiter.

8 exports

Import

import { ScrollView, renderScrollView, useScrollRegion } from "@yasinsensoy/native";

ScrollView

component

Scroll view connected to the gesture arbiter. The scrolling itself is the platform's native scrolling (momentum, bounce, 120 Hz smoothness are kept as is); on top of it a layer resolves conflicts with inner drags:

  • Inner GestureView / usePanGesture regions (slider, carousel, swipe-to-act, signature, chart) do not move the page in their own directions; on the native side the decision is made in the same frame as the touch.
  • Reports the directions it can scroll to the arbiter: at the top a pull-down closes the outer Sheet, in the middle the content scrolls; in a horizontal list at the start, a rightward pull goes to navigation's "back" gesture.
  • Open Swipeable rows close when scrolling starts.

All library components use this. It is a drop-in replacement for React Native ScrollView; ref gives the same instance.

ScrollView({ ref, ...props }: ScrollViewProps): JSX.Element

Examples

import { ScrollView } from "@yasinsensoy/native/scroll-view";

<ScrollView contentContainerStyle={{ padding: 16, gap: 12 }}>
  <Slider defaultValue={40} />
  <Carousel slides={slides} />
</ScrollView>

Scroll component for FlatList, SectionList and VirtualizedList: renders the list on the library's ScrollView, so the list is also connected to the gesture arbiter (horizontal drags in a row do not scroll the list, a pull-down at the top goes to the Sheet). When onRefresh is given it adds a RefreshControl like React Native's default.

renderScrollView({ onRefresh, refreshing, progressViewOffset, refreshControl, ...props }: ListScrollProps): JSX.Element

Examples

<FlatList data={messages} renderItem={…} renderScrollComponent={renderScrollView} />

Registers a scroll view with the gesture arbiter. ScrollView uses this itself; for other scroll views such as FlatList/SectionList:

  • Reports the directions it can scroll: at the top, a pull-down goes to the outer Sheet (drag down to close); in the middle the content scrolls. In a horizontal list at the first item, a rightward pull goes to navigation's "back" gesture.
  • Notifies the arbiter when scrolling starts (open Swipeable rows close).
  • Where there is no native gesture view (web), stops scrolling when an inner drag starts.

Given handlers are kept and merged with them.

useScrollRegion(props: P, parent?: ScrollLock | null): ScrollRegion<P>

Examples

const scroll = useScrollRegion(listProps);
return (
  <ScrollLockContext.Provider value={scroll.lock}>
    <FlatList {...scroll.props} />
  </ScrollLockContext.Provider>
);

Props virtualized lists pass to the scroll component.

Extends: NativeScrollViewProps

NameTypeDescription
ref?Ref<ScrollViewRef>React Native ScrollView instance.
onRefresh?(() => void) | nullCalled on pull to refresh.
refreshing?boolean | nullWhether the refresh indicator is shown.
progressViewOffset?numberOffset of the refresh indicator from the top.

Scroll props read and merged by useScrollRegion.

NameTypeDescription
horizontal?boolean | nullHorizontal scrolling.
inverted?boolean | nullInverted list (FlatList inverted): on-screen directions are the reverse of the scroll direction.
scrollEnabled?booleanWhether scrolling is enabled.
refreshControl?unknownIf present, a pull-down at the top belongs to scrolling (refresh).
onScroll?((event: ScrollEvent) => void) | unknownScroll handler (an Animated.event is also accepted).
onScrollBeginDrag?(event: ScrollEvent) => voidDrag started.
onScrollEndDrag?(event: ScrollEvent) => voidDrag ended.
onMomentumScrollEnd?(event: ScrollEvent) => voidMomentum scroll ended.
onLayout?(event: LayoutChangeEvent) => voidLayout changed.
onContentSizeChange?(width: number, height: number) => voidContent size changed.
onTouchStart?(event: GestureResponderEvent) => voidTouch started.
onTouchEnd?(event: GestureResponderEvent) => voidTouch ended.
onTouchCancel?(event: GestureResponderEvent) => voidTouch cancelled.

ScrollRegion

interface

Result of useScrollRegion.

NameTypeDescription
regionGestureRegionThe region in the arbiter.
propsPProps to pass to the scroll view (ScrollView, FlatList, SectionList).
lockScrollLockLock to pass to ScrollLockContext (for inner drags).

React Native ScrollView instance (scrollTo, scrollToEnd, flashScrollIndicators).

type ScrollViewRef = ComponentRef<typeof NativeScrollView>

ScrollView props: same as React Native ScrollView.

Extends: NativeScrollViewProps

NameTypeDescription
ref?Ref<ScrollViewRef>React Native ScrollView instance.