-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (48 loc) · 1.51 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
import React, { Component } from 'react'
import {ListView, View, Dimensions} from 'react-native'
import PropTypes from 'prop-types';
export default class Grid extends Component {
static propTypes = {
dataSource: PropTypes.array.isRequired,
column: PropTypes.number.isRequired,
row: PropTypes.number
}
constructor(props){
super(props)
this.windowWidth = Dimensions.get('window').width
this.windowHeight = Dimensions.get('window').height
this.width = this.windowWidth * (1/this.props.column)
if(this.props.row)
this.height = this.windowHeight * (1/this.props.row)
else
this.height = this.windowWidth * (1/this.props.column)
let ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
});
this.state = {
width: this.width,
height: this.height,
dataSource: ds.cloneWithRows(this.props.dataSource)
}
}
componentDidUpdate(){
this.setState({
dataSource: this.state.dataSource.cloneWithRows(this.props.dataSource)
});
}
render(){
return(
<ListView
{...this.props}
contentContainerStyle={{flexDirection: 'row', flexWrap: 'wrap'}}
dataSource={this.state.dataSource}
renderRow={(rowData, sectionID, rowID, highlightRow) => {
return (
<View style={{width: this.state.width ,height: this.state.height}}>
{this.props.rowView(rowData, sectionID, rowID, highlightRow)}
</View>
);
}}/>
)
}
}