/
AnimatedTransformMatrix.js
109 lines (97 loc) · 2.63 KB
/
AnimatedTransformMatrix.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class AnimatedTransformMatrix extends AnimatedWithChildren {
_transformMatrix: Array<Object>;
constructor(transformMatrix: Array<Object>) {
super();
this._transformMatrix = transformMatrix;
}
__getValue(): Array<Number> {
return this._transformMatrix.map(x => {
if (x instanceof Animated) {
return x.__getValue();
} else {
return x;
}
});
}
getAnimatedValue(): Array<Number> {
return this._transformMatrix.map(x => {
if (x instanceof Animated) {
return x.getAnimatedValue();
} else {
return x;
}
});
}
attach(): void {
this._transformMatrix.forEach(x => {
if (x instanceof Animated) {
x.addChild(this);
}
});
}
detach(): void {
this._transformMatrix.forEach(x => {
if (x instanceof Animated) {
x.removeChild(this);
}
});
}
}
class AnimatedStyle extends AnimatedWithChildren {
_style: Object;
constructor(style: any) {
super();
style = flattenStyle(style) || {};
if (style.transform) {
style = {
...style,
transform: new AnimatedTransform(style.transform),
};
}
if (style.transformMatrix) {
style = {
...style,
transformMatrix: new AnimatedTransformMatrix(style.transformMatrix),
};
}
this._style = style;
}
__getValue(): Object {
var style = {};
for (var key in this._style) {
var value = this._style[key];
if (value instanceof Animated) {
style[key] = value.__getValue();
} else {
style[key] = value;
}
}
return style;
}
getAnimatedValue(): Object {
var style = {};
for (var key in this._style) {
var value = this._style[key];
if (value instanceof Animated) {
style[key] = value.getAnimatedValue();
}
}
return style;
}
attach(): void {
for (var key in this._style) {
var value = this._style[key];
if (value instanceof Animated) {
value.addChild(this);
}
}
}
detach(): void {
for (var key in this._style) {
var value = this._style[key];
if (value instanceof Animated) {
value.removeChild(this);
}
}
}
}