Files
address-verification-app/ProgressBar.tsx

51 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-09-09 14:27:20 +05:30
import { COLORS } from '@rn-ui-lib/colors';
import React, { useState, useEffect } from 'react';
import { View, Animated, StyleSheet } from 'react-native';
2024-09-09 14:27:20 +05:30
2024-09-20 16:25:11 +05:30
type ProgressBarProps = {
2024-09-20 16:47:57 +05:30
progress: number;
height?: number;
color?: string;
};
2024-09-20 16:25:11 +05:30
const ProgressBar = ({ progress, height = 10, color = COLORS.TEXT.BLUE }: ProgressBarProps) => {
2024-09-09 14:27:20 +05:30
const [animatedWidth] = useState(new Animated.Value(0));
useEffect(() => {
Animated.timing(animatedWidth, {
toValue: progress * 100,
useNativeDriver: false,
}).start();
}, [progress]);
return (
<View style={[styles.container, { height }]}>
<Animated.View
style={[
styles.fill,
2024-09-09 14:28:08 +05:30
{
width: animatedWidth.interpolate({
inputRange: [0, 100],
outputRange: ['0%', '100%'],
}),
backgroundColor: color,
},
2024-09-09 14:27:20 +05:30
]}
/>
</View>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: '#e0e0e0',
borderRadius: 8,
overflow: 'hidden',
},
fill: {
height: '100%',
},
});
export default ProgressBar;