2020-03-15 18:44:32 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
|
|
|
import {View} from 'react-native';
|
|
|
|
import {withTheme} from 'react-native-paper';
|
|
|
|
import Cell from "./Cell";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
|
|
|
grid: Array<Array<Object>>,
|
2020-03-17 14:22:49 +01:00
|
|
|
backgroundColor: string,
|
2020-03-15 18:44:32 +01:00
|
|
|
height: number,
|
|
|
|
width: number,
|
2020-03-17 14:22:49 +01:00
|
|
|
containerHeight: number|string,
|
2020-03-15 18:44:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class Grid extends React.Component<Props>{
|
|
|
|
|
|
|
|
colors: Object;
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.colors = props.theme.colors;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRow(rowNumber: number) {
|
|
|
|
let cells = [];
|
|
|
|
for (let i = 0; i < this.props.width; i++) {
|
|
|
|
let cell = this.props.grid[rowNumber][i];
|
2020-03-15 20:18:48 +01:00
|
|
|
let key = rowNumber + ':' + i;
|
|
|
|
cells.push(<Cell color={cell.color} isEmpty={cell.isEmpty} id={key}/>);
|
2020-03-15 18:44:32 +01:00
|
|
|
}
|
|
|
|
return(
|
|
|
|
<View style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
}}>
|
|
|
|
{cells}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getGrid() {
|
|
|
|
let rows = [];
|
|
|
|
for (let i = 0; i < this.props.height; i++) {
|
|
|
|
rows.push(this.getRow(i));
|
|
|
|
}
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
flexDirection: 'column',
|
2020-03-17 14:22:49 +01:00
|
|
|
height: this.props.containerHeight,
|
2020-03-15 18:44:32 +01:00
|
|
|
aspectRatio: this.props.width/this.props.height,
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
2020-03-17 14:22:49 +01:00
|
|
|
backgroundColor: this.props.backgroundColor,
|
2020-03-15 18:44:32 +01:00
|
|
|
}}>
|
|
|
|
{this.getGrid()}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withTheme(Grid);
|