Use pure component for cells

This commit is contained in:
Arnaud Vergnet 2020-03-15 20:18:48 +01:00
parent bb54186d9e
commit 7b45841c30
3 changed files with 34 additions and 14 deletions

View file

@ -25,7 +25,7 @@ export default class GameLogic {
this.height = height;
this.width = width;
this.gameRunning = false;
this.gameTick = 250;
this.gameTick = 1000;
}
getHeight(): number {

View file

@ -4,18 +4,37 @@ import * as React from 'react';
import {View} from 'react-native';
import {withTheme} from 'react-native-paper';
function Cell(props) {
const colors = props.theme.colors;
return (
<View style={{
flex: 1,
backgroundColor: props.color,
borderColor: props.isEmpty ? props.color : "#393939",
borderStyle: 'solid',
borderWidth: 1,
aspectRatio: 1,
}}/>
);
type Props = {
color: string,
isEmpty: boolean,
id: string,
}
class Cell extends React.PureComponent<Props> {
colors: Object;
constructor(props) {
super(props);
this.colors = props.theme.colors;
}
render() {
return (
<View
style={{
flex: 1,
backgroundColor: this.props.color,
borderColor: this.props.isEmpty ? this.props.color : "#393939",
borderStyle: 'solid',
borderWidth: 1,
aspectRatio: 1,
}}
/>
);
}
}
export default withTheme(Cell);

View file

@ -25,7 +25,8 @@ class Grid extends React.Component<Props>{
let cells = [];
for (let i = 0; i < this.props.width; i++) {
let cell = this.props.grid[rowNumber][i];
cells.push(<Cell color={cell.color} isEmpty={cell.isEmpty}/>);
let key = rowNumber + ':' + i;
cells.push(<Cell color={cell.color} isEmpty={cell.isEmpty} id={key}/>);
}
return(
<View style={{