修复本地歌曲封面无法显示背景的问题

This commit is contained in:
lyswhut 2023-12-17 20:05:35 +08:00
parent ba96774ecc
commit fa879a8c4e
2 changed files with 21 additions and 16 deletions

View File

@ -11,6 +11,9 @@ interface Props {
children: React.ReactNode
}
const formatUri = <T extends string | null>(url: T) => {
return (typeof url == 'string' && url.startsWith('/')) ? `file://${url}` : url
}
export default ({ children }: Props) => {
const theme = useTheme()
@ -45,7 +48,7 @@ export default ({ children }: Props) => {
console.log('picUpdated', playerState.musicInfo.pic)
pic = playerState.musicInfo.pic
if (!isDynamicBg) return
void Image.prefetch(playerState.musicInfo.pic).then(() => {
void Image.prefetch(formatUri(playerState.musicInfo.pic)).then(() => {
if (pic != playerState.musicInfo.pic || isUnmounted) return
setPic(playerState.musicInfo.pic)
}).catch(() => {
@ -90,11 +93,12 @@ export default ({ children }: Props) => {
</View>
</View>
), [children, theme, windowSize.height, windowSize.width])
const picComponent = useMemo(() => (
const picComponent = useMemo(() => {
return (
<View style={{ flex: 1, overflow: 'hidden' }}>
<ImageBackground
style={{ position: 'absolute', left: 0, top: 0, height: windowSize.height, width: windowSize.width, backgroundColor: theme['c-content-background'] }}
source={{ uri: pic! }}
source={{ uri: formatUri(pic!) }}
resizeMode="cover"
blurRadius={30}
>
@ -104,7 +108,8 @@ export default ({ children }: Props) => {
{children}
</View>
</View>
), [children, pic, theme, windowSize.height, windowSize.width])
)
}, [children, pic, theme, windowSize.height, windowSize.width])
return pic ? picComponent : themeComponent
}

View File

@ -240,7 +240,7 @@ const styles = createStyle({
inputContent: {
marginTop: 8,
flex: 1,
// flexDirection: 'row',
flexDirection: 'row',
alignItems: 'center',
},
input: {