- Notifications
You must be signed in to change notification settings - Fork102
👆 Swiper component implemented with FlatList using Hooks & Typescript + automation tests with Detox
License
gusgard/react-native-swiper-flatlist
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
yarn add react-native-swiper-flatlist
or
npm install react-native-swiper-flatlist --save
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-flatlist | react-native | Detox tests |
---|---|---|
1.x | <= 0.58 | X |
2.x | >= 0.59 | X |
3.x | >= 0.59 |
Note: we are using the featureexport type
available inbabel v7.9.0
babel/babel#11171, you might have this issue with React Native between 0.60 and 0.63, please updatebabel
to at least tov7.9.0
Expo example with renderItems, children and more
React Native example with renderItems and custom pagination
React Native example with children
importReactfrom'react';import{Text,Dimensions,StyleSheet,View}from'react-native';import{SwiperFlatList}from'react-native-swiper-flatlist';constcolors=['tomato','thistle','skyblue','teal'];constApp=()=>(<Viewstyle={styles.container}><SwiperFlatListautoplayautoplayDelay={2}autoplayLoopindex={2}showPaginationdata={colors}renderItem={({ item})=>(<Viewstyle={[styles.child,{backgroundColor:item}]}><Textstyle={styles.text}>{item}</Text></View>)}/></View>);const{ width}=Dimensions.get('window');conststyles=StyleSheet.create({container:{flex:1,backgroundColor:'white'},child:{ width,justifyContent:'center'},text:{fontSize:width*0.5,textAlign:'center'},});exportdefaultApp;
importReactfrom'react';import{Text,Dimensions,StyleSheet,View}from'react-native';import{SwiperFlatList}from'react-native-swiper-flatlist';constApp=()=>(<Viewstyle={styles.container}><SwiperFlatListautoplayautoplayDelay={2}autoplayLoopindex={2}showPagination><Viewstyle={[styles.child,{backgroundColor:'tomato'}]}><Textstyle={styles.text}>1</Text></View><Viewstyle={[styles.child,{backgroundColor:'thistle'}]}><Textstyle={styles.text}>2</Text></View><Viewstyle={[styles.child,{backgroundColor:'skyblue'}]}><Textstyle={styles.text}>3</Text></View><Viewstyle={[styles.child,{backgroundColor:'teal'}]}><Textstyle={styles.text}>4</Text></View></SwiperFlatList></View>);const{ width}=Dimensions.get('window');conststyles=StyleSheet.create({container:{flex:1,backgroundColor:'white'},child:{ width,justifyContent:'center'},text:{fontSize:width*0.5,textAlign:'center'},});exportdefaultApp;
To usereact-native-gesture-handler
instead of FlatList import the library like:
import{SwiperFlatListWithGestureHandler}from'react-native-swiper-flatlist/WithGestureHandler';
Prop | Default | Type | Description |
---|---|---|---|
data | not required if children is used | array | Data to use in renderItem |
children | - | node | Children elements |
renderItem | not required if children is used | FlatListProps<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 |
vertical | false | boolean | Show vertical swiper |
index | 0 | number | Index to start |
renderAll | false | boolean | Render all the items before display it |
Pagination | |||
showPagination | false | boolean | Show pagination |
paginationDefaultColor | gray | string | Pagination color |
paginationActiveColor | white | string | Pagination color |
paginationStyle | {} | ViewStyle | Style object for the container |
paginationStyleItem | {} | ViewStyle | Style object for the item (dot) |
paginationStyleItemActive | {} | ViewStyle | Style object for the active item (dot) |
paginationStyleItemInactive | {} | ViewStyle | Style object for the inactive item (dot) |
onPaginationSelectedIndex | - | () => void | Executed when the user presses the pagination index, similar properties onChangeIndex |
PaginationComponent | Component | node | Overwrite Pagination component |
Autoplay | |||
autoplay | false | boolean | Change index automatically |
autoplayDelay | 3 | number | Delay between every page in seconds |
autoplayLoop | false | boolean | Continue playing after reach end |
autoplayLoopKeepAnimation | false | boolean | Show animation when reach the end of the list |
autoplayInvertDirection | false | boolean | Invert auto play direction |
disableGesture | false | boolean | Disable swipe gesture |
More props
This is a wrapper aroundFlatlist, all theirprops
works well and the inheritedprops
too (fromScrollView andVirtualizedList)
Name | Type | Use |
---|---|---|
scrollToIndex | ({ index: number, animated?: boolean}) => void | Scroll to the index |
getCurrentIndex | () => number | Returns the current index |
getPrevIndex | () => number | Returns the previous index |
onChangeIndex | ({ index: number, prevIndex: number}) => void | Executed every time the index change, the index change when the user reaches 60% of the next screen |
goToFirstIndex | () => void | Go to the first index |
goToLastIndex | () => void | Go to the last index |
This library support RTL languages, whenI18nManager.isRTL
istrue
.
- Vertical pagination is not supported on Android.Doc, that is way we have
useReactNativeGestureHandler
which is a workaround for this issue.
Gustavo Gard
About
👆 Swiper component implemented with FlatList using Hooks & Typescript + automation tests with Detox
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.