import React, { useEffect, useRef } from 'react'; import { Animated, Text, Pressable, StyleSheet, View } from 'react-native'; import { useTheme } from '../../theme/useTheme'; import type { NovaTheme } from '../../theme/types'; import type { ToastItem, ToastType } from './Toast.types'; function getToastColors( theme: NovaTheme, type: ToastType ): { bg: string; border: string; text: string; icon: string } { const map: Record = { success: { bg: theme.colors.successLight + '20', border: theme.colors.success, text: theme.dark ? theme.colors.successLight : theme.colors.successDark, icon: '✓', }, error: { bg: theme.colors.errorLight + '20', border: theme.colors.error, text: theme.dark ? theme.colors.errorLight : theme.colors.errorDark, icon: '✕', }, warning: { bg: theme.colors.warningLight + '20', border: theme.colors.warning, text: theme.dark ? theme.colors.warningLight : theme.colors.warningDark, icon: '⚠', }, info: { bg: theme.colors.infoLight + '20', border: theme.colors.info, text: theme.dark ? theme.colors.infoLight : theme.colors.infoDark, icon: 'ℹ', }, }; return map[type]; } interface ToastCardProps { toast: ToastItem; onDismiss: (id: string) => void; } export const ToastCard: React.FC = ({ toast, onDismiss }) => { const theme = useTheme(); const translateY = useRef(new Animated.Value(-20)).current; const opacity = useRef(new Animated.Value(0)).current; useEffect(() => { Animated.parallel([ Animated.timing(translateY, { toValue: 0, duration: 250, useNativeDriver: true, }), Animated.timing(opacity, { toValue: 1, duration: 250, useNativeDriver: true, }), ]).start(); }, [translateY, opacity]); const colors = getToastColors(theme, toast.type); return ( { toast.onPress?.(); onDismiss(toast.id); }} > {colors.icon} {toast.title} {toast.description && ( {toast.description} )} onDismiss(toast.id)} hitSlop={8} style={styles.dismissBtn} > ); }; const styles = StyleSheet.create({ toast: { overflow: 'hidden', }, content: { flexDirection: 'row', alignItems: 'center', padding: 12, }, iconContainer: { marginRight: 10, }, icon: { fontSize: 16, }, textContainer: { flex: 1, }, dismissBtn: { padding: 4, marginLeft: 8, }, });