-
Notifications
You must be signed in to change notification settings - Fork 0
/
Background.tsx
57 lines (51 loc) · 1.31 KB
/
Background.tsx
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
import React from 'react'
import { View, Text } from 'react-native'
const WHITE = 'rgb(230, 233, 198)'
const BLACK = 'rgb(100, 133, 68)'
interface RowProps {
row: number
}
interface CellProps extends RowProps {
col: number
}
class Background extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
{new Array(8).fill(0).map((_, row) => (
<Row key={row} row={row} />
))}
</View>
)
}
}
const Row = ({ row }: RowProps) => {
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
{new Array(8).fill(0).map((_, col) => (
<Cell key={col} row={row} col={col} />
))}
</View>
)
}
const Cell = ({ row, col }: CellProps) => {
const backgroundColor = (row + col) % 2 === 0 ? WHITE : BLACK
const color = (row + col) % 2 === 0 ? BLACK : WHITE
return (
<View
style={{
flex: 1,
justifyContent: 'space-between',
backgroundColor,
padding: 3,
opacity: 0.8,
}}
>
{/* <Text style={{ color, fontWeight: '600', opacity: col === 0 ? 1 : 0 }}>{8 - row}</Text> */}
{/* <Text style={{ color, fontWeight: '600', opacity: row === 7 ? 1 : 0, alignSelf: 'flex-end' }}>
{String.fromCharCode('a'.charCodeAt(0) + col)}
</Text> */}
</View>
)
}
export default Background