| 21 | SpringAnimation::~SpringAnimation() = default; |
| 22 | |
| 23 | bool SpringAnimation::run(Layer& layer, Duration delta) { |
| 24 | if (!_started) { |
| 25 | _applier(layer, 0.0); |
| 26 | _started = true; |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | if (_endRequested) { |
| 31 | if (_pendingPosition != kMax) { |
| 32 | _spring.setFinalPosition(_pendingPosition); |
| 33 | _pendingPosition = kMax; |
| 34 | } |
| 35 | _value = _spring.getFinalPosition(); |
| 36 | _velocity = 0; |
| 37 | _endRequested = false; |
| 38 | return true; |
| 39 | } |
| 40 | if (_pendingPosition != kMax) { |
| 41 | // Approximate by considering half of the time spring position stayed at the old |
| 42 | // position, half of the time it's at the new position. |
| 43 | MassState massState = _spring.updateValues(_value, _velocity, delta.milliseconds() / 2); |
| 44 | _spring.setFinalPosition(_pendingPosition); |
| 45 | _pendingPosition = kMax; |
| 46 | massState = _spring.updateValues(massState.value, massState.velocity, delta.milliseconds() / 2); |
| 47 | _value = massState.value; |
| 48 | _velocity = massState.velocity; |
| 49 | } else { |
| 50 | MassState massState = _spring.updateValues(_value, _velocity, delta.milliseconds()); |
| 51 | _value = massState.value; |
| 52 | _velocity = massState.velocity; |
| 53 | } |
| 54 | _value = fmax(_value, kMin); |
| 55 | _value = fmin(_value, kMax); |
| 56 | if (_spring.isAtEquilibrium(_value, _velocity)) { |
| 57 | _value = _spring.getFinalPosition(); |
| 58 | _velocity = 0; |
| 59 | _applier(layer, _value); |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | _applier(layer, _value); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | void SpringAnimation::cancel(Layer& layer) { |
| 68 | finish(layer, false); |
nothing calls this directly
no test coverage detected