vaweGitHub

SpringsJetpack Compose

Compose NoBouncy with StiffnessMediumLow

The source comments that StiffnessMediumLow is the default stiffness of the springs in enter and exit transitions. Stiffness 400, damping 40 and mass 1 give a damping ratio of 1, so the spring is about critically damped. It settles to within 0.1% in 0.465 s. It never passes the end value.

Demo

Progress against time. The time axis runs 0 to 0.465 s, the settle time.0100.51progress50%90%
Dashed: a straight line. The dot and the line move with the box on the right.
Compose NoBouncy with StiffnessMediumLow
linear

Both boxes take 0.465 s. Playing at 0.5× speed.

Your system asks for reduced motion, so nothing plays. The chart shows the whole move.

Code

A spring has no fixed duration, so the CSS takes the settle time (465 ms) and a linear() string that follows the spring.

css linear()
transition: translate 465ms linear(0, 0.0063, 0.0232, 0.0484, 0.0798, 0.1158, 0.1549, 0.1962, 0.2385, 0.2812, 0.3238, 0.3656, 0.4064, 0.4459, 0.4839, 0.5202, 0.5548, 0.5875, 0.6185, 0.6476, 0.6749, 0.7004, 0.7243, 0.7465, 0.7672, 0.7864, 0.8042, 0.8206, 0.8358, 0.8499, 0.8628, 0.8747, 0.8856, 0.8957, 0.9049, 0.9133, 0.9211, 0.9282, 0.9346, 0.9406, 0.946, 0.9509, 0.9554, 0.9595, 0.9633, 0.9667, 0.9698, 0.9726, 0.9752, 0.9775, 0.9796, 0.9816, 0.9833, 0.9849, 0.9863, 0.9876, 0.9888, 0.9899, 0.9909, 0.9917, 0.9925, 0.9933, 0.9939, 0.9945, 0.995, 0.9955, 0.996, 0.9964, 0.9967, 0.997, 0.9973, 0.9976, 0.9978, 0.998, 0.9982, 0.9984, 0.9986, 0.9987, 0.9988, 0.999, 1);
web animations api
el.animate({ translate: ['0 0', '240px 0'] }, { duration: 465, easing: 'linear(0, 0.0063, 0.0232, 0.0484, 0.0798, 0.1158, 0.1549, 0.1962, 0.2385, 0.2812, 0.3238, 0.3656, 0.4064, 0.4459, 0.4839, 0.5202, 0.5548, 0.5875, 0.6185, 0.6476, 0.6749, 0.7004, 0.7243, 0.7465, 0.7672, 0.7864, 0.8042, 0.8206, 0.8358, 0.8499, 0.8628, 0.8747, 0.8856, 0.8957, 0.9049, 0.9133, 0.9211, 0.9282, 0.9346, 0.9406, 0.946, 0.9509, 0.9554, 0.9595, 0.9633, 0.9667, 0.9698, 0.9726, 0.9752, 0.9775, 0.9796, 0.9816, 0.9833, 0.9849, 0.9863, 0.9876, 0.9888, 0.9899, 0.9909, 0.9917, 0.9925, 0.9933, 0.9939, 0.9945, 0.995, 0.9955, 0.996, 0.9964, 0.9967, 0.997, 0.9973, 0.9976, 0.9978, 0.998, 0.9982, 0.9984, 0.9986, 0.9987, 0.9988, 0.999, 1)', fill: 'both' });
vawe
import { spring, springDuration, springLinear } from '../../core/motion/springs.js';

const k = 400, d = 40;

// per-frame code (window.seek, vawe.onFrame): t is seconds since the move starts
const x = 240 * spring(t, k, d);

// CSS and Web Animations: 465 ms, the linear() string above
el.animate(
  { translate: ['0 0', '240px 0'] },
  { duration: springDuration(k, d) * 1000, easing: springLinear(k, d), fill: 'both' },
);

Numbers

Stiffness
400k, with mass 1
Damping
40d, with mass 1
Damping ratio
1about critically damped
Settle time
0.465 swithin 0.1% of the end
Overshoot
0%stays inside the end
Crosses the end
0times
50% of travel
0.084 s18% of the settle time
90% of travel
0.195 s42% of the settle time
Natural frequency
20 rad/ssqrt(k)
Ring period
noneit does not oscillate
Peak speed
3.42xtimes the average speed
linear() points
81within 0.15% of travel

Computed with spring() and springDuration() from core/motion/springs.js. The settle time is the last moment the spring is more than 0.1% away from the end value; a library stops its own spring by its own rest thresholds, so its clock can run shorter.

Source of the numbers

Jetpack Composeandroidx main at 9adbcd8 (compose animation-core 1.14.0-alpha01)
spring(dampingRatio = Spring.DampingRatioNoBouncy (1), stiffness = Spring.StiffnessMediumLow (400))Spring.DampingRatioNoBouncy, Spring.StiffnessMediumLow

Conversion: Stiffness is used as it is with mass 1 (SpringSimulation takes the natural frequency as sqrt(stiffness)). damping = 2 x dampingRatio x sqrt(stiffness), the same c = 2 x naturalFreq x dampingRatio that SpringSimulation.getAcceleration uses.

The four closest curves in this set, by the average gap between the two springs over their first seconds. A gap of 0.01 is invisible; 0.1 is a different feel.

More springs