Command palette

@yasinsensoy/native

React Native · Components

InfiniteScroll

A scroll area that loads the next page when reaching the end of the list (same API as web): feeds, comments, chat history.

2 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

Post 1
Post 2
Post 3
Post 4
Post 5
Post 6
Post 7
Post 8
Post 9
Post 10

Code

import { InfiniteScroll, Post } from "@yasinsensoy/native";

<InfiniteScroll scrollable className="h-96" onLoadMore={nextPage} hasMore={dahaVar} endMessage>
  {gonderiler.map((g) => <Post key={g.id} {...g} />)}
</InfiniteScroll>

Events

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

Import

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

A scroll area that loads the next page when reaching the end of the list (same API as web): feeds, comments, chat history. Give items as children; for thousands of items use VirtualList (the same onLoadMore behavior).

  • One load at a time; if a page does not fill the screen, the next one loads too.
  • It does not loop on errors; a "Retry" button appears.
  • direction="up": the scroll offset is kept for items added to the start (the same on iOS and Android: maintainVisibleContentPosition).
  • manualAfter: switches to a button after a few automatic loads.
  • "Busy" is reported to screen readers while loading.
InfiniteScroll({ children, onLoadMore, onError, hasMore, loading, direction, threshold, manualAfter, loader, endMessage, errorMessage, loadMoreLabel, onRefresh, scroll, style, contentStyle, testID, }: InfiniteScrollProps): JSX.Element

Examples

<InfiniteScroll onLoadMore={fetchNextPage} hasMore={hasNextPage} endMessage onRefresh={refetch}>
  {posts.map((post) => <PostCard key={post.id} post={post} />)}
</InfiniteScroll>

Props of the InfiniteScroll component (same names as on web).

NameTypeDefaultDescription
children?ReactNodeItems loaded so far.
onLoadMore() => unknownLoads the next page. If it returns a Promise it is not called again until it finishes; if it throws, a "Retry" button appears.
onError?(error: unknown) => voidCalled when onLoadMore fails (logging, notification).
hasMorebooleanWhether there is another page to load.
loading?booleanLoading info from outside (e.g. the first page); not triggered while true.
direction?"down" | "up""down"Load direction. "up": like a chat; older items are added to the start and the scroll offset is kept (content does not jump).
threshold?number400Start loading this far from the end (dp).
manualAfter?numberSwitches to a "Load more" button after this many automatic loads. 0 means always a button. If omitted it always loads automatically.
loader?ReactNodeA spinnerLoading indicator.
endMessage?ReactNodeShown at the end of the list when everything is loaded. true shows the built-in text.
errorMessage?ReactNodethe `loadError` textText shown when loading fails.
loadMoreLabel?ReactNodethe `loadMore` textText of the "Load more" button.
onRefresh?() => unknownPull to refresh; if it returns a Promise the indicator spins until it finishes.
scroll?ScrollTrackerScroll tracker (useScrollTracker): for binding Fab, BackToTop.
style?StyleProp<ViewStyle>Style of the scroll area (default flex: 1).
contentStyle?StyleProp<ViewStyle>Style of the content container (padding, gap).
testID?stringTest id.