File size: 998 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { each, eachProp, getFluidValue } from '@react-spring/shared'
import { Animated, AnimatedValue, AnimatedObject } from '@react-spring/animated'

type Transform = { [key: string]: string | number | Animated }

type Source = Transform[]

export class AnimatedTransform extends AnimatedObject {
  declare protected source: Source
  constructor(source: Source) {
    super(source)
  }

  getValue() {
    return this.source
      ? this.source.map(source => {
          const transform: any = {}
          eachProp(source, (source, key) => {
            transform[key] = getFluidValue(source)
          })
          return transform
        })
      : []
  }

  setValue(source: Source) {
    this.source = source
    this.payload = this._makePayload(source)
  }

  protected _makePayload(source: Source) {
    if (!source) return []
    const payload = new Set<AnimatedValue>()
    each(source, transform => eachProp(transform, this._addToPayload, payload))
    return Array.from(payload)
  }
}