Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-swiper-flatlist

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-swiper-flatlist

React native swiper flatlist component

  • 3.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
decreased by-4.77%
Maintainers
1
Weekly downloads
 
Created
Source

:point_up_2: Swiper FlatList component

supports iOS supports Android supports web npm npm Build Status license

Demo

Installation

yarn add react-native-swiper-flatlist

or

npm install react-native-swiper-flatlist --save

Notice

Version 2.x was re-implemented using React Hooks so it only works with version 0.59 or above

Version 3.x was re-implemented using Typescript and it works with react-native-web

react-native-swiper-flatlistreact-nativeDetox tests
1.x<= 0.58X
2.x>= 0.59X
3.x>= 0.59Build Status

Note: we are using the feature export type available in babel v7.9.0 https://github.com/babel/babel/pull/11171, you might have this issue with React Native between 0.60 and 0.63, please update babel to at least to v7.9.0

Examples

Expo example with renderItems, children and more

Expo example with children

React Native example with renderItems and custom pagination

React Native example with children

Code

Using renderItems and data run in expo snack

import React from 'react';
import { Text, Dimensions, StyleSheet, View } from 'react-native';
import { SwiperFlatList } from 'react-native-swiper-flatlist';

const colors = ['tomato', 'thistle', 'skyblue', 'teal'];

const App = () => (
  <View style={styles.container}>
    <SwiperFlatList
      autoplay
      autoplayDelay={2}
      autoplayLoop
      index={2}
      showPagination
      data={colors}
      renderItem={({ item }) => (
        <View style={[styles.child, { backgroundColor: item }]}>
          <Text style={styles.text}>{item}</Text>
        </View>
      )}
    />
  </View>
);

const { width } = Dimensions.get('window');
const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: 'white' },
  child: { width, justifyContent: 'center' },
  text: { fontSize: width * 0.5, textAlign: 'center' },
});

export default App;

Using children run in expo snack

import React from 'react';
import { Text, Dimensions, StyleSheet, View } from 'react-native';
import { SwiperFlatList } from 'react-native-swiper-flatlist';

const App = () => (
  <View style={styles.container}>
    <SwiperFlatList autoplay autoplayDelay={2} autoplayLoop index={2} showPagination>
      <View style={[styles.child, { backgroundColor: 'tomato' }]}>
        <Text style={styles.text}>1</Text>
      </View>
      <View style={[styles.child, { backgroundColor: 'thistle' }]}>
        <Text style={styles.text}>2</Text>
      </View>
      <View style={[styles.child, { backgroundColor: 'skyblue' }]}>
        <Text style={styles.text}>3</Text>
      </View>
      <View style={[styles.child, { backgroundColor: 'teal' }]}>
        <Text style={styles.text}>4</Text>
      </View>
    </SwiperFlatList>
  </View>
);

const { width } = Dimensions.get('window');

const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: 'white' },
  child: { width, justifyContent: 'center' },
  text: { fontSize: width * 0.5, textAlign: 'center' },
});

export default App;

Example project with Detox tests

Code example

To use react-native-gesture-handler instead of FlatList import the library like:

import { SwiperFlatListWithGestureHandler } from 'react-native-swiper-flatlist/WithGestureHandler';

Props

PropDefaultTypeDescription
datanot required if children is usedarrayData to use in renderItem
children-nodeChildren elements
renderItemnot required if children is usedFlatListProps<T>['renderItem']Takes an item from data and renders it into the list
onMomentumScrollEnd-(item: { index: number }, event: any)Called after scroll end and the first parameter is the current index
verticalfalsebooleanShow vertical swiper
index0numberIndex to start
renderAllfalsebooleanRender all the items before display it
Pagination
showPaginationfalsebooleanShow pagination
paginationDefaultColorgraystringPagination color
paginationActiveColorwhitestringPagination color
paginationStyle{}ViewStyleStyle object for the container
paginationStyleItem{}ViewStyleStyle object for the item (dot)
paginationStyleItemActive{}ViewStyleStyle object for the active item (dot)
paginationStyleItemInactive{}ViewStyleStyle object for the inactive item (dot)
onPaginationSelectedIndex-() => voidExecuted when the user presses the pagination index, similar properties onChangeIndex
PaginationComponentComponentnodeOverwrite Pagination component
Autoplay
autoplayfalsebooleanChange index automatically
autoplayDelay3numberDelay between every page in seconds
autoplayLoopfalsebooleanContinue playing after reach end
autoplayLoopKeepAnimationfalsebooleanShow animation when reach the end of the list
autoplayInvertDirectionfalsebooleanInvert auto play direction
disableGesturefalsebooleanDisable swipe gesture

More props

This is a wrapper around Flatlist, all their props works well and the inherited props too (from ScrollView and VirtualizedList)

Functions

NameTypeUse
scrollToIndex({ index: number, animated?: boolean}) => voidScroll to the index
getCurrentIndex() => numberReturns the current index
getPrevIndex() => numberReturns the previous index
onChangeIndex({ index: number, prevIndex: number}) => voidExecuted every time the index change, the index change when the user reaches 60% of the next screen
goToFirstIndex() => voidGo to the first index
goToLastIndex() => voidGo to the last index

Right To Left

This library support RTL languages, when I18nManager.isRTL is true.

Limitations

  • Vertical pagination is not supported on Android. Doc, that is way we have useReactNativeGestureHandler which is a workaround for this issue.

Author

Gustavo Gard

Keywords

FAQs

Package last updated on 10 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc