-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from lovegaoshi/dev
feat: accent color
- Loading branch information
Showing
20 changed files
with
710 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
import useAccentColor from '@hooks/useAccentColor'; | ||
|
||
export default ({ children }: { children: React.JSX.Element }) => { | ||
const { backgroundColor } = useAccentColor(); | ||
|
||
return <View style={{ backgroundColor, flex: 1 }}>{children}</View>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
import { useNoxSetting } from '@stores/useApp'; | ||
import useAccentColor from '@hooks/useAccentColor'; | ||
|
||
export default ({ children }: { children: React.JSX.Element }) => { | ||
const playerStyle = useNoxSetting(state => state.playerStyle); | ||
const {} = useAccentColor(true); | ||
|
||
return ( | ||
<View style={{ backgroundColor: playerStyle.colors.background, flex: 1 }}> | ||
{children} | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { getColors } from 'react-native-image-colors'; | ||
import { colord } from 'colord'; | ||
|
||
import useActiveTrack from './useActiveTrack'; | ||
import { useNoxSetting } from '@stores/useApp'; | ||
import { replaceStyleColor } from '@components/style'; | ||
import logger from '@utils/Logger'; | ||
|
||
export default (replaceStyle = false) => { | ||
const playerStyle = useNoxSetting(state => state.playerStyle); | ||
const setPlayerStyle = useNoxSetting(state => state.setPlayerStyle); | ||
const playerSetting = useNoxSetting(state => state.playerSetting); | ||
const [backgroundColor, setBackgroundColor] = useState<string>( | ||
playerStyle.colors.background | ||
); | ||
const { track } = useActiveTrack(); | ||
|
||
const getBackgroundColor = async () => { | ||
if (!playerSetting.accentColor) return; | ||
try { | ||
if (track?.artwork) { | ||
const color = await getColors(track?.artwork, {}); | ||
const resolvedColor = | ||
color.platform === 'ios' ? color.primary : color.dominant; | ||
const parsedColor = colord(resolvedColor); | ||
setBackgroundColor(resolvedColor); | ||
if (replaceStyle) { | ||
setPlayerStyle( | ||
replaceStyleColor({ | ||
playerStyle, | ||
primaryColor: resolvedColor, | ||
secondaryColor: parsedColor.lighten(0.2).toRgbString(), | ||
contrastColor: parsedColor.invert().toRgbString(), | ||
}) | ||
); | ||
} | ||
} | ||
} catch (e) { | ||
logger.warn(e); | ||
setBackgroundColor(playerStyle.colors.background); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getBackgroundColor(); | ||
}, [track]); | ||
|
||
return { backgroundColor }; | ||
}; |
Oops, something went wrong.