Fix progress bar regression throughout the app (#9219)
* Fix useSmoothAnimation enablement not working properly by getting rid of it Passing duration=0 is more logical and less superfluous * Refactor UploadBar to handle state more correctly * Change ProgressBar to new useSmoothAnimation signature and default animated to true for consistency * Add type guard * Make types stricter * Write tests for the ProgressBar component * Make the new test conform to tsc --strict * Update UploadBar.tsx * Update UploadBar.tsx * Update UploadBar.tsx
This commit is contained in:
parent
6407cd4c0d
commit
9b99c967f4
5 changed files with 105 additions and 37 deletions
|
@ -30,14 +30,12 @@ const debuglog = (...args: any[]) => {
|
|||
* Utility function to smoothly animate to a certain target value
|
||||
* @param initialValue Initial value to be used as initial starting point
|
||||
* @param targetValue Desired value to animate to (can be changed repeatedly to whatever is current at that time)
|
||||
* @param duration Duration that each animation should take
|
||||
* @param enabled Whether the animation should run or not
|
||||
* @param duration Duration that each animation should take, specify 0 to skip animating
|
||||
*/
|
||||
export function useSmoothAnimation(
|
||||
initialValue: number,
|
||||
targetValue: number,
|
||||
duration: number,
|
||||
enabled: boolean,
|
||||
): number {
|
||||
const state = useRef<{ timestamp: DOMHighResTimeStamp | null, value: number }>({
|
||||
timestamp: null,
|
||||
|
@ -79,7 +77,7 @@ export function useSmoothAnimation(
|
|||
[currentStepSize, targetValue],
|
||||
);
|
||||
|
||||
useAnimation(enabled, update);
|
||||
useAnimation(duration > 0, update);
|
||||
|
||||
return currentValue;
|
||||
return duration > 0 ? currentValue : targetValue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue