尝试修复某些情况下进播放详情歌词界面时报错的问题

This commit is contained in:
lyswhut 2021-05-27 11:20:41 +08:00
parent bddbd9480e
commit e7d65da8d8
3 changed files with 18 additions and 5 deletions

View File

@ -6,3 +6,7 @@
### 优化
- 优化应用布局对手机系统字体大小的适配
### 修复
- 尝试修复某些情况下进播放详情歌词界面时报错的问题

View File

@ -28,6 +28,7 @@ const lrcTools = {
onSetLyric(lines) {
this.currentLines = lines
for (const hook of this.setLyricHooks) hook(lines)
for (const hook of this.playHooks) hook(-1, '')
},
addPlayHook(callback) {
this.playHooks.push(callback)

View File

@ -3,6 +3,8 @@ import { View, Text, StyleSheet, FlatList } from 'react-native'
import { useGetter, useDispatch } from '@/store'
import { useLayout } from '@/utils/hooks'
import { useLrcPlay, useLrcSet } from '@/plugins/lyric'
import { log } from '@/utils/log'
import { toast } from '@/utils/tools'
const LrcLine = memo(({ text, line, activeLine }) => {
const theme = useGetter('common', 'theme')
@ -41,12 +43,18 @@ export default memo(() => {
// const imgWidth = useMemo(() => layout.width * 0.75, [layout.width])
const handleScrollToActive = useCallback((index = lineRef.current) => {
if (index < 0) return
if (scrollViewRef.current) {
scrollViewRef.current.scrollToIndex({
index,
animated: true,
viewPosition: 0.4,
})
try {
scrollViewRef.current.scrollToIndex({
index: index,
animated: true,
viewPosition: 0.4,
})
} catch (err) {
toast('出了点意外...你可以去错误日志查看错误', 'long')
log.warn('Scroll failed: ', err.message)
}
}
}, [])