(1) Fix missing image on first track

(2) Dial back the updates in useCurrentTrack
This commit is contained in:
Lei Nelissen
2020-08-25 23:34:35 +02:00
parent edce0329cf
commit 6e85013b5a
2 changed files with 16 additions and 4 deletions

View File

@@ -12,8 +12,6 @@ const Artwork = styled(FastImage)`
width: ${Screen.width * 0.8}px;
height: ${Screen.width * 0.8}px;
margin: 25px auto;
display: flex;
flex: 1;
`;
const styles = StyleSheet.create({
@@ -36,10 +34,17 @@ const styles = StyleSheet.create({
export default function NowPlaying() {
const track = useCurrentTrack();
console.log(track?.artwork);
return (
<View style={{ alignItems: 'center' }}>
<Artwork style={colors.imageBackground} source={{ uri: track?.artwork }} />
<Artwork
style={colors.imageBackground}
source={{
uri: track?.artwork,
priority: FastImage.priority.high,
}}
/>
<Text style={styles.artist} >{track?.artist}</Text>
<Text style={styles.title}>{track?.title}</Text>
</View>

View File

@@ -17,12 +17,19 @@ export default function useCurrentTrack(): Track | undefined {
return;
}
// GUARD: Only retrieve new track if it is different from the one we
// have currently in state.
if (currentTrackId === track?.id){
return;
}
// If it is different, retrieve the track and save it
const currentTrack = await TrackPlayer.getTrack(currentTrackId);
setTrack(currentTrack);
};
fetchTrack();
}, [state]);
}, [state, track, setTrack]);
return track;
}