mirror of
https://github.com/ragestudio/comty.git
synced 2025-07-08 16:54:15 +00:00
Fix lyrics scroll handling and track state checking
This commit is contained in:
parent
1efac82a37
commit
2031b413ce
@ -10,6 +10,7 @@ const LyricsText = React.forwardRef((props, textRef) => {
|
|||||||
|
|
||||||
const { lyrics } = props
|
const { lyrics } = props
|
||||||
|
|
||||||
|
const currentTrackId = React.useRef(null)
|
||||||
const [syncInterval, setSyncInterval] = React.useState(null)
|
const [syncInterval, setSyncInterval] = React.useState(null)
|
||||||
const [currentLineIndex, setCurrentLineIndex] = React.useState(0)
|
const [currentLineIndex, setCurrentLineIndex] = React.useState(0)
|
||||||
const [visible, setVisible] = React.useState(false)
|
const [visible, setVisible] = React.useState(false)
|
||||||
@ -25,9 +26,7 @@ const LyricsText = React.forwardRef((props, textRef) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (lineIndex === -1) {
|
if (lineIndex === -1) {
|
||||||
if (!visible) {
|
setVisible(false)
|
||||||
setVisible(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -70,8 +69,14 @@ const LyricsText = React.forwardRef((props, textRef) => {
|
|||||||
|
|
||||||
//* Handle when current line index change
|
//* Handle when current line index change
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
console.debug("[lyrics] currentLineIndex", currentLineIndex)
|
||||||
|
|
||||||
if (currentLineIndex === 0) {
|
if (currentLineIndex === 0) {
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
|
|
||||||
|
if (textRef.current) {
|
||||||
|
textRef.current.scrollTop = 0
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setVisible(true)
|
setVisible(true)
|
||||||
|
|
||||||
@ -87,9 +92,6 @@ const LyricsText = React.forwardRef((props, textRef) => {
|
|||||||
behavior: "smooth",
|
behavior: "smooth",
|
||||||
block: "center",
|
block: "center",
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
// scroll to top
|
|
||||||
textRef.current.scrollTop = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,10 +104,16 @@ const LyricsText = React.forwardRef((props, textRef) => {
|
|||||||
|
|
||||||
//* Handle when manifest object change, reset...
|
//* Handle when manifest object change, reset...
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setVisible(false)
|
currentTrackId.current = playerState.track_manifest?.id
|
||||||
setCurrentLineIndex(0)
|
|
||||||
// set scroll top to 0
|
if (playerState.track_manifest?.id !== currentTrackId.current) {
|
||||||
textRef.current.scrollTop = 0
|
setVisible(false)
|
||||||
|
setCurrentLineIndex(0)
|
||||||
|
|
||||||
|
if (textRef.current) {
|
||||||
|
textRef.current.scrollTop = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}, [playerState.track_manifest])
|
}, [playerState.track_manifest])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user