import { useEffect, useRef } from 'react'; import { Animated, Easing, Text, View } from 'react-native'; import { RiveAvatar, type Emotion } from '../RiveAvatar'; import { useColors } from '../../lib/theme'; /** * Lyra-Mascot (animiertes Rive-Avatar) links + Speech-Bubble rechts. * Fade+slide-in beim Mount und bei text-change (key-prop verwenden für Re-Animate). * * Layout entspricht Duolingo's Duo-Speech-Pattern: Avatar quadratisch links, * Bubble organisch rechts mit "Tail" zum Avatar zeigend. */ export function LyraBubble({ text, emotion = 'idle', }: { text: string; /** Lyra-Emotion fürs Rive (idle, happy, thinking, empathy). */ emotion?: Emotion; }) { const colors = useColors(); const opacity = useRef(new Animated.Value(0)).current; const translateX = useRef(new Animated.Value(-12)).current; useEffect(() => { opacity.setValue(0); translateX.setValue(-12); Animated.parallel([ Animated.timing(opacity, { toValue: 1, duration: 400, useNativeDriver: true, easing: Easing.out(Easing.cubic), }), Animated.spring(translateX, { toValue: 0, useNativeDriver: true, friction: 7, tension: 80, }), ]).start(); }, [text, opacity, translateX]); return ( {/* Speech-Bubble */} {text} ); }