Skip to content

Commit 16d75a7

Browse files
authored
feat(ui): refines progress bar animation curve (#11167)
Refines the animation curve used in the new progress bar for route transitions. Uses an exponential acceleration and decay so that the indicator progresses quickly at the onset, then gradually decelerates at it approaches completion. Also caps the progress at ~90%. Introduced in #9275.
1 parent de68ef4 commit 16d75a7

File tree

1 file changed

+14
-5
lines changed
  • packages/ui/src/providers/RouteTransition

1 file changed

+14
-5
lines changed

packages/ui/src/providers/RouteTransition/index.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ export const RouteTransitionProvider: React.FC<RouteTransitionProps> = ({ childr
2626
const timerID = useRef(null)
2727

2828
const initiateProgress = useCallback(() => {
29-
// randomly update progress at random times, never reaching 100%
3029
timerID.current = setInterval(() => {
31-
const projectedProgress =
32-
transitionProgressRef.current + Math.random() * 0.1 * (1 - transitionProgressRef.current)
33-
34-
const newProgress = projectedProgress >= 1 ? 1 : projectedProgress
30+
// randomly update progress using an exponential curve
31+
// cap the progress to ensure it never fully reaches completion
32+
// accelerate quickly then decelerate slowly
33+
const maxProgress = 0.93
34+
const jumpFactor = 0.2 // lower to reduce jumps in progress
35+
const growthFactor = 0.75 // adjust to control acceleration
36+
const slowdownFactor = 0.75 // adjust to control deceleration
37+
38+
const newProgress =
39+
transitionProgressRef.current +
40+
(maxProgress - transitionProgressRef.current) *
41+
Math.random() *
42+
jumpFactor *
43+
Math.pow(Math.log(1 + (1 - transitionProgressRef.current) * growthFactor), slowdownFactor)
3544

3645
setTransitionProgress(newProgress)
3746
transitionProgressRef.current = newProgress

0 commit comments

Comments
 (0)