Skip to content

Commit 3d63523

Browse files
committed
fix(Controller): stop tracking onStart calls via the _phase property
It was messing with the pausing functionality.
1 parent b0f6dbf commit 3d63523

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/core/src/Controller.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export class Controller<State extends Lookup = Lookup>
6969
/** The values currently being animated */
7070
protected _active = new Set<FrameValue>()
7171

72+
/** Equals false when `onStart` listeners can be called */
73+
protected _started = false
74+
7275
/** State used by the `runAsync` function */
7376
protected _state: RunAsyncState<State> = {
7477
timeouts: new Set(),
@@ -184,11 +187,14 @@ export class Controller<State extends Lookup = Lookup>
184187
/** Resume the animation if paused. */
185188
resume(keys?: OneOrMore<string>) {
186189
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+
187194
if (this.is(PAUSED)) {
188-
this._phase = this._active.size ? ACTIVE : IDLE
195+
this._phase = this.idle ? IDLE : ACTIVE
189196
flushCalls(this._state.resumeQueue)
190197
}
191-
this.each(spring => spring.resume())
192198
} else {
193199
const springs = this.springs as Lookup<SpringValue>
194200
each(toArray(keys), key => springs[key].resume())
@@ -213,8 +219,8 @@ export class Controller<State extends Lookup = Lookup>
213219
const { onStart, onChange, onRest } = this._events
214220

215221
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
218224
flushCalls(onStart, this)
219225
}
220226

@@ -225,7 +231,10 @@ export class Controller<State extends Lookup = Lookup>
225231

226232
// The "onRest" queue is only flushed when all springs are idle.
227233
if (!isActive) {
228-
this._phase = IDLE
234+
this._started = false
235+
if (!this.is(PAUSED) && this.idle) {
236+
this._phase = IDLE
237+
}
229238
flush(onRest, ([onRest, result]) => {
230239
result.value = values
231240
onRest(result)

0 commit comments

Comments
 (0)