* 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
(cherry picked from commit 9b99c967f4)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user