import { useEffect, useRef } from "react"; import { Animated, StyleSheet, Text, View } from "react-native"; // Default colors - using black and white as defaults const defaultColors = { white: "#FFFFFF", black: "#000000", darkGray: "#1C1C1E", forest_green: "#228B22", // Keep forest_green for progress bar }; interface CustomProgressBarProps { progress?: number; width?: number; height?: number; color?: string; backgroundColor?: string; label?: string; variant?: "normal" | "count"; count?: number; currentCount?: number; } const CustomProgressBar: React.FC = ({ progress, width = 300, height = 20, color = defaultColors.forest_green, backgroundColor = "#e0e0e0", label = "", variant = "normal", count = 1, currentCount = 0, }) => { let calculatedProgress = 0; if (variant === "normal") { calculatedProgress = Math.min(Math.max(progress || 0, 0), 100); } else if (variant === "count" && count > 0) { calculatedProgress = (currentCount / count) * 100; } const animatedWidth = useRef(new Animated.Value(0)).current; useEffect(() => { Animated.timing(animatedWidth, { toValue: (calculatedProgress / 100) * width, duration: 500, useNativeDriver: false, }).start(); }, [calculatedProgress, width]); return ( {label && ( {label} )} {variant === "count" && ( {currentCount} {count} )} ); }; const styles = StyleSheet.create({ container: { justifyContent: "center", alignItems: "center", }, label: { fontSize: 16, marginBottom: 8, fontWeight: "bold", }, progressBarContainer: { borderRadius: 10, overflow: "hidden", }, progressBar: { borderRadius: 10, }, }); export default CustomProgressBar;