2.1.3 • Published 4 years ago

react-native-stuff-swiper v2.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

react-native-stuff-swiper

npm

A lightweight React Native component for swipe stuff out!

Besides horizontal swipe motion, it has support for side buttons, static header and footer.

npm.io

Usage

 import React, { useRef, useState } from 'react';
 import StuffSwiper from 'react-native-stuff-swiper';
 ...
 
 const YourAwesomeComponent = () => {
  const [screensData, setScreensData] = useState(null);
  const swiperRef = useRef(null);

  const onPaginationChange = ({ pagination, total, currentIndex})  => {
    // Do your stuff here ...
  }

  return (
    <StuffSwiper
      ref={swiperRef}
      HeaderComponent={<YourHeaderComponent />}
      screensData={screensData}
      enableSideButtons
      loop
      onPaginationChange={onPaginationChange}
      DefaultScreenComponent={MyScreenComponent}
    />
  );
};

NOTE: ref it's required in order to use public methods (e.g. swiperRef.current.goToIndex(0) in the above example)

screensData example

screenData prop must be an array of objects with the following format:

    {
        id: 2,
        screen: <ReactComponent />,
        // OR
        props: {
          //your props
        }
    }

Example of full screensData array:

Without Default screen component:

[
  {
    id: '1',
    screen: 
    	<View>
    		<Text>My first screen </Text>
    	</View>,
  },
  {
    id: '2',
    screen: 
      <View>
        <FlatList
          data={myListInfos}
          keyExtractor={(item, index) => item + index}
          renderItem={({ item }) => <Text style={{ fontSize: 16 }}>{item}</Text>}
        />
      </View>,
  },
  {
    id: '3',
    screen: 
        <Image
          style={{width: 100, height: 100}}
          source={{uri: 'https://facebook.github.io/react-native/img/tiny_logo.png'}}
        />
  },
]

With Default screen component:

[
  {
    id: '1',
    props: {
      title: 'first screen',
    },
  {
    id: '2',
    props: {
      title: 'second screen',
    },
  },
  {
    id: '3',
    props: {
      title: 'third screen',
      // any other props that you want to be injected into our DefaultScreenComponent
    },
  },
]

API Reference

Props

Prop nameInfoType
onPaginationChangeCallback that returns pagination (aka formatted current/total), currentIndex and totalFunction
loopSpecify if the loop behaviour it's enabled (default: false)Bool
animatedSpecify if the animations are enabled (default: true)Bool
screensDataData that will be rendered on screensArray of Objects
HeaderComponentComponent that will be rendered as headerReact Component
FooterComponentComponent that will be rendered as footerReact Component
DefaultScreenComponentComponent that will be rendered as screenReact Component
DefaultScreenPropsGlobal Props that will be injected in DefaultScreenComponentObject
enableSideButtonsSpecify if side buttons are enabled (default: false)Bool
nextButtonComponentComponent that will be rendered as next side buttonReact Component
previousButtonComponentComponent that will be rendered as previous side buttonReact Component
styleHeaderContainerSpecify the header container stylesStyle Object
styleFooterContainerSpecify the footer container stylesStyle Object
styleContentContainerSpecify the content container stylesStyle Object
styleSideButtonsContainerSpecify the side buttons container stylesStyle Object
styleButtonSpecify the default side button container stylesStyle Object
buttonSizeSpecify the side buttons size (default: 30)Number

Public methods

Method nameInfoParametersReturn
getPaginationGet current pagination status-{ currentIndex, pagination, total }
nextGo to the next screen--
prevGo to the previous screen--
goToIndexGo to the specified indexindex-