xref: /MusicFree/src/components/mediaItem/musicItem.tsx (revision 3b155a6565ae64531be1b64ed1094d20a3a101b4)
1a3b33415S猫头猫import React from 'react';
24060c00aS猫头猫import {Text} from 'react-native';
3a3b33415S猫头猫import rpx from '@/utils/rpx';
4a3b33415S猫头猫import ListItem, {ILeftProps} from '../base/listItem';
5a3b33415S猫头猫import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
6242960d3S猫头猫import MusicQueue from '@/core/musicQueue';
7a3b33415S猫头猫import IconButton from '../base/iconButton';
8a3b33415S猫头猫import usePanel from '../panels/usePanel';
90e4173cdS猫头猫import LocalMusicSheet from '@/core/localMusicSheet';
10a3b33415S猫头猫
11a3b33415S猫头猫interface IMusicItemProps {
12a3b33415S猫头猫    index?: string | number;
13a3b33415S猫头猫    left?: ILeftProps;
1494824d29S猫头猫    right?: () => JSX.Element;
15a3b33415S猫头猫    musicItem: IMusic.IMusicItem;
16a3b33415S猫头猫    musicSheet?: IMusic.IMusicSheetItem;
17a3b33415S猫头猫    onItemPress?: (musicItem: IMusic.IMusicItem) => void;
1894824d29S猫头猫    onItemLongPress?: () => void;
19*3b155a65S猫头猫    itemWidth?: number | string;
2094824d29S猫头猫    itemBackgroundColor?: string;
2117c7a0a6S猫头猫    itemPaddingRight?: number;
22a3b33415S猫头猫}
23a3b33415S猫头猫const ITEM_HEIGHT = rpx(120);
24a3b33415S猫头猫export default function MusicItem(props: IMusicItemProps) {
2594824d29S猫头猫    const {
2694824d29S猫头猫        musicItem,
2794824d29S猫头猫        index,
2894824d29S猫头猫        left,
2994824d29S猫头猫        right,
3094824d29S猫头猫        onItemPress,
3194824d29S猫头猫        onItemLongPress,
3294824d29S猫头猫        musicSheet,
33aeaa4fceS猫头猫        itemWidth,
3417c7a0a6S猫头猫        itemPaddingRight,
3594824d29S猫头猫        itemBackgroundColor,
3694824d29S猫头猫    } = props;
37a3b33415S猫头猫    const {showPanel} = usePanel();
38a3b33415S猫头猫
39a3b33415S猫头猫    return (
40a3b33415S猫头猫        <ListItem
41aeaa4fceS猫头猫            itemWidth={itemWidth}
42a3b33415S猫头猫            itemHeight={ITEM_HEIGHT}
43950202e4S猫头猫            itemPaddingLeft={index !== undefined ? 0 : undefined}
4417c7a0a6S猫头猫            itemPaddingRight={itemPaddingRight}
4594824d29S猫头猫            itemBackgroundColor={itemBackgroundColor}
4694824d29S猫头猫            onLongPress={onItemLongPress}
47950202e4S猫头猫            left={index !== undefined ? {index: index, width: rpx(96)} : left}
48a3b33415S猫头猫            title={musicItem.title}
49a3b33415S猫头猫            desc={
50a3b33415S猫头猫                <>
510e4173cdS猫头猫                    {LocalMusicSheet.isLocalMusic(musicItem) && (
524060c00aS猫头猫                        <Icon
534060c00aS猫头猫                            color="#11659a"
544060c00aS猫头猫                            name="check-circle"
554060c00aS猫头猫                            size={rpx(22)}
564060c00aS猫头猫                        />
57a3b33415S猫头猫                    )}
58a3b33415S猫头猫                    <Text>
59b1fa57d0S猫头猫                        {musicItem.artist}
60b1fa57d0S猫头猫                        {musicItem.album ? ` - ${musicItem.album}` : ''}
61a3b33415S猫头猫                    </Text>
62a3b33415S猫头猫                </>
63a3b33415S猫头猫            }
64a3b33415S猫头猫            tag={musicItem.platform}
65a3b33415S猫头猫            onPress={() => {
66a3b33415S猫头猫                if (onItemPress) {
67a3b33415S猫头猫                    onItemPress(musicItem);
68a3b33415S猫头猫                } else {
69a3b33415S猫头猫                    MusicQueue.play(musicItem);
70a3b33415S猫头猫                }
71a3b33415S猫头猫            }}
7294824d29S猫头猫            right={
7394824d29S猫头猫                right
7494824d29S猫头猫                    ? right
7594824d29S猫头猫                    : () => (
76a3b33415S猫头猫                          <IconButton
7794824d29S猫头猫                              name={'dots-vertical'}
78a3b33415S猫头猫                              size="normal"
79a3b33415S猫头猫                              fontColor="normal"
80a3b33415S猫头猫                              onPress={() => {
8194824d29S猫头猫                                  showPanel('MusicItemOptions', {
8294824d29S猫头猫                                      musicItem,
8394824d29S猫头猫                                      musicSheet,
8494824d29S猫头猫                                  });
854060c00aS猫头猫                              }}
864060c00aS猫头猫                          />
8794824d29S猫头猫                      )
8894824d29S猫头猫            }
894060c00aS猫头猫        />
90a3b33415S猫头猫    );
91a3b33415S猫头猫}
92