({
color,
indeterminate,
progress = 0,
visible = true,
theme: themeOverrides,
animatedValue,
style,
fillStyle,
testID = 'progress-bar',
...rest
}: Props)
| 73 | * ``` |
| 74 | */ |
| 75 | const ProgressBar = ({ |
| 76 | color, |
| 77 | indeterminate, |
| 78 | progress = 0, |
| 79 | visible = true, |
| 80 | theme: themeOverrides, |
| 81 | animatedValue, |
| 82 | style, |
| 83 | fillStyle, |
| 84 | testID = 'progress-bar', |
| 85 | ...rest |
| 86 | }: Props) => { |
| 87 | const isWeb = Platform.OS === 'web'; |
| 88 | const theme = useInternalTheme(themeOverrides); |
| 89 | const { current: timer } = React.useRef<Animated.Value>( |
| 90 | new Animated.Value(0) |
| 91 | ); |
| 92 | const { current: fade } = React.useRef<Animated.Value>(new Animated.Value(0)); |
| 93 | const passedAnimatedValue = |
| 94 | React.useRef<Props['animatedValue']>(animatedValue); |
| 95 | const [width, setWidth] = React.useState<number>(0); |
| 96 | const [prevWidth, setPrevWidth] = React.useState<number>(0); |
| 97 | |
| 98 | const indeterminateAnimation = |
| 99 | React.useRef<Animated.CompositeAnimation | null>(null); |
| 100 | |
| 101 | const { scale } = theme.animation; |
| 102 | |
| 103 | React.useEffect(() => { |
| 104 | passedAnimatedValue.current = animatedValue; |
| 105 | }); |
| 106 | |
| 107 | const startAnimation = React.useCallback(() => { |
| 108 | // Show progress bar |
| 109 | Animated.timing(fade, { |
| 110 | duration: 200 * scale, |
| 111 | toValue: 1, |
| 112 | useNativeDriver: true, |
| 113 | isInteraction: false, |
| 114 | }).start(); |
| 115 | |
| 116 | /** |
| 117 | * We shouldn't add @param animatedValue to the |
| 118 | * deps array, to avoid the unnecessary loop. |
| 119 | * We can only check if the prop is passed initially, |
| 120 | * and we do early return. |
| 121 | */ |
| 122 | const externalAnimation = |
| 123 | typeof passedAnimatedValue.current !== 'undefined' && |
| 124 | passedAnimatedValue.current >= 0; |
| 125 | |
| 126 | if (externalAnimation) { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | // Animate progress bar |
| 131 | if (indeterminate) { |
| 132 | if (!indeterminateAnimation.current) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…