diff options
author | Ivan Chen <ivan@tagg.id> | 2021-07-20 17:58:31 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-07-20 17:58:31 -0400 |
commit | 74c853034e893aeda18ee78f59e4539fba6d8fc0 (patch) | |
tree | 01a114c3e48ae5ef3231b7cbba30c03e550196ec /src | |
parent | 3d616c5d445919c476aa926c6d2c44db38cbab37 (diff) |
Fix logic to make progress bar work
Diffstat (limited to 'src')
-rw-r--r-- | src/components/common/GradientProgressBar.tsx | 10 | ||||
-rw-r--r-- | src/components/moments/MomentUploadProgressBar.tsx | 18 |
2 files changed, 18 insertions, 10 deletions
diff --git a/src/components/common/GradientProgressBar.tsx b/src/components/common/GradientProgressBar.tsx index 2f7f0431..fc62bd3c 100644 --- a/src/components/common/GradientProgressBar.tsx +++ b/src/components/common/GradientProgressBar.tsx @@ -1,6 +1,7 @@ import React, {FC} from 'react'; -import {StyleSheet, View, ViewProps} from 'react-native'; +import {StyleSheet, ViewProps, ViewStyle} from 'react-native'; import LinearGradient from 'react-native-linear-gradient'; +import Animated, {useAnimatedStyle} from 'react-native-reanimated'; import { TAGG_LIGHT_BLUE_2, TAGG_LIGHT_BLUE_3, @@ -9,19 +10,22 @@ import { import {normalize} from '../../utils'; interface GradientProgressBarProps extends ViewProps { - progress: number; + progress: Animated.SharedValue<number>; } const GradientProgressBar: FC<GradientProgressBarProps> = ({ style, progress, }) => { + const animatedProgressStyle = useAnimatedStyle<ViewStyle>(() => ({ + width: `${(1 - progress.value) * 100}%`, + })); return ( <LinearGradient style={[styles.bar, style]} useAngle={true} colors={[TAGG_PURPLE, TAGG_LIGHT_BLUE_2]}> - <View style={[styles.blank, {width: `${(1 - progress) * 100}%`}]} /> + <Animated.View style={[styles.blank, animatedProgressStyle]} /> </LinearGradient> ); }; diff --git a/src/components/moments/MomentUploadProgressBar.tsx b/src/components/moments/MomentUploadProgressBar.tsx index 7310727e..26c20a46 100644 --- a/src/components/moments/MomentUploadProgressBar.tsx +++ b/src/components/moments/MomentUploadProgressBar.tsx @@ -1,6 +1,7 @@ -import React from 'react'; +import React, {useEffect} from 'react'; import {StyleSheet, Text} from 'react-native'; import {View} from 'react-native-animatable'; +import {Easing, useSharedValue, withTiming} from 'react-native-reanimated'; import {SafeAreaView} from 'react-native-safe-area-context'; import {useSelector} from 'react-redux'; import {RootState} from '../../store/rootReducer'; @@ -12,17 +13,20 @@ interface MomentUploadProgressBarProps {} const MomentUploadProgressBar: React.FC<MomentUploadProgressBarProps> = ({}) => { const {momentUploadStatus} = useSelector((state: RootState) => state.user); - // const [progress, setProgress] = useState(0); - // const progressTime = useSharedValue<number>(0); - // const [indeterminate, setIndeterminate] = useState(false); - // const range = new Animated.Value(0); - // const transX = new Animated.Value(0); + const progress = useSharedValue(0); + + useEffect(() => { + progress.value = withTiming(1, { + duration: 5000, + easing: Easing.linear, + }); + }, []); return ( <View style={styles.background}> <SafeAreaView style={styles.container}> <Text style={styles.text}>Uploading Moment...</Text> - <GradientProgressBar style={styles.bar} progress={0.6} /> + <GradientProgressBar style={styles.bar} progress={progress} /> </SafeAreaView> </View> ); |