Skip to content

About

Fast scroll implementation that can be added to flastlist, flashlist on any list that is based on a scrollview container

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

react-native-fast-scroll

Fast Scroll implementation over Flashlist for react native

Show Case

Installation

yarn add react-native-fast-scroll

Requirements

The package's peer dependencies:

  1. react-native-gesture-handler >= 2.8
  2. react-native-reanimated >= 2.12
  3. react-native-redash
  4. @shopify/flash-list

Usage of the FastScroll Indicator

The indicator works with offsets from 0 (the top of the list) to 1 (its end), over the height the list can scroll: its content minus its own height.

import { FastScrollIndicator } from 'react-native-fast-scroll';

// ...

const contentHeight = useRef(0);
const listHeight = useRef(0);
const scrollableHeight = () =>
  Math.max(0, contentHeight.current - listHeight.current);

// The thumb was dragged: scroll the list.
const scrollToOffsetPercentage = (offsetPercentage: number) => {
  flashListRef.current?.scrollToOffset({
    offset: offsetPercentage * scrollableHeight(),
    animated: false,
  });
};

// The list scrolled: move the thumb.
const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
  const scrollable = scrollableHeight();
  const offsetPercentage =
    scrollable > 0 ? event.nativeEvent.contentOffset.y / scrollable : 0;
  fastScrollIndicatorRef.current?.onScrollToOffsetPercentage(
    offsetPercentage
  );
  fastScrollSectionDotsRef.current?.onScrollToOffsetPercentage(
    offsetPercentage
  );
};

<FlashList
  ref={flashListRef}
  onScroll={onScroll}
  onContentSizeChange={(_width, height) => (contentHeight.current = height)}
  onLayout={(event) => (listHeight.current = event.nativeEvent.layout.height)}
  // ...
/>

<FastScrollIndicator
  scrollToOffsetPercentage={scrollToOffsetPercentage}
  hideFastScrollIndicatorTimeout={2000}
  side={'right'}
  ref={fastScrollIndicatorRef}
  thumbColor={'rgba(65, 64, 66, 0.6)'}
  scrollBarColor={'transparent'}
/>

Usage of the FastScroll Section Tab

import { FastScrollSectionTab } from 'react-native-fast-scroll';

// ...

  const onScrollToIndex = (index: number) => {
    flashListRef.current?.scrollToIndex({
      index,
      animated: true,
    });
  };


<FastScrollSectionTab
    ref={fastScrollSectionTabRef}
    onScrollToIndex={onScrollToIndex}
    stickyHeaderIndicesWithData={stickyHeaderIndicesWithData}
/>

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

About

Fast scroll implementation that can be added to flastlist, flashlist on any list that is based on a scrollview container

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages