mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-03 07:02:10 +08:00
158 lines
6.4 KiB
TypeScript
158 lines
6.4 KiB
TypeScript
import { useRef } from 'react'
|
|
|
|
import listState from '@/store/list/state'
|
|
import ListMenu, { type ListMenuType, type Position, type SelectInfo } from './ListMenu'
|
|
import { handlePlay, handlePlayLater, handleRemove, handleShare, handleUpdateMusicPosition } from './listAction'
|
|
import List, { type ListType } from './List'
|
|
import ListMusicAdd, { type MusicAddModalType as ListMusicAddType } from '@/components/MusicAddModal'
|
|
import ListMusicMultiAdd, { type MusicMultiAddModalType as ListAddMultiType } from '@/components/MusicMultiAddModal'
|
|
import { createStyle } from '@/utils/tools'
|
|
import { type LayoutChangeEvent, View } from 'react-native'
|
|
import ActiveList, { type ActiveListType } from './ActiveList'
|
|
import MultipleModeBar, { type SelectMode, type MultipleModeBarType } from './MultipleModeBar'
|
|
import ListSearchBar, { type ListSearchBarType } from './ListSearchBar'
|
|
import ListMusicSearch, { type ListMusicSearchType } from './ListMusicSearch'
|
|
import MusicPositionModal, { type MusicPositionModalType } from './MusicPositionModal'
|
|
|
|
|
|
export default () => {
|
|
// const t = useI18n()
|
|
const activeListRef = useRef<ActiveListType>(null)
|
|
const listMusicSearchRef = useRef<ListMusicSearchType>(null)
|
|
const listRef = useRef<ListType>(null)
|
|
const multipleModeBarRef = useRef<MultipleModeBarType>(null)
|
|
const listSearchBarRef = useRef<ListSearchBarType>(null)
|
|
const listMusicAddRef = useRef<ListMusicAddType>(null)
|
|
const listMusicMultiAddRef = useRef<ListAddMultiType>(null)
|
|
const musicPositionModalRef = useRef<MusicPositionModalType>(null)
|
|
const listMenuRef = useRef<ListMenuType>(null)
|
|
const layoutHeightRef = useRef<number>(0)
|
|
const isShowMultipleModeBar = useRef(false)
|
|
const isShowSearchBarModeBar = useRef(false)
|
|
// console.log('render index list')
|
|
|
|
const hancelMultiSelect = () => {
|
|
if (isShowSearchBarModeBar.current) {
|
|
multipleModeBarRef.current?.setVisibleBar(false)
|
|
} else activeListRef.current?.setVisibleBar(false)
|
|
isShowMultipleModeBar.current = true
|
|
multipleModeBarRef.current?.show()
|
|
listRef.current?.setIsMultiSelectMode(true)
|
|
}
|
|
const hancelExitSelect = () => {
|
|
if (isShowSearchBarModeBar.current) {
|
|
multipleModeBarRef.current?.setVisibleBar(true)
|
|
} else activeListRef.current?.setVisibleBar(true)
|
|
// console.log('hancelExitSelect', isShowSearchBarModeBar.current)
|
|
multipleModeBarRef.current?.exitSelectMode()
|
|
listRef.current?.setIsMultiSelectMode(false)
|
|
isShowMultipleModeBar.current = false
|
|
}
|
|
const hancelSwitchSelectMode = (mode: SelectMode) => {
|
|
multipleModeBarRef.current?.setSwitchMode(mode)
|
|
listRef.current?.setSelectMode(mode)
|
|
}
|
|
|
|
const showMenu = (musicInfo: LX.Music.MusicInfo, index: number, position: Position) => {
|
|
listMenuRef.current?.show({
|
|
musicInfo,
|
|
index,
|
|
listId: listState.activeListId,
|
|
single: false,
|
|
selectedList: listRef.current!.getSelectedList(),
|
|
}, position)
|
|
}
|
|
const handleShowSearch = () => {
|
|
isShowSearchBarModeBar.current = true
|
|
if (isShowMultipleModeBar.current) {
|
|
multipleModeBarRef.current?.setVisibleBar(false)
|
|
} else activeListRef.current?.setVisibleBar(false)
|
|
listSearchBarRef.current?.show()
|
|
}
|
|
const handleExitSearch = () => {
|
|
isShowSearchBarModeBar.current = false
|
|
listMusicSearchRef.current?.hide()
|
|
listSearchBarRef.current?.hide()
|
|
// console.log('handleExitSearch', isShowMultipleModeBar.current)
|
|
if (isShowMultipleModeBar.current) {
|
|
multipleModeBarRef.current?.setVisibleBar(true)
|
|
} else activeListRef.current?.setVisibleBar(true)
|
|
}
|
|
const handleScrollToInfo = (info: LX.Music.MusicInfo) => {
|
|
listRef.current?.scrollToInfo(info)
|
|
handleExitSearch()
|
|
}
|
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
layoutHeightRef.current = e.nativeEvent.layout.height
|
|
}
|
|
|
|
const handleAddMusic = (info: SelectInfo) => {
|
|
if (info.selectedList.length) {
|
|
listMusicMultiAddRef.current?.show({ selectedList: info.selectedList, listId: info.listId, isMove: false })
|
|
} else {
|
|
listMusicAddRef.current?.show({ musicInfo: info.musicInfo, listId: info.listId, isMove: false })
|
|
}
|
|
}
|
|
const handleMoveMusic = (info: SelectInfo) => {
|
|
if (info.selectedList.length) {
|
|
listMusicMultiAddRef.current?.show({ selectedList: info.selectedList, listId: info.listId, isMove: true })
|
|
} else {
|
|
listMusicAddRef.current?.show({ musicInfo: info.musicInfo, listId: info.listId, isMove: true })
|
|
}
|
|
}
|
|
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<View style={{ zIndex: 2 }}>
|
|
<ActiveList ref={activeListRef} onShowSearchBar={handleShowSearch} />
|
|
<MultipleModeBar
|
|
ref={multipleModeBarRef}
|
|
onSwitchMode={hancelSwitchSelectMode}
|
|
onSelectAll={isAll => listRef.current?.selectAll(isAll)}
|
|
onExitSelectMode={hancelExitSelect}
|
|
/>
|
|
<ListSearchBar
|
|
ref={listSearchBarRef}
|
|
onSearch={keyword => listMusicSearchRef.current?.search(keyword, layoutHeightRef.current)}
|
|
onExitSearch={handleExitSearch}
|
|
/>
|
|
</View>
|
|
<View style={{ flex: 1 }} onLayout={onLayout}>
|
|
<List
|
|
ref={listRef}
|
|
onShowMenu={showMenu}
|
|
onMuiltSelectMode={hancelMultiSelect}
|
|
onSelectAll={isAll => multipleModeBarRef.current?.setIsSelectAll(isAll)}
|
|
/>
|
|
<ListMusicSearch
|
|
ref={listMusicSearchRef}
|
|
onScrollToInfo={handleScrollToInfo}
|
|
/>
|
|
</View>
|
|
<ListMusicAdd ref={listMusicAddRef} onAdded={() => { hancelExitSelect() }} />
|
|
<ListMusicMultiAdd ref={listMusicMultiAddRef} onAdded={() => { hancelExitSelect() }} />
|
|
<MusicPositionModal ref={musicPositionModalRef}
|
|
onUpdatePosition={(info, postion) => { handleUpdateMusicPosition(postion, info.listId, info.musicInfo, info.selectedList, hancelExitSelect) }} />
|
|
<ListMenu
|
|
ref={listMenuRef}
|
|
onPlay={info => { handlePlay(info.listId, info.index) }}
|
|
onPlayLater={info => { hancelExitSelect(); handlePlayLater(info.listId, info.musicInfo, info.selectedList, hancelExitSelect) }}
|
|
onRemove={info => { hancelExitSelect(); handleRemove(info.listId, info.musicInfo, info.selectedList, hancelExitSelect) }}
|
|
onCopyName={info => { handleShare(info.musicInfo) }}
|
|
onAdd={handleAddMusic}
|
|
onMove={handleMoveMusic}
|
|
onChangePosition={info => musicPositionModalRef.current?.show(info)}
|
|
/>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
|
|
const styles = createStyle({
|
|
container: {
|
|
flex: 1,
|
|
flexDirection: 'column',
|
|
},
|
|
})
|