Created
May 11, 2020 13:05
-
-
Save renanmav/162e6f6b681735d32e9350c81ebc57f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Image, TouchableWithoutFeedback, View } from 'react-native'; | |
import { t } from 'react-native-tailwindcss'; | |
const s = { | |
wrapper: [t.bgTransparent, t.w4_12, t.p1, { aspectRatio: 1 }], | |
field: [t.bgBlue900, t.rounded, t.flex1, t.itemsCenter, t.justifyCenter, t.overflowHidden], | |
symbol: [t.w8_12, t.objectContain], | |
success: [t.bgGreen900], | |
}; | |
interface TicTacToeFieldProps { | |
symbol: 'X' | 'O' | ' '; | |
onPress: () => void; | |
success?: boolean; | |
} | |
const TicTacToeField: React.FC<TicTacToeFieldProps> = ({ symbol, onPress, success = false }) => { | |
function renderSymbol() { | |
switch (symbol) { | |
case 'X': | |
return <Image source={require('../../../assets/x.png')} style={s.symbol} testID="X" />; | |
case 'O': | |
return <Image source={require('../../../assets/o.png')} style={s.symbol} testID="O" />; | |
default: | |
return null; | |
} | |
} | |
return ( | |
<View style={s.wrapper}> | |
<TouchableWithoutFeedback onPress={onPress} testID="field-touchable"> | |
<View style={[s.field, success && s.success]} testID="field-background"> | |
{renderSymbol()} | |
</View> | |
</TouchableWithoutFeedback> | |
</View> | |
); | |
}; | |
export default TicTacToeField; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment