All Projects → ajsmth → React Native Pager

ajsmth / React Native Pager

Licence: mit
controllable pager component for react native

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Native Pager

Tablesorter
Github fork of Christian Bach's tablesorter plugin + awesomeness ~
Stars: ✭ 2,532 (+848.31%)
Mutual labels:  pager
react-native-carousel-pager
React Native carousel pager.
Stars: ✭ 90 (-66.29%)
Mutual labels:  pager
Walk-Through-Screen
This library provides easy ways to add onboarding or pager screens with different animation and indicators.
Stars: ✭ 31 (-88.39%)
Mutual labels:  pager
Jxpagecontrol
🚀🚀🚀 自定义pageControl指示器, 支持多种动画, 自定义布局.
Stars: ✭ 246 (-7.87%)
Mutual labels:  pager
autopagerize
Infiniscroll on web pages using a large database of rules. A fully reworked fork of the original extension.
Stars: ✭ 55 (-79.4%)
Mutual labels:  pager
vue-pagination
🔵一个`bootstrap`风格的`vue.js`(2.0)分页组件
Stars: ✭ 28 (-89.51%)
Mutual labels:  pager
Pagestatemanager
manage the loading,emtpy,error state of page, use in xml or just in code
Stars: ✭ 173 (-35.21%)
Mutual labels:  pager
tiny-wheels
一套基于原生JavaScript开发的组件库,无依赖、体积小、简单易用
Stars: ✭ 60 (-77.53%)
Mutual labels:  pager
RxPager
RxPager is an Android library that helps handling paginated results in a reactive way
Stars: ✭ 56 (-79.03%)
Mutual labels:  pager
KPSmartTabBar
A fully customisable and flexible tab bar controller
Stars: ✭ 37 (-86.14%)
Mutual labels:  pager
Pagerbeauty
📟✨ PagerDuty on-call widget for monitoring dashboard. Datadog and Grafana compatible
Stars: ✭ 250 (-6.37%)
Mutual labels:  pager
spotify-song-recommender
A Spotify song recommendation engine built with the power of graph analytics.
Stars: ✭ 34 (-87.27%)
Mutual labels:  pager
CircularCardsStackView
CircularCardsStackView is an Android library for dealing with swipeable card views.
Stars: ✭ 30 (-88.76%)
Mutual labels:  pager
Swiftpagemenu
Customizable Page Tab Menu Controller 👍
Stars: ✭ 233 (-12.73%)
Mutual labels:  pager
Reside-Menu
By applying viewpager animation you can also make AMAZING Reside Menu's
Stars: ✭ 72 (-73.03%)
Mutual labels:  pager
Csview
📠 A high performance csv viewer with cjk/emoji support.
Stars: ✭ 208 (-22.1%)
Mutual labels:  pager
MvcSimplePager
Simple,lightweight,easy to expand pager for asp.net mvc and asp.net core,针对asp.net mvc 和 asp.net core 设计的通用、扩展性良好的轻量级分页扩展
Stars: ✭ 13 (-95.13%)
Mutual labels:  pager
Transformerslayout
🔥 App金刚区导航菜单,类似淘宝、QQ音乐等APP导航,方格布局横向多行滑动翻页带滚动条
Stars: ✭ 258 (-3.37%)
Mutual labels:  pager
security-study-tutorial
Summary of online learning materials
Stars: ✭ 73 (-72.66%)
Mutual labels:  pager
pagination
Aplus Framework Pagination Library
Stars: ✭ 167 (-37.45%)
Mutual labels:  pager

react-native-pager

A fully controllable, high performance pager for React Native

Installation

yarn add @crowdlinker/react-native-pager

If you're using expo, all dependencies are already installed by default. If not, you'll need to install two dependencies along with this library:

yarn add react-native-gesture-handler
yarn add react-native-reanimated

There are additional steps to setting these up:

Example

// lots more examples are available in example/src directory of this repo

import React, { useState } from 'react';
import { View } from 'react-native';
import { Pager, PagerProvider } from '@crowdlinker/react-native-pager';
import { Slide } from './shared-components';

function MyPager() {
  const [activeIndex, onChange] = useState(1);

  return (
    <PagerProvider activeIndex={activeIndex} onChange={onChange}>
      <Pager>
        <Slide />
        <Slide />
        <Slide />
        <Slide />
      </Pager>
    </PagerProvider>
  );
}

API Reference

Pager

import { Pager } from '@crowdlinker/react-native-pager'

Props
--------
children: React.ReactNode[];
activeIndex?: number; - active screen
onChange?: (nextIndex: number) => void; - active screen changed
initialIndex?: number; - initial active screen
springConfig?: Partial<SpringConfig> - configuration for spring transitions on swipe / snap
pageInterpolation?: iPageInterpolation - see below - configuration for individual page transforms
panProps?: Partial<GestureHandlerProperties> - configuration for <PanGestureHandler />
pageSize?: number; - percentage (0 - 1), how far should it page on index change
threshold?: number; - percentage (0 - 1), how far should the user drag before snapping to next / prev
minIndex?: number; - minimum index to swipe to (default 0)
maxIndex?: number; - maximum index to swipe to (default children.length - 1)
adjacentChildOffset?: number; - the number of children adjacent to the activeIndex to render
style?: ViewStyle; - style for pages
containerStyle?: ViewStyle - style for pan handler container
animatedValue?: Animated.Value<number>; - total translation value of the pager
animatedIndex?: Animated.Value<number>; - activeIndex as an animated value e.g intermediate values
type?: 'horizontal' | 'vertical'; - target horizontal swipes or vertical swipes
clamp?: {
  prev?: number; - percentage (0 - 1) - clamp children to the left of the active screen
  next?: number; - percentage (0 - 1) - clamp children to the right of the active screen
};
clampDrag: {
  prev?: number - max drag distance to previous screen,
  next?: number - max drag distance to next screen
}

This interface looks intimidating, but nearly all of these props are optional and customize specific behaviours. They won't be necessary in a lot of use cases.

PagerProvider

import { PagerProvider } from '@crowdlinker/react-native-pager'

Props
--------
children: React.ReactNode;
initialIndex?: number;
activeIndex?: number;
onChange?: (nextIndex: number) => void;

Pagination

import { Pagination } from '@crowdlinker/react-native-pager'

Props
--------
children: React.ReactNode;
pageInterpolation: iPageInterpolation;
style?: ViewStyle;

Slider

import { Slider } from '@crowdlinker/react-native-pager'

Props
--------
numberOfScreens: number;
style: ViewStyle;

Progress

import { Progress } from '@crowdlinker/react-native-pager'

Props
--------
numberOfScreens: number;
style: ViewStyle;

Hooks

There are a number of useful hooks you can use in your screens when you wrap <Pager /> in a <PagerProvider />

  usePager(): [activeIndex, onChange, animatedIndex]
  useFocus(): boolean -> is screen focused
  useOffset(index: number) -> animatedIndex value relative to the given index
  useOnFocus(fn) -> fn() to fire on screen focus
  useIndex() -> the index of the screen
  useAnimatedIndex() -> the animatedIndex value of the pager
  useInterpolation(interpolationConfig) -> interpolated style object

What is animatedIndex?

Animated index represents the animated value of the active index -- it includes possible intermediate values. When panning or transitioning, the activeIndex value moves from 0 -> 1 but the animatedIndex value captures all intermediate values between 0 and 1 during this transition.

Hooks in action

function MySlide(props) {
  const [data, setData] = useState();

  useOnFocus(() => {
    if (!data) {
      myApi.fetchData(props);
    }
  });

  const style = useInterpolation({
    transform: [
      {
        scale: {
          inputRange: [-1, 0, 1],
          outputRange: [0.9, 1, 0.9],
          extrapolate: 'clamp',
        },
      },
      {
        rotate: {
          unit: 'deg',
          inputRange: [-1, 0, 1],
          outputRange: [90, 0, 120],
        },
      },
    ],
  });

  return <Animated.View style={{ flex: 1, ...style }}>...</Animated.View>;
}

Interpolation

One of the core features of this library is the ability to customize style transformations based on a screen's position relative to the focused screen.

Here is an example of an interpolation configuration:

const scaledDown = {
  transform: [
    {
      scaleX: {
        inputRange: [-1, 0, 1],
        outputRange: [0.8, 1, 0.8],
        extrapolate: 'clamp',
      },
    },
  ],
};

The object itself is the same shape as any style prop you would normally pass into a <Animated.View /> component. However, the values of these properties define an interpolation configuration.

The input range refers to the position relative to the focused screen:

inputRange: [-1, 0, 1];
// [-1] targets the screen before the focused screen
// [0] targets the screen that is focused
// [1] targets the screen after the focused screen

The output range reflects the style values that will be applied for each specified inputRange value:

outputRange: [0.8, 1, 0.8];
// [0.8] will be applied to the screen before the focused screen
// [1] will be applied to the screen that is focused
// [0.8] will be applied to the screen after the focused screen

In this case, screens that are on the left and right of the focused screen will be scaled to 80% of their size, and any screen outside of this range will also be given 80% scale.

You can customize the behaviour of all of the screens in a <Pager /> by passing this configuration as the pageInterpolation prop. The interpolations can target all kinds of style properties, such as translations, rotations, and more.

Alternatively, you can customize styles for individual screens by using the useInterpolation() hook. This accepts the same configuration object, and will return the style property that you can apply to your Animated.View

The interpolation configs can be found in the react-native-reanimated docs here.

Examples

All of the examples in the gifs above (and more) are available in the /example/src directory of this repo. For the most part, these are different configurations of the pageInterpolation prop. There is all kinds of neat stuff you can do with these - if you have a particular configuration you'd like to share, please submit a PR and spread the love!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].