尝试修复播放详情页歌词导致UI冻结的问题

This commit is contained in:
lyswhut 2021-05-25 16:20:54 +08:00
parent 00239b669d
commit 35fa550512
3 changed files with 30 additions and 14 deletions

View File

@ -1,4 +1,4 @@
### 修复 ### 修复
- 尝试修复软件启动时恢复上一次播放的歌曲可能导致软件崩溃的问题 - 尝试修复软件启动时恢复上一次播放的歌曲可能导致软件崩溃的问题
- 修复播放详情页歌词的一个滚动错误 - 尝试修复播放详情页歌词导致UI冻结的问题

View File

@ -41,7 +41,7 @@ export default memo(() => {
// const imgWidth = useMemo(() => layout.width * 0.75, [layout.width]) // const imgWidth = useMemo(() => layout.width * 0.75, [layout.width])
const handleScrollToActive = useCallback((index = lineRef.current) => { const handleScrollToActive = useCallback((index = lineRef.current) => {
if (scrollViewRef.current && linesRef.current.length) { if (scrollViewRef.current) {
scrollViewRef.current.scrollToIndex({ scrollViewRef.current.scrollToIndex({
index, index,
animated: true, animated: true,
@ -68,17 +68,13 @@ export default memo(() => {
} }
useEffect(() => { useEffect(() => {
setTimeout(() => {
isPauseScrollRef.current = false
handleScrollToActive()
}, 100)
return () => { return () => {
if (scrollTimoutRef.current) { if (scrollTimoutRef.current) {
clearTimeout(scrollTimoutRef.current) clearTimeout(scrollTimoutRef.current)
scrollTimoutRef.current = null scrollTimoutRef.current = null
} }
} }
}, [handleScrollToActive]) }, [])
useEffect(() => { useEffect(() => {
linesRef.current = lyricLines linesRef.current = lyricLines
@ -89,6 +85,10 @@ export default memo(() => {
}) })
if (isFirstSetLrc.current) { if (isFirstSetLrc.current) {
isFirstSetLrc.current = false isFirstSetLrc.current = false
setTimeout(() => {
isPauseScrollRef.current = false
handleScrollToActive()
}, 100)
} else { } else {
handleScrollToActive(0) handleScrollToActive(0)
} }
@ -96,7 +96,7 @@ export default memo(() => {
useEffect(() => { useEffect(() => {
lineRef.current = line lineRef.current = line
if (!scrollViewRef.current || !linesRef.current.length || isPauseScrollRef.current) return if (!scrollViewRef.current || isPauseScrollRef.current) return
handleScrollToActive() handleScrollToActive()
}, [handleScrollToActive, line]) }, [handleScrollToActive, line])
@ -132,6 +132,8 @@ export default memo(() => {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
paddingLeft: 10,
paddingRight: 10,
// backgroundColor: 'rgba(0,0,0,0.1)', // backgroundColor: 'rgba(0,0,0,0.1)',
}, },
space: { space: {
@ -141,7 +143,9 @@ const styles = StyleSheet.create({
borderRadius: 4, borderRadius: 4,
textAlign: 'center', textAlign: 'center',
fontSize: 16, fontSize: 16,
lineHeight: 28, lineHeight: 22,
paddingTop: 5,
paddingBottom: 5,
// opacity: 0, // opacity: 0,
}, },
}) })

View File

@ -1,4 +1,4 @@
import React, { useEffect, useCallback, memo, useState, useMemo } from 'react' import React, { useEffect, useCallback, memo, useState, useMemo, useRef } from 'react'
import { View, StyleSheet } from 'react-native' import { View, StyleSheet } from 'react-native'
import Header from '../components/Header' import Header from '../components/Header'
@ -11,6 +11,20 @@ import Pic from './Pic'
import Lyric from './Lyric' import Lyric from './Lyric'
import { screenkeepAwake, screenUnkeepAwake } from '@/utils/utils' import { screenkeepAwake, screenUnkeepAwake } from '@/utils/utils'
const LyricPage = ({ activeIndex }) => {
const initedRef = useRef(false)
const lyric = useMemo(() => <Lyric />, [])
switch (activeIndex) {
// case 3:
case 1:
if (!initedRef.current) initedRef.current = true
return lyric
default:
return initedRef.current ? lyric : null
}
// return activeIndex == 0 || activeIndex == 1 ? setting : null
}
// global.iskeep = false // global.iskeep = false
export default memo(() => { export default memo(() => {
const theme = useGetter('common', 'theme') const theme = useGetter('common', 'theme')
@ -25,8 +39,6 @@ export default memo(() => {
} }
}, []) }, [])
const pic = useMemo(() => <Pic />, [])
return ( return (
<> <>
<Header /> <Header />
@ -37,10 +49,10 @@ export default memo(() => {
style={styles.pagerView} style={styles.pagerView}
> >
<View collapsable={false} style={styles.pageStyle}> <View collapsable={false} style={styles.pageStyle}>
{pageIndex == 0 ? pic : null} <Pic />
</View> </View>
<View collapsable={false} style={styles.pageStyle}> <View collapsable={false} style={styles.pageStyle}>
{pageIndex == 1 ? <Lyric /> : null} <LyricPage activeIndex={pageIndex} />
</View> </View>
</PagerView> </PagerView>
<View style={styles.pageIndicator}> <View style={styles.pageIndicator}>