forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#48772 from nkdengineer/feature/46611
Feature: add loading indicator when ReconnectApp is running
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React, {useEffect} from 'react'; | ||
import Animated, {cancelAnimation, Easing, runOnJS, useAnimatedStyle, useSharedValue, withDelay, withRepeat, withSequence, withTiming} from 'react-native-reanimated'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
|
||
type LoadingBarProps = { | ||
// Whether or not to show the loading bar | ||
shouldShow: boolean; | ||
}; | ||
|
||
function LoadingBar({shouldShow}: LoadingBarProps) { | ||
const left = useSharedValue(0); | ||
const width = useSharedValue(0); | ||
const opacity = useSharedValue(0); | ||
const isVisible = useSharedValue(false); | ||
const styles = useThemeStyles(); | ||
|
||
useEffect(() => { | ||
if (shouldShow) { | ||
// eslint-disable-next-line react-compiler/react-compiler | ||
isVisible.value = true; | ||
left.value = 0; | ||
width.value = 0; | ||
opacity.value = withTiming(1, {duration: CONST.ANIMATED_PROGRESS_BAR_OPACITY_DURATION}); | ||
left.value = withDelay( | ||
CONST.ANIMATED_PROGRESS_BAR_DELAY, | ||
withRepeat( | ||
withSequence( | ||
withTiming(0, {duration: 0}), | ||
withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}), | ||
withTiming(100, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}), | ||
), | ||
-1, | ||
false, | ||
), | ||
); | ||
|
||
width.value = withDelay( | ||
CONST.ANIMATED_PROGRESS_BAR_DELAY, | ||
withRepeat( | ||
withSequence( | ||
withTiming(0, {duration: 0}), | ||
withTiming(100, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}), | ||
withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_DURATION, easing: Easing.bezier(0.65, 0, 0.35, 1)}), | ||
), | ||
-1, | ||
false, | ||
), | ||
); | ||
} else if (isVisible.value) { | ||
opacity.value = withTiming(0, {duration: CONST.ANIMATED_PROGRESS_BAR_OPACITY_DURATION}, () => { | ||
runOnJS(() => { | ||
isVisible.value = false; | ||
cancelAnimation(left); | ||
cancelAnimation(width); | ||
}); | ||
}); | ||
} | ||
// we want to update only when shouldShow changes | ||
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps | ||
}, [shouldShow]); | ||
|
||
const animatedIndicatorStyle = useAnimatedStyle(() => { | ||
return { | ||
left: `${left.value}%`, | ||
width: `${width.value}%`, | ||
}; | ||
}); | ||
|
||
const animatedContainerStyle = useAnimatedStyle(() => { | ||
return { | ||
opacity: opacity.value, | ||
}; | ||
}); | ||
|
||
return ( | ||
<Animated.View style={[styles.progressBarWrapper, animatedContainerStyle]}> | ||
{isVisible.value ? <Animated.View style={[styles.progressBar, animatedIndicatorStyle]} /> : null} | ||
</Animated.View> | ||
); | ||
} | ||
|
||
LoadingBar.displayName = 'ProgressBar'; | ||
|
||
export default LoadingBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters