import { Image } from 'expo-image'; import { LinearGradient } from 'expo-linear-gradient'; import { useEffect } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import Animated, { Easing, cancelAnimation, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from 'react-native-reanimated'; import type { UserSummaryDTO } from '@musicshare/shared'; import { colors, fonts } from '@/lib/theme'; /** `live` wraps the avatar in a spinning gradient ring (someone is listening right now). */ export function Avatar({ user, size = 40, live }: { user: UserSummaryDTO; size?: number; live?: boolean }) { const rotation = useSharedValue(0); useEffect(() => { if (live) rotation.set(withRepeat(withTiming(360, { duration: 3500, easing: Easing.linear }), -1, false)); else cancelAnimation(rotation); return () => cancelAnimation(rotation); }, [live, rotation]); const spin = useAnimatedStyle(() => ({ transform: [{ rotate: `${rotation.value}deg` }] })); const shape = { width: size, height: size, borderRadius: size / 2 }; const face = user.avatarUrl ? ( ) : ( {(user.displayName ?? user.username).slice(0, 1).toUpperCase()} ); if (!live) return face; const ring = size + 6; return ( {face} ); } const styles = StyleSheet.create({ empty: { alignItems: 'center', justifyContent: 'center' }, letter: { color: '#fff', fontFamily: fonts.display }, });