forked from gajendrakumartwinwal/infiniteslideshow
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Ignore.tsx
111 lines (100 loc) · 3.06 KB
/
Ignore.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, { Component } from 'react';
import {
View,
Text,
FlatList,
Dimensions,
Platform,
Button,
} from 'react-native';
const itemWidth = Dimensions.get('window').width;
const MARGIN = 60//Dimensions.get('window').width / 2.5
let counter = 1
export default class App extends Component {
constructor(props) {
super(props);
this.index = 0;
this.users = []
for (let i = 0; i < 10; i++) {
this.users[i] = {
key: '5a31077f6dda99e234ad6727',
name: i,
company: 'EXOVENT',
email: '[email protected]',
}
}
}
render() {
return (
<View>
<FlatList
style={{ height: 400, marginTop: 100}}
ref={(ref) => (this.flatlist = ref)}
data={this.users}
ItemSeparatorComponent={this.renderSeparator}
showsHorizontalScrollIndicator={false}
contentContainerStyle={{ paddingHorizontal: '5%' }}
// keyExtractor={this.props.keyExtractor}
onScrollEndDrag={(e) => {
// this.pagination(e.nativeEvent.velocity.x);
}}
snapToAlignment={'center'}
// getItemLayout={this.getItemLayout}
horizontal
renderItem={this.renderItem}
/>
<Button
style={{ height: 50 }}
onPress={this.onPress}
title="Press Me"
/>
</View>
);
}
renderSeparator = () => {
return (
<View
style={{
height: '100%',
width: 20,
backgroundColor: "#CED0CE"
}}
/>
);
};
onPress = () => {
this.flatlist.scrollToIndex({ animated: true, index: (counter++%this.users.length) });
};
getItemLayout = (data, index) => ({
length: itemWidth,
offset: itemWidth * index,
index,
});
pagination = (velocity) => {
let nextIndex;
if (Platform.OS == 'ios')
nextIndex = velocity > 0 ? this.index + 1 : this.index - 1;
else nextIndex = velocity < 0 ? this.index + 1 : this.index - 1;
if (this.isLegitIndex(nextIndex, this.users.length)) {
this.index = nextIndex;
}
this.flatlist.scrollToIndex({ index: this.index, animated: true });
};
isLegitIndex(index, length) {
if (index < 0 || index >= length) return false;
return true;
}
renderItem = ({ item }) => (
<View
style={{
borderColor: 'red',
borderWidth: 1,
width: 200,
backgroundColor: '#e2e2e2',
justifyContent: 'center',
alignItems: 'center',
}}>
<Text>{item.name}</Text>
</View>
);
}