1*bf6e62f2S猫头猫import React, { useState } from 'react'; 2*bf6e62f2S猫头猫import {StyleSheet, Text, View} from 'react-native'; 3*bf6e62f2S猫头猫import rpx from '@/utils/rpx'; 4*bf6e62f2S猫头猫import Slider from '@react-native-community/slider'; 5*bf6e62f2S猫头猫import MusicQueue from '@/common/musicQueue'; 6*bf6e62f2S猫头猫import timeformat from '@/utils/timeformat'; 7*bf6e62f2S猫头猫import { fontSizeConst } from '@/constants/uiConst'; 8*bf6e62f2S猫头猫import ThemeText from '@/components/themeText'; 9*bf6e62f2S猫头猫import useTextColor from '@/hooks/useTextColor'; 10*bf6e62f2S猫头猫import Color from 'color'; 11*bf6e62f2S猫头猫 12*bf6e62f2S猫头猫interface ISeekBarProps {} 13*bf6e62f2S猫头猫export default function SeekBar(props: ISeekBarProps) { 14*bf6e62f2S猫头猫 const progress = MusicQueue.useProgress(800); 15*bf6e62f2S猫头猫 const [tmpProgress, setTmpProgress] = useState<number | null>(null); 16*bf6e62f2S猫头猫 const textColor = useTextColor(); 17*bf6e62f2S猫头猫 18*bf6e62f2S猫头猫 return ( 19*bf6e62f2S猫头猫 <View style={style.wrapper}> 20*bf6e62f2S猫头猫 <ThemeText type='secondary' style={style.text}>{timeformat(tmpProgress ?? progress.position)}</ThemeText> 21*bf6e62f2S猫头猫 <Slider 22*bf6e62f2S猫头猫 style={style.slider} 23*bf6e62f2S猫头猫 minimumTrackTintColor={textColor} 24*bf6e62f2S猫头猫 maximumTrackTintColor={Color(textColor).alpha(0.7).toString()} 25*bf6e62f2S猫头猫 thumbTintColor={textColor} 26*bf6e62f2S猫头猫 minimumValue={0} 27*bf6e62f2S猫头猫 maximumValue={progress.duration} 28*bf6e62f2S猫头猫 onValueChange={(val)=>{ 29*bf6e62f2S猫头猫 setTmpProgress(val); 30*bf6e62f2S猫头猫 }} 31*bf6e62f2S猫头猫 onSlidingComplete={(val) => { 32*bf6e62f2S猫头猫 setTmpProgress(null); 33*bf6e62f2S猫头猫 MusicQueue.seekTo(val); 34*bf6e62f2S猫头猫 }} 35*bf6e62f2S猫头猫 value={progress.position}></Slider> 36*bf6e62f2S猫头猫 <ThemeText type='secondary' style={style.text}>{timeformat(progress.duration)}</ThemeText> 37*bf6e62f2S猫头猫 </View> 38*bf6e62f2S猫头猫 ); 39*bf6e62f2S猫头猫} 40*bf6e62f2S猫头猫 41*bf6e62f2S猫头猫const style = StyleSheet.create({ 42*bf6e62f2S猫头猫 wrapper: { 43*bf6e62f2S猫头猫 width: rpx(750), 44*bf6e62f2S猫头猫 height: rpx(40), 45*bf6e62f2S猫头猫 justifyContent: 'center', 46*bf6e62f2S猫头猫 alignItems: 'center', 47*bf6e62f2S猫头猫 flexDirection: 'row', 48*bf6e62f2S猫头猫 }, 49*bf6e62f2S猫头猫 slider: { 50*bf6e62f2S猫头猫 width: rpx(550), 51*bf6e62f2S猫头猫 height: rpx(40), 52*bf6e62f2S猫头猫 }, 53*bf6e62f2S猫头猫 text: { 54*bf6e62f2S猫头猫 fontSize: fontSizeConst.smaller, 55*bf6e62f2S猫头猫 includeFontPadding: false, 56*bf6e62f2S猫头猫 } 57*bf6e62f2S猫头猫}); 58