xref: /MusicFree/src/pages/musicDetail/components/content/albumCover/index.tsx (revision 756bc302d40f6f21e72cdfca8580b52a8341d658)
113cebe63S猫头猫import React, {useMemo} from 'react';
213cebe63S猫头猫import rpx from '@/utils/rpx';
313cebe63S猫头猫import {ImgAsset} from '@/constants/assetsConst';
413cebe63S猫头猫import FastImage from '@/components/base/fastImage';
513cebe63S猫头猫import useOrientation from '@/hooks/useOrientation';
613cebe63S猫头猫import {Gesture, GestureDetector} from 'react-native-gesture-handler';
713cebe63S猫头猫import TrackPlayer from '@/core/trackPlayer';
813cebe63S猫头猫import globalStyle from '@/constants/globalStyle';
913cebe63S猫头猫import {View} from 'react-native';
1013cebe63S猫头猫import Operations from './operations';
11*756bc302S猫头猫import {showPanel} from '@/components/panels/usePanel.ts';
1213cebe63S猫头猫
1313cebe63S猫头猫interface IProps {
1413cebe63S猫头猫    onTurnPageClick?: () => void;
1513cebe63S猫头猫}
1613cebe63S猫头猫
1713cebe63S猫头猫export default function AlbumCover(props: IProps) {
1813cebe63S猫头猫    const {onTurnPageClick} = props;
1913cebe63S猫头猫
2013cebe63S猫头猫    const musicItem = TrackPlayer.useCurrentMusic();
2113cebe63S猫头猫    const orientation = useOrientation();
2213cebe63S猫头猫
2313cebe63S猫头猫    const artworkStyle = useMemo(() => {
2413cebe63S猫头猫        if (orientation === 'vertical') {
2513cebe63S猫头猫            return {
2613cebe63S猫头猫                width: rpx(500),
2713cebe63S猫头猫                height: rpx(500),
2813cebe63S猫头猫            };
2913cebe63S猫头猫        } else {
3013cebe63S猫头猫            return {
3113cebe63S猫头猫                width: rpx(260),
3213cebe63S猫头猫                height: rpx(260),
3313cebe63S猫头猫            };
3413cebe63S猫头猫        }
3513cebe63S猫头猫    }, [orientation]);
3613cebe63S猫头猫
3713cebe63S猫头猫    const longPress = Gesture.LongPress()
3813cebe63S猫头猫        .onStart(() => {
3913cebe63S猫头猫            if (musicItem?.artwork) {
40*756bc302S猫头猫                showPanel('ImageViewer', {
41*756bc302S猫头猫                    url: musicItem.artwork,
42*756bc302S猫头猫                });
4313cebe63S猫头猫            }
4413cebe63S猫头猫        })
4513cebe63S猫头猫        .runOnJS(true);
4613cebe63S猫头猫
4713cebe63S猫头猫    const tap = Gesture.Tap()
4813cebe63S猫头猫        .onStart(() => {
4913cebe63S猫头猫            onTurnPageClick?.();
5013cebe63S猫头猫        })
5113cebe63S猫头猫        .runOnJS(true);
5213cebe63S猫头猫
5313cebe63S猫头猫    const combineGesture = Gesture.Race(tap, longPress);
5413cebe63S猫头猫
5513cebe63S猫头猫    return (
5613cebe63S猫头猫        <>
5713cebe63S猫头猫            <GestureDetector gesture={combineGesture}>
5813cebe63S猫头猫                <View style={globalStyle.fullCenter}>
5913cebe63S猫头猫                    <FastImage
6013cebe63S猫头猫                        style={artworkStyle}
6113cebe63S猫头猫                        uri={musicItem?.artwork}
6213cebe63S猫头猫                        emptySrc={ImgAsset.albumDefault}
6313cebe63S猫头猫                    />
6413cebe63S猫头猫                </View>
6513cebe63S猫头猫            </GestureDetector>
6613cebe63S猫头猫            <Operations />
6713cebe63S猫头猫        </>
6813cebe63S猫头猫    );
6913cebe63S猫头猫}
70