forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.tsx
56 lines (52 loc) · 1.21 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import { View, ViewStyle } from 'react-native';
import Animated, {
Extrapolate,
SharedValue,
interpolate,
useAnimatedStyle,
withSpring,
} from 'react-native-reanimated';
import { cn } from '~/lib/utils';
const Progress = React.forwardRef<
React.ElementRef<typeof Animated.View>,
Omit<React.ComponentPropsWithoutRef<typeof Animated.View>, 'style'> & {
/**
* Value between 0 and 100
*/
progress: SharedValue<number>;
rootClass?: string;
style?: ViewStyle;
}
>(({ progress, rootClass, className, style, ...props }, ref) => {
const stylez = useAnimatedStyle(() => {
return {
width: withSpring(
`${interpolate(
progress.value,
[0, 100],
[1, 100],
Extrapolate.CLAMP
)}%`,
{ overshootClamping: true }
),
};
});
return (
<View
className={cn(
'rounded-xl h-4 bg-border overflow-hidden relative',
rootClass
)}
role='progressbar'
>
<Animated.View
style={[stylez, style]}
className={cn('h-full bg-foreground', className)}
{...props}
/>
</View>
);
});
Progress.displayName = 'Progress';
export { Progress };