-
Notifications
You must be signed in to change notification settings - Fork 52
/
Progress.tsx
42 lines (37 loc) · 944 Bytes
/
Progress.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useEffect, useRef } from 'react';
import { Animated, View as RnView, type View } from 'react-native';
import { cn } from '../lib/utils';
function Progress({
className,
...props
}: { className?: string; value: number } & React.ComponentPropsWithoutRef<
typeof View
>) {
const widthAnim = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.timing(widthAnim, {
toValue: props.value,
duration: 1000,
useNativeDriver: false,
}).start();
}, [widthAnim, props.value]);
return (
<RnView
className={cn(
'h-4 w-full overflow-hidden rounded-full bg-secondary',
className
)}
>
<Animated.View
className={cn('bg-primary h-full')}
style={{
width: widthAnim.interpolate({
inputRange: [0, 100],
outputRange: ['0%', '100%'],
}),
}}
/>
</RnView>
);
}
export { Progress };