1import React, {useMemo} from 'react'; 2import rpx from '@/utils/rpx'; 3import {ImgAsset} from '@/constants/assetsConst'; 4import FastImage from '@/components/base/fastImage'; 5import useOrientation from '@/hooks/useOrientation'; 6import {Gesture, GestureDetector} from 'react-native-gesture-handler'; 7import TrackPlayer from '@/core/trackPlayer'; 8import globalStyle from '@/constants/globalStyle'; 9import {View} from 'react-native'; 10import Operations from './operations'; 11import {showPanel} from '@/components/panels/usePanel.ts'; 12 13interface IProps { 14 onTurnPageClick?: () => void; 15} 16 17export default function AlbumCover(props: IProps) { 18 const {onTurnPageClick} = props; 19 20 const musicItem = TrackPlayer.useCurrentMusic(); 21 const orientation = useOrientation(); 22 23 const artworkStyle = useMemo(() => { 24 if (orientation === 'vertical') { 25 return { 26 width: rpx(500), 27 height: rpx(500), 28 }; 29 } else { 30 return { 31 width: rpx(260), 32 height: rpx(260), 33 }; 34 } 35 }, [orientation]); 36 37 const longPress = Gesture.LongPress() 38 .onStart(() => { 39 if (musicItem?.artwork) { 40 showPanel('ImageViewer', { 41 url: musicItem.artwork, 42 }); 43 } 44 }) 45 .runOnJS(true); 46 47 const tap = Gesture.Tap() 48 .onStart(() => { 49 onTurnPageClick?.(); 50 }) 51 .runOnJS(true); 52 53 const combineGesture = Gesture.Race(tap, longPress); 54 55 return ( 56 <> 57 <GestureDetector gesture={combineGesture}> 58 <View style={globalStyle.fullCenter}> 59 <FastImage 60 style={artworkStyle} 61 uri={musicItem?.artwork} 62 emptySrc={ImgAsset.albumDefault} 63 /> 64 </View> 65 </GestureDetector> 66 <Operations /> 67 </> 68 ); 69} 70