0.3.16 • Published 1 month ago

react-native-infinite-pager v0.3.16

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

React Native Infinite Pager

An infinitely-swipeable horizontal and vertical pager component. Fully native interactions powered by Reanimated 2 and React Native Gesture Handler

InfinitePager demo

Install

  1. Follow installation instructions for reanimated and react-native-gesture-handler
  2. npm install or yarn add react-native-infinite-pager
  3. import InfinitePager from 'react-native-infinite-pager'

Props

type PageProps = {
  index: number;
  focusAnim: Animated.DerivedValue<number>;
  isActive: boolean;
  pageWidthAnim: Animated.SharedValue<number>;
  pageAnim: Animated.SharedValue<number>;
}

type PageComponentType = (props: PageProps) => JSX.Element | null;

type AnyStyle = StyleProp<ViewStyle> | ReturnType<typeof useAnimatedStyle>;

type Props = {
  PageComponent?:
    | PageComponentType
    | React.MemoExoticComponent<PageComponentType>;
  renderPage?: PageComponentType
  pageCallbackNode?: Animated.SharedValue<number>;
  onPageChange?: (page: number) => void;
  pageBuffer?: number; 
  style?: AnyStyle;
  pageWrapperStyle?: AnyStyle;
  pageInterpolator?: typeof defaultPageInterpolator;
  minIndex?: number;
  maxIndex?: number;
  initialIndex?: number;
  simultaneousGestures?: (ComposedGesture | GestureType)[];
  gesturesDisabled?: boolean;
  animationConfig?: Partial<WithSpringConfig>;
  vertical?: boolean;
  flingVelocity?: number;
  preset?: Preset;
};
NameTypeDescription
PageComponentPageComponentTypeComponent to be rendered as each page (either PageComponent OR renderPage must be defined, but not both — choose the version that suits your use case).
renderPagePageComponentTypeFunction to be called to render each page.
onPageChange(page: number) => voidCallback invoked when the current page changes.
styleAnyStyleStyle of the pager container.
pageWrapperStyleAnyStyleStyle of the container that wraps each page.
pageCallbackNodeAnimated.SharedValue<number>SharedValue that represents the index of the current page.
pageBuffernumberNumber of pages to render on either side of the active page.
pageInterpolator(params: PageInterpolatorParams) => ReturnType<typeof useAnimatedStyle>Interpolator for custom page animations.
minIndexnumberMinimum page index for non-infinite behavior (optional).
maxIndexnumberMaximum page index for non-infinite behavior (optional).
initialIndexnumberIndex that the pager initializes at (optional).
simultaneousGestures(ComposedGesture \| GestureType)[]Simultaneous RNGH gestures.
gesturesDisabledbooleanDisables pan gestures.
animationConfigPartial<WithSpringConfig>Customizes paging animations.
verticalbooleanSets page gesture to the vertical axis.
flingVelocitynumberDetermines sensitivity of a page-turning "fling" at the end of the gesture.
presetPresetUses a pre-configured page interpolator.

Imperative Api

type ImperativeApiOptions = {
  animated?: boolean;
};

export type InfinitePagerImperativeApi = {
  setPage: (index: number, options: ImperativeApiOptions) => void;
  incrementPage: (options: ImperativeApiOptions) => void;
  decrementPage: (options: ImperativeApiOptions) => void;
};
NameTypeDescription
incrementPage(options: ImperativeApiOptions) => voidGo to next page.
decrementPage(options: ImperativeApiOptions) => voidGo to previous page.
setPage(index: number, options: ImperativeApiOptions) => voidGo to page of given index.

Example

https://snack.expo.dev/@computerjazz/infinite-pager

import React from "react";
import { Text, View, StyleSheet, TouchableOpacity } from "react-native";
import InfinitePager from "react-native-infinite-pager";

const NUM_ITEMS = 50;

function getColor(i: number) {
  const multiplier = 255 / (NUM_ITEMS - 1);
  const colorVal = Math.abs(i) * multiplier;
  return `rgb(${colorVal}, ${Math.abs(128 - colorVal)}, ${255 - colorVal})`;
}

const Page = ({ index }: { index: number }) => {
  return (
    <View
      style={[
        styles.flex,
        {
          alignItems: "center",
          justifyContent: "center",
          backgroundColor: getColor(index),
        },
      ]}
    >
      <Text style={{ color: "white", fontSize: 80 }}>{index}</Text>
    </View>
  );
};

export default function App() {
  return (
    <View style={styles.flex}>
      <InfinitePager
        PageComponent={Page}
        style={styles.flex}
        pageWrapperStyle={styles.flex}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  flex: { flex: 1 },
});
0.3.16

1 month ago

0.3.15

2 months ago

0.3.14

2 months ago

0.3.13

5 months ago

0.3.12

5 months ago

0.3.11

5 months ago

0.3.10

5 months ago

0.3.9

5 months ago

0.3.6

5 months ago

0.3.5

5 months ago

0.3.8

5 months ago

0.3.7

5 months ago

0.3.4

6 months ago

0.3.3

7 months ago

0.3.0

7 months ago

0.3.2

7 months ago

0.3.1

7 months ago

0.2.1

10 months ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.12

2 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago