mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 09:09:29 +01:00
probably unnecessery image cache optimizations
This commit is contained in:
parent
a151fe299e
commit
b908dd87f6
@ -113,7 +113,7 @@ const NowPlayingLayout = () => {
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
paddingTop: StatusBar.currentHeight,
|
paddingTop: StatusBar.currentHeight,
|
||||||
}}>
|
}}>
|
||||||
<ImageGradientBackground imageUri={track?.artwork as string} />
|
<ImageGradientBackground imageUri={track?.artworkThumb as string} imageKey={`${track?.album}${track?.artist}`} />
|
||||||
<NowPlayingHeader />
|
<NowPlayingHeader />
|
||||||
<SongCoverArt />
|
<SongCoverArt />
|
||||||
<SongInfo />
|
<SongInfo />
|
||||||
|
|||||||
@ -103,7 +103,8 @@ const AlbumDetails: React.FC<{
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ImageGradientScrollView
|
<ImageGradientScrollView
|
||||||
imageUri={album.coverArtUri}
|
imageUri={album.coverArtThumbUri}
|
||||||
|
imageKey={`${album.name}${album.artist}`}
|
||||||
style={{
|
style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { ViewStyle } from 'react-native';
|
import { ViewStyle } from 'react-native';
|
||||||
|
import FastImage from 'react-native-fast-image';
|
||||||
import ImageColors from 'react-native-image-colors';
|
import ImageColors from 'react-native-image-colors';
|
||||||
import { AndroidImageColors } from 'react-native-image-colors/lib/typescript/types';
|
import { AndroidImageColors } from 'react-native-image-colors/lib/typescript/types';
|
||||||
import colors from '../../styles/colors';
|
import colors from '../../styles/colors';
|
||||||
@ -12,7 +13,8 @@ const ImageGradientBackground: React.FC<{
|
|||||||
position?: 'relative' | 'absolute';
|
position?: 'relative' | 'absolute';
|
||||||
style?: ViewStyle;
|
style?: ViewStyle;
|
||||||
imageUri?: string;
|
imageUri?: string;
|
||||||
}> = ({ height, width, position, style, imageUri, children }) => {
|
imageKey?: string;
|
||||||
|
}> = ({ height, width, position, style, imageUri, imageKey, children }) => {
|
||||||
const [highColor, setHighColor] = useState<string>(colors.gradient.high);
|
const [highColor, setHighColor] = useState<string>(colors.gradient.high);
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
|
||||||
@ -22,13 +24,16 @@ const ImageGradientBackground: React.FC<{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cachedResult = ImageColors.cache.getItem(imageKey ? imageKey : imageUri);
|
||||||
|
|
||||||
let res: AndroidImageColors;
|
let res: AndroidImageColors;
|
||||||
const cachedResult = ImageColors.cache.getItem(imageUri);
|
|
||||||
if (cachedResult) {
|
if (cachedResult) {
|
||||||
res = cachedResult as AndroidImageColors;
|
res = cachedResult as AndroidImageColors;
|
||||||
} else {
|
} else {
|
||||||
res = (await ImageColors.getColors(imageUri, {
|
const path = await FastImage.getCachePath({ uri: imageUri });
|
||||||
|
res = (await ImageColors.getColors(path ? `file://${path}` : imageUri, {
|
||||||
cache: true,
|
cache: true,
|
||||||
|
key: imageKey ? imageKey : imageUri,
|
||||||
})) as AndroidImageColors;
|
})) as AndroidImageColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +44,7 @@ const ImageGradientBackground: React.FC<{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
getColors();
|
getColors();
|
||||||
}, [imageUri]);
|
}, [imageUri, imageKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
navigation.setOptions({
|
navigation.setOptions({
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { LayoutRectangle, ScrollView, ScrollViewProps } from 'react-native';
|
|||||||
import colors from '../../styles/colors';
|
import colors from '../../styles/colors';
|
||||||
import ImageGradientBackground from './ImageGradientBackground';
|
import ImageGradientBackground from './ImageGradientBackground';
|
||||||
|
|
||||||
const ImageGradientScrollView: React.FC<ScrollViewProps & { imageUri?: string }> = props => {
|
const ImageGradientScrollView: React.FC<ScrollViewProps & { imageUri?: string; imageKey?: string }> = props => {
|
||||||
const [layout, setLayout] = useState<LayoutRectangle | undefined>(undefined);
|
const [layout, setLayout] = useState<LayoutRectangle | undefined>(undefined);
|
||||||
|
|
||||||
props.style = props.style || {};
|
props.style = props.style || {};
|
||||||
@ -21,7 +21,7 @@ const ImageGradientScrollView: React.FC<ScrollViewProps & { imageUri?: string }>
|
|||||||
onLayout={event => {
|
onLayout={event => {
|
||||||
setLayout(event.nativeEvent.layout);
|
setLayout(event.nativeEvent.layout);
|
||||||
}}>
|
}}>
|
||||||
<ImageGradientBackground height={layout?.height} imageUri={props.imageUri} />
|
<ImageGradientBackground height={layout?.height} imageUri={props.imageUri} imageKey={props.imageKey} />
|
||||||
{props.children}
|
{props.children}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ function mapSongToTrack(song: Song, queueName: string): Track {
|
|||||||
artist: song.artist || 'Unknown Artist',
|
artist: song.artist || 'Unknown Artist',
|
||||||
url: song.streamUri,
|
url: song.streamUri,
|
||||||
artwork: song.coverArtUri,
|
artwork: song.coverArtUri,
|
||||||
|
artworkThumb: song.coverArtThumbUri,
|
||||||
duration: song.duration,
|
duration: song.duration,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,7 @@ export interface Song {
|
|||||||
|
|
||||||
streamUri: string;
|
streamUri: string;
|
||||||
coverArtUri?: string;
|
coverArtUri?: string;
|
||||||
|
coverArtThumbUri?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DownloadedSong = {
|
export type DownloadedSong = {
|
||||||
|
|||||||
@ -188,6 +188,7 @@ function mapChildToSong(child: ChildElement, client: SubsonicApiClient): Song {
|
|||||||
...child,
|
...child,
|
||||||
streamUri: client.streamUri({ id: child.id }),
|
streamUri: client.streamUri({ id: child.id }),
|
||||||
coverArtUri: child.coverArt ? client.getCoverArtUri({ id: child.coverArt }) : undefined,
|
coverArtUri: child.coverArt ? client.getCoverArtUri({ id: child.coverArt }) : undefined,
|
||||||
|
coverArtThumbUri: child.coverArt ? client.getCoverArtUri({ id: child.coverArt, size: '256' }) : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5401,7 +5401,7 @@ react-native-codegen@^0.0.6:
|
|||||||
|
|
||||||
"react-native-fast-image@https://github.com/austinried/react-native-fast-image":
|
"react-native-fast-image@https://github.com/austinried/react-native-fast-image":
|
||||||
version "8.3.4"
|
version "8.3.4"
|
||||||
resolved "https://github.com/austinried/react-native-fast-image#65b70ba8f21971265c56e4adba4981a9bbb6499a"
|
resolved "https://github.com/austinried/react-native-fast-image#2aa1ec7425e70927e179640fc8eb2a7c268357a3"
|
||||||
|
|
||||||
react-native-fs@^2.18.0:
|
react-native-fs@^2.18.0:
|
||||||
version "2.18.0"
|
version "2.18.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user