mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
新增长按收藏列表名自动跳转列表顶部的功能
This commit is contained in:
parent
81e883a013
commit
35ecd2022b
@ -1,6 +1,7 @@
|
|||||||
### 新增
|
### 新增
|
||||||
|
|
||||||
- 新增自定义源,但需要注意的是,移动端自定义源的环境与PC端不同,某些API不可用
|
- 新增自定义源(实验性功能),但需要注意的是,移动端自定义源的环境与PC端不同,某些API不可用
|
||||||
|
- 新增长按收藏列表名自动跳转列表顶部的功能
|
||||||
|
|
||||||
### 优化
|
### 优化
|
||||||
|
|
||||||
|
@ -14,12 +14,13 @@ import { LIST_IDS } from '@/config/constant'
|
|||||||
|
|
||||||
export interface ActiveListProps {
|
export interface ActiveListProps {
|
||||||
onShowSearchBar: () => void
|
onShowSearchBar: () => void
|
||||||
|
onScrollToTop: () => void
|
||||||
}
|
}
|
||||||
export interface ActiveListType {
|
export interface ActiveListType {
|
||||||
setVisibleBar: (visible: boolean) => void
|
setVisibleBar: (visible: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default forwardRef<ActiveListType, ActiveListProps>(({ onShowSearchBar }, ref) => {
|
export default forwardRef<ActiveListType, ActiveListProps>(({ onShowSearchBar, onScrollToTop }, ref) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const currentListId = useActiveListId()
|
const currentListId = useActiveListId()
|
||||||
let currentListName = currentListId == LIST_IDS.TEMP ? global.i18n.t(`list_${LIST_IDS.TEMP}`) : listState.allList.find(l => l.id === currentListId)?.name ?? ''
|
let currentListName = currentListId == LIST_IDS.TEMP ? global.i18n.t(`list_${LIST_IDS.TEMP}`) : listState.allList.find(l => l.id === currentListId)?.name ?? ''
|
||||||
@ -42,7 +43,7 @@ export default forwardRef<ActiveListType, ActiveListProps>(({ onShowSearchBar },
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity onPress={showList} style={{ ...styles.currentList, opacity: visibleBar ? 1 : 0, borderBottomColor: theme['c-border-background'] }}>
|
<TouchableOpacity onPress={showList} onLongPress={onScrollToTop} style={{ ...styles.currentList, opacity: visibleBar ? 1 : 0, borderBottomColor: theme['c-border-background'] }}>
|
||||||
<Icon style={styles.currentListIcon} color={theme['c-button-font']} name="chevron-right" size={12} />
|
<Icon style={styles.currentListIcon} color={theme['c-button-font']} name="chevron-right" size={12} />
|
||||||
<Text numberOfLines={1} style={styles.currentListText} color={theme['c-button-font']}>{currentListName}</Text>
|
<Text numberOfLines={1} style={styles.currentListText} color={theme['c-button-font']}>{currentListName}</Text>
|
||||||
<TouchableOpacity style={styles.currentListBtns} onPress={onShowSearchBar}>
|
<TouchableOpacity style={styles.currentListBtns} onPress={onShowSearchBar}>
|
||||||
|
@ -28,6 +28,7 @@ export interface ListType {
|
|||||||
selectAll: (isAll: boolean) => void
|
selectAll: (isAll: boolean) => void
|
||||||
getSelectedList: () => LX.List.ListMusics
|
getSelectedList: () => LX.List.ListMusics
|
||||||
scrollToInfo: (info: LX.Music.MusicInfo) => void
|
scrollToInfo: (info: LX.Music.MusicInfo) => void
|
||||||
|
scrollToTop: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const usePlayIndex = () => {
|
const usePlayIndex = () => {
|
||||||
@ -91,6 +92,12 @@ const List = forwardRef<ListType, ListProps>(({ onShowMenu, onMuiltSelectMode, o
|
|||||||
flatListRef.current?.scrollToIndex({ index: Math.floor(index / (rowInfo.current.rowNum ?? 1)), viewPosition: 0.3, animated: true })
|
flatListRef.current?.scrollToIndex({ index: Math.floor(index / (rowInfo.current.rowNum ?? 1)), viewPosition: 0.3, animated: true })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
scrollToTop() {
|
||||||
|
flatListRef.current?.scrollToOffset({
|
||||||
|
offset: 0,
|
||||||
|
animated: true,
|
||||||
|
})
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useRef } from 'react'
|
import { useCallback, useRef } from 'react'
|
||||||
|
|
||||||
import listState from '@/store/list/state'
|
import listState from '@/store/list/state'
|
||||||
import ListMenu, { type ListMenuType, type Position, type SelectInfo } from './ListMenu'
|
import ListMenu, { type ListMenuType, type Position, type SelectInfo } from './ListMenu'
|
||||||
@ -31,15 +31,15 @@ export default () => {
|
|||||||
const isShowSearchBarModeBar = useRef(false)
|
const isShowSearchBarModeBar = useRef(false)
|
||||||
// console.log('render index list')
|
// console.log('render index list')
|
||||||
|
|
||||||
const hancelMultiSelect = () => {
|
const hancelMultiSelect = useCallback(() => {
|
||||||
if (isShowSearchBarModeBar.current) {
|
if (isShowSearchBarModeBar.current) {
|
||||||
multipleModeBarRef.current?.setVisibleBar(false)
|
multipleModeBarRef.current?.setVisibleBar(false)
|
||||||
} else activeListRef.current?.setVisibleBar(false)
|
} else activeListRef.current?.setVisibleBar(false)
|
||||||
isShowMultipleModeBar.current = true
|
isShowMultipleModeBar.current = true
|
||||||
multipleModeBarRef.current?.show()
|
multipleModeBarRef.current?.show()
|
||||||
listRef.current?.setIsMultiSelectMode(true)
|
listRef.current?.setIsMultiSelectMode(true)
|
||||||
}
|
}, [])
|
||||||
const hancelExitSelect = () => {
|
const hancelExitSelect = useCallback(() => {
|
||||||
if (isShowSearchBarModeBar.current) {
|
if (isShowSearchBarModeBar.current) {
|
||||||
multipleModeBarRef.current?.setVisibleBar(true)
|
multipleModeBarRef.current?.setVisibleBar(true)
|
||||||
} else activeListRef.current?.setVisibleBar(true)
|
} else activeListRef.current?.setVisibleBar(true)
|
||||||
@ -47,13 +47,16 @@ export default () => {
|
|||||||
multipleModeBarRef.current?.exitSelectMode()
|
multipleModeBarRef.current?.exitSelectMode()
|
||||||
listRef.current?.setIsMultiSelectMode(false)
|
listRef.current?.setIsMultiSelectMode(false)
|
||||||
isShowMultipleModeBar.current = false
|
isShowMultipleModeBar.current = false
|
||||||
}
|
}, [])
|
||||||
const hancelSwitchSelectMode = (mode: SelectMode) => {
|
const hancelSwitchSelectMode = useCallback((mode: SelectMode) => {
|
||||||
multipleModeBarRef.current?.setSwitchMode(mode)
|
multipleModeBarRef.current?.setSwitchMode(mode)
|
||||||
listRef.current?.setSelectMode(mode)
|
listRef.current?.setSelectMode(mode)
|
||||||
}
|
}, [])
|
||||||
|
const hancelScrollToTop = useCallback(() => {
|
||||||
|
listRef.current?.scrollToTop()
|
||||||
|
}, [])
|
||||||
|
|
||||||
const showMenu = (musicInfo: LX.Music.MusicInfo, index: number, position: Position) => {
|
const showMenu = useCallback((musicInfo: LX.Music.MusicInfo, index: number, position: Position) => {
|
||||||
listMenuRef.current?.show({
|
listMenuRef.current?.show({
|
||||||
musicInfo,
|
musicInfo,
|
||||||
index,
|
index,
|
||||||
@ -61,15 +64,15 @@ export default () => {
|
|||||||
single: false,
|
single: false,
|
||||||
selectedList: listRef.current!.getSelectedList(),
|
selectedList: listRef.current!.getSelectedList(),
|
||||||
}, position)
|
}, position)
|
||||||
}
|
}, [])
|
||||||
const handleShowSearch = () => {
|
const handleShowSearch = useCallback(() => {
|
||||||
isShowSearchBarModeBar.current = true
|
isShowSearchBarModeBar.current = true
|
||||||
if (isShowMultipleModeBar.current) {
|
if (isShowMultipleModeBar.current) {
|
||||||
multipleModeBarRef.current?.setVisibleBar(false)
|
multipleModeBarRef.current?.setVisibleBar(false)
|
||||||
} else activeListRef.current?.setVisibleBar(false)
|
} else activeListRef.current?.setVisibleBar(false)
|
||||||
listSearchBarRef.current?.show()
|
listSearchBarRef.current?.show()
|
||||||
}
|
}, [])
|
||||||
const handleExitSearch = () => {
|
const handleExitSearch = useCallback(() => {
|
||||||
isShowSearchBarModeBar.current = false
|
isShowSearchBarModeBar.current = false
|
||||||
listMusicSearchRef.current?.hide()
|
listMusicSearchRef.current?.hide()
|
||||||
listSearchBarRef.current?.hide()
|
listSearchBarRef.current?.hide()
|
||||||
@ -77,35 +80,35 @@ export default () => {
|
|||||||
if (isShowMultipleModeBar.current) {
|
if (isShowMultipleModeBar.current) {
|
||||||
multipleModeBarRef.current?.setVisibleBar(true)
|
multipleModeBarRef.current?.setVisibleBar(true)
|
||||||
} else activeListRef.current?.setVisibleBar(true)
|
} else activeListRef.current?.setVisibleBar(true)
|
||||||
}
|
}, [])
|
||||||
const handleScrollToInfo = (info: LX.Music.MusicInfo) => {
|
const handleScrollToInfo = useCallback((info: LX.Music.MusicInfo) => {
|
||||||
listRef.current?.scrollToInfo(info)
|
listRef.current?.scrollToInfo(info)
|
||||||
handleExitSearch()
|
handleExitSearch()
|
||||||
}
|
}, [])
|
||||||
const onLayout = (e: LayoutChangeEvent) => {
|
const onLayout = useCallback((e: LayoutChangeEvent) => {
|
||||||
layoutHeightRef.current = e.nativeEvent.layout.height
|
layoutHeightRef.current = e.nativeEvent.layout.height
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
const handleAddMusic = (info: SelectInfo) => {
|
const handleAddMusic = useCallback((info: SelectInfo) => {
|
||||||
if (info.selectedList.length) {
|
if (info.selectedList.length) {
|
||||||
listMusicMultiAddRef.current?.show({ selectedList: info.selectedList, listId: info.listId, isMove: false })
|
listMusicMultiAddRef.current?.show({ selectedList: info.selectedList, listId: info.listId, isMove: false })
|
||||||
} else {
|
} else {
|
||||||
listMusicAddRef.current?.show({ musicInfo: info.musicInfo, listId: info.listId, isMove: false })
|
listMusicAddRef.current?.show({ musicInfo: info.musicInfo, listId: info.listId, isMove: false })
|
||||||
}
|
}
|
||||||
}
|
}, [])
|
||||||
const handleMoveMusic = (info: SelectInfo) => {
|
const handleMoveMusic = useCallback((info: SelectInfo) => {
|
||||||
if (info.selectedList.length) {
|
if (info.selectedList.length) {
|
||||||
listMusicMultiAddRef.current?.show({ selectedList: info.selectedList, listId: info.listId, isMove: true })
|
listMusicMultiAddRef.current?.show({ selectedList: info.selectedList, listId: info.listId, isMove: true })
|
||||||
} else {
|
} else {
|
||||||
listMusicAddRef.current?.show({ musicInfo: info.musicInfo, listId: info.listId, isMove: true })
|
listMusicAddRef.current?.show({ musicInfo: info.musicInfo, listId: info.listId, isMove: true })
|
||||||
}
|
}
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<View style={{ zIndex: 2 }}>
|
<View style={{ zIndex: 2 }}>
|
||||||
<ActiveList ref={activeListRef} onShowSearchBar={handleShowSearch} />
|
<ActiveList ref={activeListRef} onShowSearchBar={handleShowSearch} onScrollToTop={hancelScrollToTop} />
|
||||||
<MultipleModeBar
|
<MultipleModeBar
|
||||||
ref={multipleModeBarRef}
|
ref={multipleModeBarRef}
|
||||||
onSwitchMode={hancelSwitchSelectMode}
|
onSwitchMode={hancelSwitchSelectMode}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user