import React, { useEffect, useState } from 'react' import { ActivityIndicator, LayoutChangeEvent, StyleSheet, View } from 'react-native' import FastImage from 'react-native-fast-image' import colors from '@app/styles/colors' import IconFA5 from 'react-native-vector-icons/FontAwesome5' import LinearGradient from 'react-native-linear-gradient' const CoverArt: React.FC<{ PlaceholderComponent?: () => JSX.Element placeholderIcon?: string height?: string | number width?: string | number coverArtUri?: string resizeMode?: keyof typeof FastImage.resizeMode }> = ({ PlaceholderComponent, placeholderIcon, height, width, coverArtUri, resizeMode }) => { const [placeholderVisible, setPlaceholderVisible] = useState(false) const [loading, setLoading] = useState(true) const [layout, setLayout] = useState({ x: 0, y: 0, width: 0, height: 0 }) useEffect(() => { if (!coverArtUri) { setLoading(false) } }, [coverArtUri, setLoading]) const Image = () => ( { setLoading(false) setPlaceholderVisible(true) }} onLoadEnd={() => setLoading(false)} /> ) const Placeholder = () => ( ) const onLayout = (event: LayoutChangeEvent) => { setLayout(event.nativeEvent.layout) } return ( {coverArtUri ? : <>} {PlaceholderComponent ? : } ) } const styles = StyleSheet.create({ container: {}, image: { height: '100%', width: '100%', }, placeholderContainer: { height: '100%', width: '100%', position: 'absolute', }, placeholder: { height: '100%', width: '100%', justifyContent: 'center', alignItems: 'center', }, indicator: { height: '100%', width: '100%', position: 'absolute', }, }) export default React.memo(CoverArt)