修复歌单排序列表滚动重置问题

This commit is contained in:
lyswhut 2023-03-27 21:03:21 +08:00
parent 8f83046cdb
commit f3ac526b51
2 changed files with 8 additions and 2 deletions

View File

@ -5,3 +5,7 @@
### 优化
- 更新设置界面菜单布局
### 修复
- 修复歌单排序列表滚动重置问题

View File

@ -1,4 +1,4 @@
import React, { forwardRef, useImperativeHandle, useMemo, useState } from 'react'
import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState } from 'react'
import { ScrollView, TouchableOpacity } from 'react-native'
import songlistState, { type SortInfo, type Source } from '@/store/songlist/state'
import { useI18n } from '@/lang'
@ -20,9 +20,11 @@ export default forwardRef<SortTabType, SortTabProps>(({ onSortChange }, ref) =>
const [activeId, setActiveId] = useState<SortInfo['id']>('')
const t = useI18n()
const theme = useTheme()
const scrollViewRef = useRef<ScrollView>(null)
useImperativeHandle(ref, () => ({
setSource(source, activeTab) {
scrollViewRef.current?.scrollTo({ x: 0 })
setSortList(songlistState.sortList[source] as SortInfo[])
setActiveId(activeTab)
},
@ -38,7 +40,7 @@ export default forwardRef<SortTabType, SortTabProps>(({ onSortChange }, ref) =>
}
return (
<ScrollView style={styles.container} keyboardShouldPersistTaps={'always'} horizontal={true}>
<ScrollView ref={scrollViewRef} style={styles.container} keyboardShouldPersistTaps={'always'} horizontal>
{
sorts.map(s => (
<TouchableOpacity style={styles.button} onPress={() => { handleSortChange(s.id) }} key={s.id}>