forked from vergnet/application-amicale
Use pure component for cells
This commit is contained in:
parent
bb54186d9e
commit
7b45841c30
3 changed files with 34 additions and 14 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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={{
|
||||
|
|
Loading…
Reference in a new issue