import React, { FC, memo } from 'react'; import { View, Image, Text, TouchableOpacity, } from 'react-native'; import Animated, { useSharedValue, useAnimatedStyle, useDerivedValue, withTiming, } from 'react-native-reanimated'; import { StoryAvatarProps } from '../../core/dto/componentsDTO'; import AvatarStyles from './Avatar.styles'; import Loader from '../Loader'; import { AVATAR_OFFSET } from '../../core/constants'; const AnimatedImage = Animated.createAnimatedComponent( Image ); const StoryAvatar: FC = ( { id, imgUrl, name, stories, loadingStory, seenStories, onPress, colors, seenColors, size, showName, nameTextStyle, } ) => { const loaded = useSharedValue( false ); const isLoading = useDerivedValue( () => loadingStory.value === id || !loaded.value ); const loaderColor = useDerivedValue( () => ( seenStories.value[id] === stories[stories.length - 1]?.id ? seenColors : colors ) ); const onLoad = () => { loaded.value = true; }; const imageAnimatedStyles = useAnimatedStyle( () => ( { opacity: withTiming( isLoading.value ? 0.5 : 1 ) } ) ); return ( {Boolean( showName ) && {name}} ); }; export default memo( StoryAvatar );