/* eslint-disable react-native/no-inline-styles */ import React from 'react'; import { View, StyleSheet, Text } from 'react-native'; import { useChessboardProps } from '../context/props-context/hooks'; const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', }, }); type BackgroundProps = { letters: boolean; numbers: boolean; }; interface BaseProps extends BackgroundProps { white: boolean; } interface RowProps extends BaseProps { row: number; } interface SquareProps extends RowProps { col: number; } const Square = React.memo( ({ white, row, col, letters, numbers }: SquareProps) => { const { colors, orientation } = useChessboardProps(); const backgroundColor = white ? colors.black : colors.white; const color = white ? colors.white : colors.black; const textStyle = { fontWeight: '500' as const, fontSize: 10, color }; const newLocal = orientation === 'black' ? col === 7 : col === 0; return ( {numbers && ( {'' + (8 - row)} )} {row === (orientation === 'black' ? 0 : 7) && letters && ( {String.fromCharCode(97 + col)} )} ); } ); const Row = React.memo(({ white, row, ...rest }: RowProps) => { const { orientation } = useChessboardProps(); const offset = white ? 0 : 1; const cols = new Array(8).fill(0).map((_, i) => i); const colIndexes = orientation === 'black' ? [...cols].reverse() : cols; return ( {colIndexes.map((col) => ( ))} ); }); const Background: React.FC = React.memo(() => { const { withLetters, withNumbers, orientation } = useChessboardProps(); const rows = new Array(8).fill(0).map((_, i) => i); const rowIndexes = orientation === 'black' ? [...rows].reverse() : rows; return ( {rowIndexes.map((rowIdx) => ( ))} ); }); export default Background;