mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-29 09:29:29 +01:00
imprv CoverArt perf and interface
This commit is contained in:
parent
62b27974a7
commit
e6c76776a3
@ -1,11 +1,12 @@
|
|||||||
import { useAtomValue } from 'jotai/utils'
|
import CoverArt from '@app/components/CoverArt'
|
||||||
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 { artistArtAtomFamily } from '@app/state/music'
|
||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import CoverArt from '@app/components/CoverArt'
|
import { useLayout } from '@react-native-community/hooks'
|
||||||
|
import { useAtomValue } from 'jotai/utils'
|
||||||
|
import React from 'react'
|
||||||
|
import { ActivityIndicator, StyleSheet, View } from 'react-native'
|
||||||
|
import FastImage from 'react-native-fast-image'
|
||||||
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
||||||
|
|
||||||
interface ArtistArtSizeProps {
|
interface ArtistArtSizeProps {
|
||||||
@ -23,15 +24,11 @@ interface ArtistArtProps extends ArtistArtSizeProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const PlaceholderContainer: React.FC<ArtistArtSizeProps> = ({ height, width, children }) => {
|
const PlaceholderContainer: React.FC<ArtistArtSizeProps> = ({ height, width, children }) => {
|
||||||
const [layout, setLayout] = useState({ x: 0, y: 0, width: 0, height: 0 })
|
const layout = useLayout()
|
||||||
|
|
||||||
const onLayout = (event: LayoutChangeEvent) => {
|
|
||||||
setLayout(event.nativeEvent.layout)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LinearGradient
|
<LinearGradient
|
||||||
onLayout={onLayout}
|
onLayout={layout.onLayout}
|
||||||
colors={[colors.accent, colors.accentLow]}
|
colors={[colors.accent, colors.accentLow]}
|
||||||
style={[styles.placeholderContainer, { height, width }]}>
|
style={[styles.placeholderContainer, { height, width }]}>
|
||||||
<IconFA5 name="microphone" color="black" size={layout.width / 1.8} style={styles.placeholderIcon} />
|
<IconFA5 name="microphone" color="black" size={layout.width / 1.8} style={styles.placeholderIcon} />
|
||||||
@ -142,10 +139,8 @@ const ArtistArt = React.memo<ArtistArtProps>(({ id, height, width, round }) => {
|
|||||||
round = round === undefined ? true : round
|
round = round === undefined ? true : round
|
||||||
|
|
||||||
const Placeholder = () => {
|
const Placeholder = () => {
|
||||||
const none = <NoneUp height={height} width={width} />
|
if (!artistArt) {
|
||||||
|
return <NoneUp height={height} width={width} />
|
||||||
if (!artistArt || !artistArt.albumCoverUris) {
|
|
||||||
return none
|
|
||||||
}
|
}
|
||||||
const { albumCoverUris } = artistArt
|
const { albumCoverUris } = artistArt
|
||||||
|
|
||||||
@ -162,15 +157,14 @@ const ArtistArt = React.memo<ArtistArtProps>(({ id, height, width, round }) => {
|
|||||||
return <OneUp height={height} width={width} albumCoverUris={albumCoverUris} />
|
return <OneUp height={height} width={width} albumCoverUris={albumCoverUris} />
|
||||||
}
|
}
|
||||||
|
|
||||||
return none
|
return <NoneUp height={height} width={width} />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.container, round ? { borderRadius: height / 2 } : {}]}>
|
<View style={[styles.container, round ? { borderRadius: height / 2 } : {}]}>
|
||||||
<CoverArt
|
<CoverArt
|
||||||
PlaceholderComponent={Placeholder}
|
FallbackComponent={Placeholder}
|
||||||
height={height}
|
style={{ height, width }}
|
||||||
width={width}
|
|
||||||
coverArtUri={artistArt?.uri}
|
coverArtUri={artistArt?.uri}
|
||||||
resizeMode={FastImage.resizeMode.cover}
|
resizeMode={FastImage.resizeMode.cover}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,77 +1,84 @@
|
|||||||
import React, { useEffect, useState } from 'react'
|
|
||||||
import { ActivityIndicator, LayoutChangeEvent, StyleSheet, View, ViewStyle } from 'react-native'
|
|
||||||
import FastImage from 'react-native-fast-image'
|
|
||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import IconFA5 from 'react-native-vector-icons/FontAwesome5'
|
import React, { useState } from 'react'
|
||||||
|
import { ActivityIndicator, StyleSheet, View } from 'react-native'
|
||||||
|
import FastImage, { ImageStyle } from 'react-native-fast-image'
|
||||||
import LinearGradient from 'react-native-linear-gradient'
|
import LinearGradient from 'react-native-linear-gradient'
|
||||||
|
|
||||||
|
type CoverImageProps = {
|
||||||
|
uri?: string
|
||||||
|
style?: ImageStyle
|
||||||
|
resizeMode?: keyof typeof FastImage.resizeMode
|
||||||
|
onProgress?: () => void
|
||||||
|
onLoadEnd?: () => void
|
||||||
|
onError?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const CoverImage = React.memo<CoverImageProps>(({ uri, style, resizeMode, onProgress, onLoadEnd, onError }) => (
|
||||||
|
<FastImage
|
||||||
|
source={{ uri }}
|
||||||
|
style={style}
|
||||||
|
resizeMode={resizeMode || FastImage.resizeMode.contain}
|
||||||
|
onProgress={onProgress}
|
||||||
|
onLoadEnd={onLoadEnd}
|
||||||
|
onError={onError}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
|
||||||
|
const Fallback = React.memo<{}>(({}) => {
|
||||||
|
return <LinearGradient colors={[colors.accent, colors.accentLow]} style={styles.fallback} />
|
||||||
|
})
|
||||||
|
|
||||||
const CoverArt: React.FC<{
|
const CoverArt: React.FC<{
|
||||||
PlaceholderComponent?: () => JSX.Element
|
FallbackComponent?: () => JSX.Element
|
||||||
placeholderIcon?: string
|
placeholderIcon?: string
|
||||||
height?: string | number
|
height?: string | number
|
||||||
width?: string | number
|
width?: string | number
|
||||||
coverArtUri?: string
|
coverArtUri?: string
|
||||||
resizeMode?: keyof typeof FastImage.resizeMode
|
resizeMode?: keyof typeof FastImage.resizeMode
|
||||||
style?: ViewStyle
|
style?: ImageStyle
|
||||||
}> = ({ PlaceholderComponent, placeholderIcon, height, width, coverArtUri, resizeMode, style }) => {
|
}> = ({ FallbackComponent, coverArtUri, resizeMode, style }) => {
|
||||||
const [placeholderVisible, setPlaceholderVisible] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [loading, setLoading] = useState(true)
|
const [fallbackVisible, setFallbackVisible] = useState(false)
|
||||||
const [layout, setLayout] = useState({ x: 0, y: 0, width: 0, height: 0 })
|
|
||||||
|
|
||||||
useEffect(() => {
|
const enableLoading = React.useCallback(() => setLoading(true), [])
|
||||||
if (!coverArtUri) {
|
const disableLoading = React.useCallback(() => setLoading(false), [])
|
||||||
setLoading(false)
|
const enableFallback = React.useCallback(() => setFallbackVisible(true), [])
|
||||||
}
|
|
||||||
}, [coverArtUri, setLoading])
|
|
||||||
|
|
||||||
const Image = () => (
|
|
||||||
<FastImage
|
|
||||||
source={{ uri: coverArtUri, priority: 'high' }}
|
|
||||||
style={{ ...styles.image, opacity: placeholderVisible ? 0 : 1 }}
|
|
||||||
resizeMode={resizeMode || FastImage.resizeMode.contain}
|
|
||||||
onError={() => {
|
|
||||||
setLoading(false)
|
|
||||||
setPlaceholderVisible(true)
|
|
||||||
}}
|
|
||||||
onLoadEnd={() => setLoading(false)}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
|
|
||||||
const Placeholder = () => (
|
|
||||||
<LinearGradient colors={[colors.accent, colors.accentLow]} style={styles.placeholder}>
|
|
||||||
<IconFA5 name={placeholderIcon || 'record-vinyl'} color="black" size={layout.width / 1.5} />
|
|
||||||
</LinearGradient>
|
|
||||||
)
|
|
||||||
|
|
||||||
const onLayout = (event: LayoutChangeEvent) => {
|
|
||||||
setLayout(event.nativeEvent.layout)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[style, { height, width }]} onLayout={onLayout}>
|
<View style={style}>
|
||||||
{coverArtUri ? <Image /> : <></>}
|
<CoverImage
|
||||||
<View style={{ ...styles.placeholderContainer, opacity: placeholderVisible ? 1 : 0 }}>
|
uri={coverArtUri}
|
||||||
{PlaceholderComponent ? <PlaceholderComponent /> : <Placeholder />}
|
style={style}
|
||||||
</View>
|
resizeMode={resizeMode}
|
||||||
<ActivityIndicator style={styles.indicator} animating={loading} size={'large'} color={colors.accent} />
|
onProgress={enableLoading}
|
||||||
|
onLoadEnd={disableLoading}
|
||||||
|
onError={enableFallback}
|
||||||
|
/>
|
||||||
|
{fallbackVisible ? (
|
||||||
|
FallbackComponent ? (
|
||||||
|
<View style={styles.fallback}>
|
||||||
|
<FallbackComponent />
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<Fallback />
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
)}
|
||||||
|
<ActivityIndicator animating={loading} size="large" color={colors.accent} style={styles.indicator} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {},
|
|
||||||
image: {
|
image: {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
},
|
},
|
||||||
placeholderContainer: {
|
fallback: {
|
||||||
height: '100%',
|
height: '100%',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
},
|
|
||||||
placeholder: {
|
|
||||||
height: '100%',
|
|
||||||
width: '100%',
|
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
|
|||||||
@ -69,8 +69,7 @@ const NowPlayingBar = () => {
|
|||||||
<ProgressBar />
|
<ProgressBar />
|
||||||
<View style={styles.subContainer}>
|
<View style={styles.subContainer}>
|
||||||
<CoverArt
|
<CoverArt
|
||||||
height={styles.subContainer.height}
|
style={{ height: styles.subContainer.height, width: styles.subContainer.height }}
|
||||||
width={styles.subContainer.height}
|
|
||||||
coverArtUri={track?.artworkThumb}
|
coverArtUri={track?.artworkThumb}
|
||||||
/>
|
/>
|
||||||
<View style={styles.detailsContainer}>
|
<View style={styles.detailsContainer}>
|
||||||
|
|||||||
@ -23,7 +23,7 @@ const SongItem: React.FC<{
|
|||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<PressableOpacity onPress={onPress} style={styles.item}>
|
<PressableOpacity onPress={onPress} style={styles.item}>
|
||||||
{showArt ? <CoverArt coverArtUri={song.coverArtThumbUri} style={styles.art} height={50} width={50} /> : <></>}
|
{showArt ? <CoverArt coverArtUri={song.coverArtThumbUri} style={styles.art} /> : <></>}
|
||||||
<View style={styles.text}>
|
<View style={styles.text}>
|
||||||
<Text style={[styles.title, { color: currentTrack?.id === song.id ? colors.accent : colors.text.primary }]}>
|
<Text style={[styles.title, { color: currentTrack?.id === song.id ? colors.accent : colors.text.primary }]}>
|
||||||
{song.title}
|
{song.title}
|
||||||
@ -58,6 +58,8 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
art: {
|
art: {
|
||||||
marginRight: 10,
|
marginRight: 10,
|
||||||
|
height: 50,
|
||||||
|
width: 50,
|
||||||
},
|
},
|
||||||
text: {
|
text: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
@ -28,9 +28,7 @@ const AlbumDetails: React.FC<{
|
|||||||
imageKey={`${album.name}${album.artist}`}
|
imageKey={`${album.name}${album.artist}`}
|
||||||
style={styles.container}>
|
style={styles.container}>
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
<View style={styles.cover}>
|
<CoverArt coverArtUri={album.coverArtUri} style={styles.cover} />
|
||||||
<CoverArt coverArtUri={album.coverArtUri} height="100%" width="100%" />
|
|
||||||
</View>
|
|
||||||
<Text style={styles.title}>{album.name}</Text>
|
<Text style={styles.title}>{album.name}</Text>
|
||||||
<Text style={styles.subtitle}>
|
<Text style={styles.subtitle}>
|
||||||
{album.artist}
|
{album.artist}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ const AlbumItem = React.memo<{
|
|||||||
<PressableOpacity
|
<PressableOpacity
|
||||||
onPress={() => navigation.navigate('AlbumView', { id: album.id, title: album.name })}
|
onPress={() => navigation.navigate('AlbumView', { id: album.id, title: album.name })}
|
||||||
style={[styles.albumItem, { width }]}>
|
style={[styles.albumItem, { width }]}>
|
||||||
<CoverArt coverArtUri={album.coverArtThumbUri} height={height} width={width} />
|
<CoverArt coverArtUri={album.coverArtThumbUri} style={{ height, width }} />
|
||||||
<Text style={styles.albumTitle}>{album.name}</Text>
|
<Text style={styles.albumTitle}>{album.name}</Text>
|
||||||
<Text style={styles.albumYear}> {album.year ? album.year : ''}</Text>
|
<Text style={styles.albumYear}> {album.year ? album.year : ''}</Text>
|
||||||
</PressableOpacity>
|
</PressableOpacity>
|
||||||
@ -73,11 +73,9 @@ const ArtistDetails: React.FC<{ id: string }> = ({ id }) => {
|
|||||||
style={styles.scroll}
|
style={styles.scroll}
|
||||||
contentContainerStyle={styles.scrollContent}>
|
contentContainerStyle={styles.scrollContent}>
|
||||||
<CoverArt
|
<CoverArt
|
||||||
PlaceholderComponent={ArtistCoverFallback}
|
FallbackComponent={ArtistCoverFallback}
|
||||||
coverArtUri={artist.largeImageUrl}
|
coverArtUri={artist.largeImageUrl}
|
||||||
style={styles.artistCover}
|
style={styles.artistCover}
|
||||||
height={artistCoverHeight}
|
|
||||||
width={coverLayout.width}
|
|
||||||
resizeMode={FastImage.resizeMode.cover}
|
resizeMode={FastImage.resizeMode.cover}
|
||||||
/>
|
/>
|
||||||
<View style={styles.titleContainer}>
|
<View style={styles.titleContainer}>
|
||||||
@ -151,8 +149,8 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
artistCover: {
|
artistCover: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
width: '100%',
|
|
||||||
height: artistCoverHeight,
|
height: artistCoverHeight,
|
||||||
|
width: '100%',
|
||||||
},
|
},
|
||||||
albums: {
|
albums: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
|
|||||||
@ -6,11 +6,19 @@ import { homeListsAtom, homeListsUpdatingAtom, useUpdateHomeLists } from '@app/s
|
|||||||
import { homeListTypesAtom, useActiveServerRefresh } from '@app/state/settings'
|
import { homeListTypesAtom, useActiveServerRefresh } from '@app/state/settings'
|
||||||
import colors from '@app/styles/colors'
|
import colors from '@app/styles/colors'
|
||||||
import font from '@app/styles/font'
|
import font from '@app/styles/font'
|
||||||
|
import { GetAlbumListType } from '@app/subsonic/params'
|
||||||
import { useNavigation } from '@react-navigation/native'
|
import { useNavigation } from '@react-navigation/native'
|
||||||
import { useAtomValue } from 'jotai/utils'
|
import { useAtomValue } from 'jotai/utils'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { RefreshControl, ScrollView, StatusBar, StyleSheet, Text, View } from 'react-native'
|
import { RefreshControl, ScrollView, StatusBar, StyleSheet, Text, View } from 'react-native'
|
||||||
|
|
||||||
|
const titles: { [key in GetAlbumListType]?: string } = {
|
||||||
|
recent: 'Recent Albums',
|
||||||
|
random: 'Random Albums',
|
||||||
|
frequent: 'Frequent Albums',
|
||||||
|
starred: 'Starred Albums',
|
||||||
|
}
|
||||||
|
|
||||||
const AlbumItem = React.memo<{
|
const AlbumItem = React.memo<{
|
||||||
album: AlbumListItem
|
album: AlbumListItem
|
||||||
}>(({ album }) => {
|
}>(({ album }) => {
|
||||||
@ -21,7 +29,7 @@ const AlbumItem = React.memo<{
|
|||||||
onPress={() => navigation.navigate('AlbumView', { id: album.id, title: album.name })}
|
onPress={() => navigation.navigate('AlbumView', { id: album.id, title: album.name })}
|
||||||
key={album.id}
|
key={album.id}
|
||||||
style={styles.item}>
|
style={styles.item}>
|
||||||
<CoverArt coverArtUri={album.coverArtThumbUri} height={styles.item.width} width={styles.item.width} />
|
<CoverArt coverArtUri={album.coverArtThumbUri} style={{ height: styles.item.width, width: styles.item.width }} />
|
||||||
<Text style={styles.title} numberOfLines={1}>
|
<Text style={styles.title} numberOfLines={1}>
|
||||||
{album.name}
|
{album.name}
|
||||||
</Text>
|
</Text>
|
||||||
@ -33,7 +41,7 @@ const AlbumItem = React.memo<{
|
|||||||
})
|
})
|
||||||
|
|
||||||
const Category = React.memo<{
|
const Category = React.memo<{
|
||||||
name: string
|
name?: string
|
||||||
data: AlbumListItem[]
|
data: AlbumListItem[]
|
||||||
}>(({ name, data }) => {
|
}>(({ name, data }) => {
|
||||||
return (
|
return (
|
||||||
@ -75,7 +83,7 @@ const Home = () => {
|
|||||||
}>
|
}>
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
{types.map(type => (
|
{types.map(type => (
|
||||||
<Category key={type} name={type} data={type in lists ? lists[type] : []} />
|
<Category key={type} name={titles[type as GetAlbumListType]} data={type in lists ? lists[type] : []} />
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
</GradientScrollView>
|
</GradientScrollView>
|
||||||
|
|||||||
@ -25,7 +25,7 @@ const AlbumItem = React.memo<{
|
|||||||
<PressableOpacity
|
<PressableOpacity
|
||||||
style={[styles.item, { maxWidth: size, height }]}
|
style={[styles.item, { maxWidth: size, height }]}
|
||||||
onPress={() => navigation.navigate('AlbumView', { id, title: name })}>
|
onPress={() => navigation.navigate('AlbumView', { id, title: name })}>
|
||||||
<CoverArt coverArtUri={coverArtUri} height={size} width={size} />
|
<CoverArt coverArtUri={coverArtUri} style={{ height: size, width: size }} />
|
||||||
<View style={styles.itemDetails}>
|
<View style={styles.itemDetails}>
|
||||||
<Text style={styles.title} numberOfLines={1}>
|
<Text style={styles.title} numberOfLines={1}>
|
||||||
{name}
|
{name}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ const SongCoverArt = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={coverArtStyles.container}>
|
<View style={coverArtStyles.container}>
|
||||||
<CoverArt height="100%" width="100%" coverArtUri={track?.artwork as string} />
|
<CoverArt coverArtUri={track?.artwork as string} style={coverArtStyles.image} />
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -84,6 +84,10 @@ const coverArtStyles = StyleSheet.create({
|
|||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
paddingBottom: 20,
|
paddingBottom: 20,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const SongInfo = () => {
|
const SongInfo = () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user