-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathSwiperWithRenderItems.tsx
56 lines (51 loc) · 1.63 KB
/
SwiperWithRenderItems.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import { Dimensions, ImageBackground, StyleSheet, Text } from 'react-native';
// import { SwiperFlatList } from 'react-native-swiper-flatlist';
import { SwiperFlatListWithGestureHandler } from 'react-native-swiper-flatlist/WithGestureHandler';
import { fox, cat, background, element, lion } from './images';
import { CustomPagination } from './CustomPagination';
const { width } = Dimensions.get('window');
const newImage = [lion, fox, cat, background, element];
const image = (index: number) => ({ image: newImage[index % newImage.length] });
const items = Array.from(Array(5)).map((_, index) => image(index));
export default () => {
return (
<SwiperFlatListWithGestureHandler
// useReactNativeGestureHandler
// inverted
autoplay
autoplayDelay={2}
// index={3}
// autoplayLoop
// autoplayInvertDirection
data={items}
renderItem={({ item, index }) => (
<ImageBackground
style={styles.image}
source={item.image}
testID={`container_swiper_renderItem_screen_${index}`}
>
<Text style={styles.text}>Item at index {index}</Text>
</ImageBackground>
)}
// onChangeIndex={({ index, prevIndex }) => {
// console.log('renderItem', { index, prevIndex });
// }}
showPagination
PaginationComponent={CustomPagination}
e2eID="container_swiper_renderItem"
/>
);
};
const styles = StyleSheet.create({
image: {
width,
resizeMode: 'cover',
justifyContent: 'flex-end',
},
text: {
fontSize: width * 0.1,
color: 'whitesmoke',
textAlign: 'center',
},
});