ProgressBar.tsx
1.04 KB
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
import React, { useEffect, useMemo, useState, useRef } from 'react';
import { Animated, StyleSheet } from 'react-native';
import * as Progress from 'react-native-progress';
const styles = StyleSheet.create({
progressBar: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
height: 1,
},
});
export default function ProgressBar({
progress,
loading,
}: {
progress: number;
loading: boolean;
}) {
const progressBarOpacity = useRef(new Animated.Value(1)).current;
useEffect(() => {
if (!loading) {
Animated.timing(progressBarOpacity, {
toValue: 0,
useNativeDriver: true,
duration: 1000,
}).start();
} else {
progressBarOpacity.setValue(1);
}
}, [loading, progressBarOpacity]);
return (
<Animated.View
style={[{ opacity: progressBarOpacity }, styles.progressBar]}
>
<Progress.Bar
progress={progress}
borderWidth={0}
borderRadius={0}
width={null}
height={4}
useNativeDriver
/>
</Animated.View>
);
}