diff --git a/app/components/ArtistArt.tsx b/app/components/ArtistArt.tsx index 9f0336c..2b1e8a3 100644 --- a/app/components/ArtistArt.tsx +++ b/app/components/ArtistArt.tsx @@ -1,11 +1,12 @@ import { useAtomValue } from 'jotai/utils' -import React from 'react' -import { ActivityIndicator, View } from 'react-native' +import React, { useState } from 'react' +import { ActivityIndicator, LayoutChangeEvent, StyleSheet, View } from 'react-native' import FastImage from 'react-native-fast-image' import LinearGradient from 'react-native-linear-gradient' import { artistArtAtomFamily } from '@app/state/music' import colors from '@app/styles/colors' import CoverArt from '@app/components/CoverArt' +import IconFA5 from 'react-native-vector-icons/FontAwesome5' interface ArtistArtSizeProps { height: number @@ -20,26 +21,31 @@ interface ArtistArtProps extends ArtistArtSizeProps { id: string } -const PlaceholderContainer: React.FC = ({ height, width, children }) => ( - - {children} - -) +const PlaceholderContainer: React.FC = ({ height, width, children }) => { + const [layout, setLayout] = useState({ x: 0, y: 0, width: 0, height: 0 }) -const FourUp: React.FC = ({ height, width, coverArtUris }) => { + const onLayout = (event: LayoutChangeEvent) => { + setLayout(event.nativeEvent.layout) + } + + return ( + + + {children} + + ) +} + +const FourUp = React.memo(({ height, width, coverArtUris }) => { const halfHeight = height / 2 const halfWidth = width / 2 return ( - + = ({ height, width, coverArtUris }) => resizeMode={FastImage.resizeMode.cover} /> - + = ({ height, width, coverArtUris }) => ) -} +}) -const ThreeUp: React.FC = ({ height, width, coverArtUris }) => { +const ThreeUp = React.memo(({ height, width, coverArtUris }) => { const halfHeight = height / 2 const halfWidth = width / 2 return ( - + - + = ({ height, width, coverArtUris }) = ) -} +}) -const TwoUp: React.FC = ({ height, width, coverArtUris }) => { +const TwoUp = React.memo(({ height, width, coverArtUris }) => { const halfHeight = height / 2 return ( - + - + = ({ height, width, coverArtUris }) => ) -} +}) -const OneUp: React.FC = ({ height, width, coverArtUris }) => { - return ( - - - - ) -} +const OneUp = React.memo(({ height, width, coverArtUris }) => ( + + + +)) -const NoneUp: React.FC = ({ height, width }) => { - return ( - - - - ) -} +const NoneUp = React.memo(({ height, width }) => ( + +)) -const ArtistArt: React.FC = ({ id, height, width }) => { +const ArtistArt = React.memo(({ id, height, width }) => { const artistArt = useAtomValue(artistArtAtomFamily(id)) const Placeholder = () => { @@ -170,27 +163,17 @@ const ArtistArt: React.FC = ({ id, height, width }) => { } return ( - + ) -} +}) -const ArtistArtFallback: React.FC = ({ height, width }) => ( - - +const ArtistArtFallback = React.memo(({ height, width }) => ( + + -) +)) const ArtistArtLoader: React.FC = props => ( }> @@ -198,4 +181,24 @@ const ArtistArtLoader: React.FC = props => ( ) +const styles = StyleSheet.create({ + placeholderContainer: { + alignItems: 'center', + justifyContent: 'center', + }, + placeholderIcon: { + position: 'absolute', + }, + artRow: { + flexDirection: 'row', + }, + container: { + overflow: 'hidden', + }, + fallback: { + alignItems: 'center', + justifyContent: 'center', + }, +}) + export default React.memo(ArtistArtLoader) diff --git a/app/components/CoverArt.tsx b/app/components/CoverArt.tsx index 1066d9d..069ede4 100644 --- a/app/components/CoverArt.tsx +++ b/app/components/CoverArt.tsx @@ -1,16 +1,20 @@ import React, { useEffect, useState } from 'react' -import { ActivityIndicator, StyleSheet, View } from 'react-native' +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 -}> = ({ PlaceholderComponent, height, width, coverArtUri }) => { +}> = ({ PlaceholderComponent, placeholderIcon, height, width, coverArtUri }) => { 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) { @@ -25,18 +29,27 @@ const CoverArt: React.FC<{ resizeMode={FastImage.resizeMode.contain} onError={() => { setLoading(false) - console.log('asdfdsaf') setPlaceholderVisible(true) }} onLoadEnd={() => setLoading(false)} /> ) + const Placeholder = () => ( + + + + ) + + const onLayout = (event: LayoutChangeEvent) => { + setLayout(event.nativeEvent.layout) + } + return ( - + {coverArtUri ? : <>} - {PlaceholderComponent ? : <>} + {PlaceholderComponent ? : } @@ -54,6 +67,12 @@ const styles = StyleSheet.create({ width: '100%', position: 'absolute', }, + placeholder: { + height: '100%', + width: '100%', + justifyContent: 'center', + alignItems: 'center', + }, indicator: { height: '100%', width: '100%', diff --git a/app/screens/Home.tsx b/app/screens/Home.tsx index d2f0ed5..fdf950c 100644 --- a/app/screens/Home.tsx +++ b/app/screens/Home.tsx @@ -21,12 +21,7 @@ const AlbumItem = React.memo<{ onPress={() => navigation.navigate('AlbumView', { id: album.id, title: album.name })} key={album.id} style={styles.item}> - <>} - coverArtUri={album.coverArtThumbUri} - height={styles.item.width} - width={styles.item.width} - /> + {album.name}