import React from "react"; import { View, TouchableOpacity, StyleSheet, Platform, } from "react-native"; import { CardProps } from "./types"; import { useTheme } from "../../theme/ThemeContext"; import { LinearGradient } from "expo-linear-gradient"; import { Grayscale } from "react-native-color-matrix-image-filters"; import { ImageBackground } from "expo-image"; import { Pressable } from "react-native-gesture-handler"; const Card: React.FC = ({ children, style, onPress, disabled = false, elevation = 1, testID, variant, backgroundColor, borderColor, borderRadius = 8, backgroundImage, gradient, greyscale = false, gestureHandler }) => { const { theme } = useTheme(); const getCardStyle = () => { const baseStyle: any = { backgroundColor: backgroundColor || theme.background, borderRadius, }; return baseStyle; }; const cardStyle = [ styles.card, getCardStyle(), disabled && { opacity: 0.6 }, style, backgroundImage && { backgroundColor: "transparent" }, ]; const RenderCardContent = () => { if (backgroundImage) { const img = ( {children} ); if (!greyscale) return img; return {img}; } else if (gradient) { return ( {children} ); } else { return children; } }; if (onPress) { if (gestureHandler) { return ( [ cardStyle, pressed && { opacity: 0.9 }, ]} onPress={onPress} disabled={disabled} testID={testID} accessibilityRole="button" accessibilityLabel={"Card"} > {RenderCardContent()} ); } return ( {RenderCardContent()} ); } return ( {RenderCardContent()} ); }; const styles = StyleSheet.create({ card: { borderRadius: 8, flexDirection: "column", display: "flex", }, backgroundImage: { width: "100%", height: "100%", }, imageContentContainer: { flex: 1, backgroundColor: "transparent", }, gradient: { flex: 1, width: "100%", height: "100%", justifyContent: "flex-start", alignItems: "flex-start", }, }); export default Card;