-
Notifications
You must be signed in to change notification settings - Fork 61
/
index.js
64 lines (55 loc) · 1.19 KB
/
index.js
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
'use strict';
import React, {Component} from 'react';
import {
AppRegistry,
FlatList,
StyleSheet,
View,
} from 'react-native';
class CollectionView extends Component {
groupItems = (items, itemsPerRow) => {
let itemsGroups = [];
let group = [];
items.forEach(function (item) {
if (group.length === itemsPerRow) {
itemsGroups.push(group);
group = [item];
} else {
group.push(item);
}
});
if (group.length > 0) {
itemsGroups.push(group);
}
return itemsGroups;
};
renderGroup = ({item}) => {
const items = item.map((item, index) => {
return this.props.renderItem(item, index);
});
return (
<View style={styles.group}>
{items}
</View>
);
};
render = () => {
const groups = this.groupItems(this.props.items, this.props.itemsPerRow);
return (
<FlatList
{...this.props}
renderItem={this.renderGroup}
data={groups}
/>
);
};
}
var styles = StyleSheet.create({
group: {
flexDirection : 'row',
alignItems : 'center',
justifyContent: 'center',
overflow : 'hidden'
}
});
module.exports = CollectionView;