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 imageViewer from '@/components/imageViewer'; 8import TrackPlayer from '@/core/trackPlayer'; 9import globalStyle from '@/constants/globalStyle'; 10import {View} from 'react-native'; 11import Operations from './operations'; 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 imageViewer.show(musicItem.artwork); 41 } 42 }) 43 .runOnJS(true); 44 45 const tap = Gesture.Tap() 46 .onStart(() => { 47 onTurnPageClick?.(); 48 }) 49 .runOnJS(true); 50 51 const combineGesture = Gesture.Race(tap, longPress); 52 53 return ( 54 <> 55 <GestureDetector gesture={combineGesture}> 56 <View style={globalStyle.fullCenter}> 57 <FastImage 58 style={artworkStyle} 59 uri={musicItem?.artwork} 60 emptySrc={ImgAsset.albumDefault} 61 /> 62 </View> 63 </GestureDetector> 64 <Operations /> 65 </> 66 ); 67} 68