-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProgressBar.js
38 lines (33 loc) · 920 Bytes
/
ProgressBar.js
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
import React, {useRef, useEffect} from 'react';
import {View, StyleSheet, Animated, Easing} from 'react-native';
const ProgressBar = ({progress, backgroundColor = '#fff'}) => {
const animation = useRef(new Animated.Value(0));
useEffect(() => {
Animated.timing(animation.current, {
toValue: progress,
duration: 250,
useNativeDriver: false,
easing: Easing.quad,
}).start();
}, [progress]);
const width = animation.current.interpolate({
inputRange: [0, 100],
outputRange: ['0%', '100%'],
extrapolate: 'clamp',
});
return (
<View style={[styles.progressBar, {backgroundColor}]}>
<Animated.View
style={([StyleSheet.absoluteFill], {backgroundColor: '#008080', width})}
/>
</View>
);
};
export default ProgressBar;
const styles = StyleSheet.create({
progressBar: {
flexDirection: 'row',
height: 4,
width: '100%',
},
});