@@ -69,6 +69,9 @@ export class Controller<State extends Lookup = Lookup>
69
69
/** The values currently being animated */
70
70
protected _active = new Set < FrameValue > ( )
71
71
72
+ /** Equals false when `onStart` listeners can be called */
73
+ protected _started = false
74
+
72
75
/** State used by the `runAsync` function */
73
76
protected _state : RunAsyncState < State > = {
74
77
timeouts : new Set ( ) ,
@@ -184,11 +187,14 @@ export class Controller<State extends Lookup = Lookup>
184
187
/** Resume the animation if paused. */
185
188
resume ( keys ?: OneOrMore < string > ) {
186
189
if ( is . und ( keys ) ) {
190
+ // The `idle` property treats paused springs as idle, so we need
191
+ // to resume every spring before updating our `_phase` with it.
192
+ this . each ( spring => spring . resume ( ) )
193
+
187
194
if ( this . is ( PAUSED ) ) {
188
- this . _phase = this . _active . size ? ACTIVE : IDLE
195
+ this . _phase = this . idle ? IDLE : ACTIVE
189
196
flushCalls ( this . _state . resumeQueue )
190
197
}
191
- this . each ( spring => spring . resume ( ) )
192
198
} else {
193
199
const springs = this . springs as Lookup < SpringValue >
194
200
each ( toArray ( keys ) , key => springs [ key ] . resume ( ) )
@@ -213,8 +219,8 @@ export class Controller<State extends Lookup = Lookup>
213
219
const { onStart, onChange, onRest } = this . _events
214
220
215
221
const isActive = this . _active . size > 0
216
- if ( isActive && this . _phase != ACTIVE ) {
217
- this . _phase = ACTIVE
222
+ if ( isActive && ! this . _started ) {
223
+ this . _started = true
218
224
flushCalls ( onStart , this )
219
225
}
220
226
@@ -225,7 +231,10 @@ export class Controller<State extends Lookup = Lookup>
225
231
226
232
// The "onRest" queue is only flushed when all springs are idle.
227
233
if ( ! isActive ) {
228
- this . _phase = IDLE
234
+ this . _started = false
235
+ if ( ! this . is ( PAUSED ) && this . idle ) {
236
+ this . _phase = IDLE
237
+ }
229
238
flush ( onRest , ( [ onRest , result ] ) => {
230
239
result . value = values
231
240
onRest ( result )
0 commit comments