import { useState } from 'react'; import { StyleSheet, View } from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'; import type { FCCWD, ProgressBarProps } from '../../types'; import { applyDefaults } from '../../core/KitraProvider'; const ProgressBar: FCCWD = ({ theme, progress = 0, barColor, progressColor, progressStyle, testID }) => { const offset = useSharedValue(progress); const [barWidth, setBarWidth] = useState(0); offset.value = progress; const animatedStyle = useAnimatedStyle(() => ({ width: withTiming((offset.value / 100) * barWidth, { duration: 400, }), })); return ( setBarWidth(x.nativeEvent.layout.width)} style={[Style.container, { backgroundColor: barColor || theme?.primary15 }]} > ); }; export default applyDefaults(ProgressBar); export const Style = StyleSheet.create({ container: { backgroundColor: 'transparent', height: 2, width: '100%', overflow: 'visible', justifyContent: 'center' }, progressStyle: { borderRadius: 14, position: 'absolute', height: 4 }, });