import {useCallback, useEffect} from 'react' import {type StyleProp, View, type ViewStyle} from 'react-native' import Animated, { Easing, interpolate, type SharedValue, useAnimatedStyle, useSharedValue, withDelay, withTiming, } from 'react-native-reanimated' import {useSession} from '#/state/session' import {UserAvatar} from '#/view/com/util/UserAvatar' import {atoms as a, useTheme} from '#/alf' import {Person_Filled_Corner2_Rounded as PersonIcon} from '#/components/icons/Person' import type * as bsky from '#/types/bsky' type Props = { animate?: boolean profiles: bsky.profile.AnyProfileView[] size?: 'small' | 'medium' | 'large' | number } export function AvatarBubbles({ animate = false, profiles: allProfiles, size = 'large', }: Props) { const {currentAccount} = useSession() const profiles = allProfiles.length > 2 ? allProfiles.filter(p => p.did !== currentAccount?.did) : allProfiles const containerSize = typeof size === 'number' ? size : size === 'small' ? 40 : size === 'medium' ? 56 : 120 const scale = typeof size === 'number' ? size / 120 : size === 'small' ? 40 / 120 : size === 'medium' ? 56 / 120 : 1 const marginOffset = (typeof size === 'number' && size < 120) || size === 'small' || size === 'medium' ? -2 : 0 const initialValue = animate ? 0 : 1 const p0 = useSharedValue(initialValue) const p1 = useSharedValue(initialValue) const p2 = useSharedValue(initialValue) const p3 = useSharedValue(initialValue) const animateScale = (p: Animated.SharedValue, index: number) => { p.set(0) p.set(() => withDelay( 500 + index * 100, withTiming(1, { duration: 250, easing: Easing.out(Easing.back(1.75)), }), ), ) } const playScaleAnimation = useCallback(() => { animateScale(p0, 0) animateScale(p1, 1) animateScale(p2, 2) animateScale(p3, 3) }, [p0, p1, p2, p3]) useEffect(() => { if (!animate) return playScaleAnimation() }, [animate, playScaleAnimation]) let avatars = ( <> ) if (profiles.length === 3) { avatars = ( <> ) } if (profiles.length >= 4) { avatars = ( <> ) } return ( {avatars} ) } function AvatarBubble({ profile, scale, size, style, x, y, includeProfileBorder, }: { profile?: bsky.profile.AnyProfileView scale: SharedValue size: number style?: StyleProp x: number y: number includeProfileBorder?: boolean }) { const t = useTheme() const animatedStyle = useAnimatedStyle(() => ({ transform: [ {translateX: x}, {translateY: y}, {scale: interpolate(scale.get(), [0, 1], [0, 1])}, ], })) return ( {profile ? ( ) : ( )} ) } function Avatar({ profile, size = 76, }: { profile: bsky.profile.AnyProfileView size?: number }) { return ( ) } function AvatarPlaceholder({size = 76}: {size?: number}) { const t = useTheme() return ( ) }