Skip to content

Commit 4ab33f8

Browse files
committed
interpolation
1 parent 46b01bf commit 4ab33f8

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

spring/src/Interpolation.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { FluidValue } from "./fluids"
2-
import { FrameValue } from "./FrameValue"
3-
import { Any } from "./utils"
1+
import * as G from './globals'
2+
import { getAnimated, getPayload, setAnimated } from "./animated"
3+
import { createInterpolator } from "./createInterpolator"
4+
import { addFluidObserver, callFluidObservers, FluidValue, getFluidValue, hasFluidValue, removeFluidObserver } from "./fluids"
5+
import { frameLoop } from "./FrameLoop"
6+
import { FrameValue, isFrameValue } from "./FrameValue"
7+
import { raf } from "./rafz"
8+
import { Any, toArray, each, getAnimatedType, isEqual, is } from "./utils"
49

510
export type Animatable<T = any> = T extends number
611
? number
@@ -245,3 +250,32 @@ export interface InterpolatorFactory {
245250

246251
<In, Out>(...args: InterpolatorArgs<In, Out>): InterpolatorFn<In, Out>
247252
}
253+
254+
255+
/** Returns true for an idle source. */
256+
function isIdle(source: any) {
257+
return source.idle !== false
258+
}
259+
260+
/** Return true if all values in the given set are idle or paused. */
261+
function checkIdle(active: Set<FluidValue>) {
262+
// Parents can be active even when paused, so the `.every` check
263+
// removes us from the frameloop if all active parents are paused.
264+
return !active.size || Array.from(active).every(isIdle)
265+
}
266+
267+
/** Become idle if not already idle. */
268+
function becomeIdle(self: Interpolation) {
269+
if (!self.idle) {
270+
self.idle = true
271+
272+
each(getPayload(self)!, node => {
273+
node.done = true
274+
})
275+
276+
callFluidObservers(self, {
277+
type: 'idle',
278+
parent: self,
279+
})
280+
}
281+
}

0 commit comments

Comments
 (0)