import React, {useEffect, useState} from 'react'; import {StyleSheet, View} from 'react-native'; import {ControllerConfig, ProgressProps} from '../../types'; type ProgressBarProps = { progress: ProgressProps; config: ControllerConfig; }; const dotSize = 8; const ProgressBar: React.FC = props => { const [width, setWidth] = useState(dotSize); const [cacheX, setCacheX] = useState(0); const [doneX, setDoneX] = useState(0); const {progress, config} = props; useEffect(() => { if (progress.total) { setCacheX((progress.cached / progress.total) * width); setDoneX((progress.current / progress.total) * width); } return () => {}; }, [progress, width]); return ( { setWidth(e.nativeEvent.layout.width); }}> ); }; const styles = StyleSheet.create({ view: { flex: 1, height: 3, borderRadius: 1.5, flexDirection: 'row', alignItems: 'center', }, viewCache: { height: 3, borderRadius: 1.5, position: 'absolute', }, viewCurrect: { height: 3, borderRadius: 1.5, position: 'absolute', }, }); export default ProgressBar;