Skip to content

Commit 267772e

Browse files
committed
SpringPhase
1 parent 588861f commit 267772e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

spring/src/SpringPhase.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** The property symbol of the current animation phase. */
2+
const $P = Symbol.for('SpringPhase')
3+
4+
const HAS_ANIMATED = 1
5+
const IS_ANIMATING = 2
6+
const IS_PAUSED = 4
7+
8+
/** Returns true if the `target` has ever animated. */
9+
export const hasAnimated = (target: any) => (target[$P] & HAS_ANIMATED) > 0
10+
11+
/** Returns true if the `target` is animating (even if paused). */
12+
export const isAnimating = (target: any) => (target[$P] & IS_ANIMATING) > 0
13+
14+
/** Returns true if the `target` is paused (even if idle). */
15+
export const isPaused = (target: any) => (target[$P] & IS_PAUSED) > 0
16+
17+
/** Set the active bit of the `target` phase. */
18+
export const setActiveBit = (target: any, active: boolean) =>
19+
active
20+
? (target[$P] |= IS_ANIMATING | HAS_ANIMATED)
21+
: (target[$P] &= ~IS_ANIMATING)
22+
23+
export const setPausedBit = (target: any, paused: boolean) =>
24+
paused ? (target[$P] |= IS_PAUSED) : (target[$P] &= ~IS_PAUSED)

0 commit comments

Comments
 (0)