From e7d65da8d8df583153ba41aee71a6d343aa738fd Mon Sep 17 00:00:00 2001 From: lyswhut Date: Thu, 27 May 2021 11:20:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E8=BF=9B=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=AD=8C=E8=AF=8D=E7=95=8C=E9=9D=A2=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 ++++ src/plugins/lyric.js | 1 + .../PlayDetail/Portrait/Player/Lyric.js | 18 +++++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 97d519e..5da4859 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -6,3 +6,7 @@ ### 优化 - 优化应用布局对手机系统字体大小的适配 + +### 修复 + +- 尝试修复某些情况下进播放详情歌词界面时报错的问题 diff --git a/src/plugins/lyric.js b/src/plugins/lyric.js index 4394584..53054a0 100644 --- a/src/plugins/lyric.js +++ b/src/plugins/lyric.js @@ -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) diff --git a/src/screens/PlayDetail/Portrait/Player/Lyric.js b/src/screens/PlayDetail/Portrait/Player/Lyric.js index 3431cf2..4f1e8e8 100644 --- a/src/screens/PlayDetail/Portrait/Player/Lyric.js +++ b/src/screens/PlayDetail/Portrait/Player/Lyric.js @@ -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) + } } }, [])