@internal Called at the end of every animation frame
()
| 273 | |
| 274 | /** @internal Called at the end of every animation frame */ |
| 275 | protected _onFrame() { |
| 276 | const { onStart, onChange, onRest } = this._events |
| 277 | |
| 278 | const active = this._active.size > 0 |
| 279 | const changed = this._changed.size > 0 |
| 280 | |
| 281 | if ((active && !this._started) || (changed && !this._started)) { |
| 282 | this._started = true |
| 283 | flush(onStart, ([onStart, result]) => { |
| 284 | result.value = this.get() |
| 285 | onStart(result, this, this._item) |
| 286 | }) |
| 287 | } |
| 288 | |
| 289 | const idle = !active && this._started |
| 290 | const values = changed || (idle && onRest.size) ? this.get() : null |
| 291 | |
| 292 | if (changed && onChange.size) { |
| 293 | flush(onChange, ([onChange, result]) => { |
| 294 | result.value = values |
| 295 | onChange(result, this, this._item) |
| 296 | }) |
| 297 | } |
| 298 | |
| 299 | // The "onRest" queue is only flushed when all springs are idle. |
| 300 | if (idle) { |
| 301 | this._started = false |
| 302 | flush(onRest, ([onRest, result]) => { |
| 303 | result.value = values |
| 304 | onRest(result, this, this._item) |
| 305 | }) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /** @internal */ |
| 310 | eventObserved(event: FrameValue.Event) { |