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