-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGrid.js
More file actions
65 lines (56 loc) · 1.52 KB
/
Copy pathGrid.js
File metadata and controls
65 lines (56 loc) · 1.52 KB
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
/*
* A smart sudoku-grid for react-native apps
* https://github.com/react-native-component/react-native-smart-sudoku-grid/
* Released under the MIT license
* Copyright (c) 2016 react-native-component <moonsunfall@aliyun.com>
*/
import React, {
Component,
PropTypes,
} from 'react'
import {
View,
StyleSheet,
Dimensions,
} from 'react-native'
const { width: deviceWidth } = Dimensions.get('window');
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'flex-start',
flexWrap: 'wrap',
},
})
export default class SudokuGrid extends Component {
static propTypes = {
rowWidth: PropTypes.number,
columnCount: PropTypes.number.isRequired,
dataSource: PropTypes.array.isRequired,
renderCell: PropTypes.func.isRequired,
style: View.propTypes.style,
}
// 构造
constructor(props) {
super(props)
// 初始状态
this.state = {}
this._columnWidth = (props.rowWidth || deviceWidth) / props.columnCount
}
render() {
return (
<View style={[this.props.style, styles.container, {width: this.props.rowWidth,}]}>
{this._renderCells()}
</View>
)
}
_renderCells() {
return this.props.dataSource.map((data, index, dataList) => {
return (
<View style={{width: this._columnWidth, }} key={`cell-${(data.key != null) ? data.key : index}`}>
{this.props.renderCell(data, index, dataList)}
</View>
)
})
}
}