aboutsummaryrefslogtreecommitdiff
path: root/src/components/common/GradientProgressBar.tsx
blob: 066295d09c4379804a376f755247fa73813d3705 (plain)
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
57
import React, {FC} from 'react';
import {StyleSheet, ViewProps, ViewStyle} from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import Animated, {useAnimatedStyle} from 'react-native-reanimated';
import {normalize} from '../../utils';

interface GradientProgressBarProps extends ViewProps {
  progress: Animated.SharedValue<number>;
  toColor: string;
  fromColor: string;
  unfilledColor: string;
}

const GradientProgressBar: FC<GradientProgressBarProps> = ({
  style,
  progress,
  toColor,
  fromColor,
  unfilledColor,
}) => {
  const animatedProgressStyle = useAnimatedStyle<ViewStyle>(() => ({
    width: `${(1 - progress.value) * 100}%`,
  }));
  return (
    <LinearGradient
      style={[styles.bar, style]}
      useAngle={true}
      colors={[fromColor, toColor]}>
      <Animated.View
        style={[
          styles.blank,
          animatedProgressStyle,
          {
            backgroundColor: unfilledColor,
          },
        ]}
      />
    </LinearGradient>
  );
};
const styles = StyleSheet.create({
  container: {
    borderRadius: 6.5,
  },
  bar: {
    height: normalize(10),
    borderRadius: 6.5,
    opacity: 1,
  },
  blank: {
    alignSelf: 'flex-end',
    height: normalize(10),
    width: '80%',
  },
});

export default GradientProgressBar;