import { Image, ImageBackground, Platform, StyleSheet, Text, View, type ImageSourcePropType, type ViewStyle, } from 'react-native'; import FlipCard from 'react-native-flip-card'; import Icons from './Icons'; import { useMemo } from 'react'; import type { CreditCardIssuer } from './useCreditCardForm'; const CARD_SIZE = { width: 300, height: 190 }; const s = StyleSheet.create({ cardContainer: {}, cardFace: { backgroundColor: '#444', borderRadius: 10, }, cardMagneticStripe: { position: 'absolute', left: 0, right: 0, top: 30, height: 40, backgroundColor: '#000', }, icon: { position: 'absolute', top: 15, right: 15, width: 60, height: 40, resizeMode: 'contain', }, baseText: { color: 'rgba(255, 255, 255, 0.5)', backgroundColor: 'transparent', }, placeholder: { color: 'rgba(255, 255, 255, 0.5)', }, focusedField: { fontWeight: 'bold', color: 'rgba(255, 255, 255, 1)', }, number: { fontSize: 21, position: 'absolute', top: 95, left: 28, }, name: { fontSize: 16, position: 'absolute', bottom: 20, left: 25, right: 100, }, expiryLabel: { fontSize: 9, position: 'absolute', bottom: 40, left: 218, }, expiry: { fontSize: 16, position: 'absolute', bottom: 20, left: 220, }, amexCVC: { fontSize: 16, position: 'absolute', top: 73, right: 30, }, cvc: { fontSize: 16, position: 'absolute', top: 80, right: 30, }, }); interface Props { focusedField?: 'name' | 'number' | 'expiry' | 'cvc'; type?: CreditCardIssuer; name?: string; number?: string; expiry?: string; cvc?: string; placeholders?: { number: string; expiry: string; cvc: string; name: string; }; style?: ViewStyle; fontFamily?: string; imageFront?: ImageSourcePropType; imageBack?: ImageSourcePropType; } const CreditCardView = (props: Props) => { const { focusedField, type, name, number, expiry, cvc, placeholders = { number: '•••• •••• •••• ••••', name: '', expiry: '••/••', cvc: '•••', }, imageFront, imageBack, fontFamily = Platform.select({ ios: 'Courier', android: 'monospace', web: 'monospace', }), style, } = props; const isAmex = type === 'american-express'; const shouldShowCardBack = !isAmex && focusedField === 'cvc'; const cardIcon = useMemo(() => { if (type && Icons[type]) return Icons[type]; return null; }, [type]); return ( {!!cardIcon && ( )} {!number ? placeholders.number : number} {!name ? placeholders.name : name.toUpperCase()} MONTH/YEAR {!expiry ? placeholders.expiry : expiry} {isAmex && ( {!cvc ? placeholders.cvc : cvc} )} {!cvc ? placeholders.cvc : cvc} ); }; export default CreditCardView;