1c446f2b8S猫头猫import React, {memo, useEffect, useState} from 'react'; 24060c00aS猫头猫import {Keyboard, Pressable, StyleSheet, Text, View} from 'react-native'; 3bf6e62f2S猫头猫import rpx from '@/utils/rpx'; 4bf6e62f2S猫头猫import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; 5242960d3S猫头猫import MusicQueue from '@/core/musicQueue'; 64060c00aS猫头猫import {Avatar, IconButton, useTheme} from 'react-native-paper'; 7bf6e62f2S猫头猫import {CircularProgressBase} from 'react-native-circular-progress-indicator'; 8e7fa3837S猫头猫import {ROUTE_PATH, useNavigate} from '@/entry/router'; 9bf6e62f2S猫头猫 10bf6e62f2S猫头猫import musicIsPaused from '@/utils/musicIsPaused'; 11378a6099S猫头猫import usePanel from '../panels/usePanel'; 12bf6e62f2S猫头猫import Color from 'color'; 1319dc08ecS猫头猫import ThemeText from '../base/themeText'; 141befdbcdS猫头猫import {ImgAsset} from '@/constants/assetsConst'; 15c446f2b8S猫头猫import {useSafeAreaInsets} from 'react-native-safe-area-context'; 16bf6e62f2S猫头猫 17c9af9657S猫头猫function CircularPlayBtn() { 18c9af9657S猫头猫 const progress = MusicQueue.useProgress(); 19c9af9657S猫头猫 const musicState = MusicQueue.usePlaybackState(); 20c9af9657S猫头猫 const {colors} = useTheme(); 21c9af9657S猫头猫 22c9af9657S猫头猫 return ( 23c9af9657S猫头猫 <CircularProgressBase 24c9af9657S猫头猫 activeStrokeWidth={rpx(4)} 25c9af9657S猫头猫 inActiveStrokeWidth={rpx(2)} 26c9af9657S猫头猫 inActiveStrokeOpacity={0.2} 27c9af9657S猫头猫 value={ 28c9af9657S猫头猫 progress?.duration 29c9af9657S猫头猫 ? (100 * progress.position) / progress.duration 30c9af9657S猫头猫 : 0 31c9af9657S猫头猫 } 32c9af9657S猫头猫 duration={100} 33c9af9657S猫头猫 radius={rpx(36)} 34c9af9657S猫头猫 activeStrokeColor={colors.text} 35c9af9657S猫头猫 inActiveStrokeColor={Color(colors.text).alpha(0.5).toString()}> 36c9af9657S猫头猫 {musicIsPaused(musicState) ? ( 37c9af9657S猫头猫 <IconButton 38c9af9657S猫头猫 icon="play" 39c9af9657S猫头猫 size={rpx(48)} 40c9af9657S猫头猫 onPress={async () => { 41c9af9657S猫头猫 await MusicQueue.play(); 42c9af9657S猫头猫 }} 43c9af9657S猫头猫 /> 44c9af9657S猫头猫 ) : ( 45c9af9657S猫头猫 <IconButton 46c9af9657S猫头猫 icon="pause" 47c9af9657S猫头猫 size={rpx(48)} 48c9af9657S猫头猫 onPress={async () => { 49c9af9657S猫头猫 await MusicQueue.pause(); 50c9af9657S猫头猫 }} 51c9af9657S猫头猫 /> 52c9af9657S猫头猫 )} 53c9af9657S猫头猫 </CircularProgressBase> 54c9af9657S猫头猫 ); 55c9af9657S猫头猫} 56bec1e603S猫头猫function MusicBar() { 57bf6e62f2S猫头猫 const musicItem = MusicQueue.useCurrentMusicItem(); 58c9af9657S猫头猫 5900d0309bS猫头猫 const [showKeyboard, setKeyboardStatus] = useState(false); 6008a8e62cS猫头猫 const {showPanel} = usePanel(); 61e7fa3837S猫头猫 const navigate = useNavigate(); 62bf6e62f2S猫头猫 const {colors} = useTheme(); 63c446f2b8S猫头猫 const safeAreaInsets = useSafeAreaInsets(); 64bf6e62f2S猫头猫 6500d0309bS猫头猫 useEffect(() => { 6600d0309bS猫头猫 const showSubscription = Keyboard.addListener('keyboardDidShow', () => { 6700d0309bS猫头猫 setKeyboardStatus(true); 6800d0309bS猫头猫 }); 6900d0309bS猫头猫 const hideSubscription = Keyboard.addListener('keyboardDidHide', () => { 7000d0309bS猫头猫 setKeyboardStatus(false); 7100d0309bS猫头猫 }); 7200d0309bS猫头猫 7300d0309bS猫头猫 return () => { 7400d0309bS猫头猫 showSubscription.remove(); 7500d0309bS猫头猫 hideSubscription.remove(); 7600d0309bS猫头猫 }; 7700d0309bS猫头猫 }, []); 7800d0309bS猫头猫 79bf6e62f2S猫头猫 return ( 80c446f2b8S猫头猫 <> 8100d0309bS猫头猫 {musicItem && !showKeyboard && ( 82bf6e62f2S猫头猫 <Pressable 83bf6e62f2S猫头猫 style={[ 84bf6e62f2S猫头猫 style.wrapper, 854060c00aS猫头猫 { 864060c00aS猫头猫 backgroundColor: Color(colors.primary) 874060c00aS猫头猫 .alpha(0.66) 884060c00aS猫头猫 .toString(), 89c446f2b8S猫头猫 paddingLeft: safeAreaInsets.left + rpx(24), 90*3b155a65S猫头猫 paddingRight: safeAreaInsets.right + rpx(24), 914060c00aS猫头猫 }, 92bf6e62f2S猫头猫 ]} 93bf6e62f2S猫头猫 onPress={() => { 94e7fa3837S猫头猫 navigate(ROUTE_PATH.MUSIC_DETAIL); 95bf6e62f2S猫头猫 }}> 96bf6e62f2S猫头猫 <View style={style.artworkWrapper}> 97bf6e62f2S猫头猫 <Avatar.Image 98bf6e62f2S猫头猫 size={rpx(96)} 991befdbcdS猫头猫 source={ 1005e267aa1S猫头猫 musicItem?.artwork 1011befdbcdS猫头猫 ? { 102bf6e62f2S猫头猫 uri: musicItem.artwork, 1031befdbcdS猫头猫 } 1041befdbcdS猫头猫 : ImgAsset.albumDefault 1054060c00aS猫头猫 } 1064060c00aS猫头猫 /> 107bf6e62f2S猫头猫 </View> 108bf6e62f2S猫头猫 <Text 109bf6e62f2S猫头猫 ellipsizeMode="tail" 110bf6e62f2S猫头猫 style={style.textWrapper} 111bf6e62f2S猫头猫 numberOfLines={1}> 1124060c00aS猫头猫 <ThemeText fontSize="content"> 1135e267aa1S猫头猫 {musicItem?.title} 1144060c00aS猫头猫 </ThemeText> 115bf6e62f2S猫头猫 {musicItem?.artist && ( 1164060c00aS猫头猫 <ThemeText 1174060c00aS猫头猫 fontSize="description" 1184060c00aS猫头猫 fontColor="secondary"> 1191befdbcdS猫头猫 {' '} 1201befdbcdS猫头猫 -{musicItem.artist} 1211befdbcdS猫头猫 </ThemeText> 122bf6e62f2S猫头猫 )} 123bf6e62f2S猫头猫 </Text> 124bf6e62f2S猫头猫 <View style={style.actionGroup}> 125c9af9657S猫头猫 <CircularPlayBtn /> 126bf6e62f2S猫头猫 127bf6e62f2S猫头猫 <Icon 128bf6e62f2S猫头猫 name="playlist-music" 129bf6e62f2S猫头猫 size={rpx(56)} 130bf6e62f2S猫头猫 onPress={() => { 131bf6e62f2S猫头猫 showPanel('PlayList'); 132bf6e62f2S猫头猫 }} 1334060c00aS猫头猫 style={[style.actionIcon, {color: colors.text}]} 1344060c00aS猫头猫 /> 135bf6e62f2S猫头猫 </View> 136bf6e62f2S猫头猫 </Pressable> 137bf6e62f2S猫头猫 )} 138c446f2b8S猫头猫 </> 139bf6e62f2S猫头猫 ); 140bf6e62f2S猫头猫} 141bf6e62f2S猫头猫 142bec1e603S猫头猫export default memo(MusicBar, () => true); 143bec1e603S猫头猫 144bf6e62f2S猫头猫const style = StyleSheet.create({ 145bf6e62f2S猫头猫 wrapper: { 146c446f2b8S猫头猫 width: '100%', 147bf6e62f2S猫头猫 height: rpx(120), 148bf6e62f2S猫头猫 flexDirection: 'row', 149bf6e62f2S猫头猫 alignItems: 'center', 150bf6e62f2S猫头猫 paddingHorizontal: rpx(24), 151bf6e62f2S猫头猫 }, 152bf6e62f2S猫头猫 artworkWrapper: { 153bf6e62f2S猫头猫 height: rpx(120), 154bf6e62f2S猫头猫 width: rpx(120), 155bf6e62f2S猫头猫 }, 156bf6e62f2S猫头猫 textWrapper: { 157bf6e62f2S猫头猫 flexGrow: 1, 158c446f2b8S猫头猫 flexShrink: 1, 159bf6e62f2S猫头猫 }, 160bf6e62f2S猫头猫 actionGroup: { 161bf6e62f2S猫头猫 width: rpx(200), 162bf6e62f2S猫头猫 justifyContent: 'flex-end', 163bf6e62f2S猫头猫 flexDirection: 'row', 164bf6e62f2S猫头猫 alignItems: 'center', 165bf6e62f2S猫头猫 }, 166bf6e62f2S猫头猫 actionIcon: { 167bf6e62f2S猫头猫 marginLeft: rpx(36), 168bf6e62f2S猫头猫 }, 169bf6e62f2S猫头猫}); 170