@@ -38,6 +38,8 @@ import type {DecayAnimationConfig} from './animations/DecayAnimation';
38
38
import type { SpringAnimationConfig } from './animations/SpringAnimation' ;
39
39
import type { Mapping , EventConfig } from './AnimatedEvent' ;
40
40
41
+ import AnimatedColor from './nodes/AnimatedColor' ;
42
+
41
43
export type CompositeAnimation = {
42
44
start : ( callback ?: ?EndCallback ) => void ,
43
45
stop : ( ) => void ,
@@ -102,7 +104,7 @@ const _combineCallbacks = function (
102
104
} ;
103
105
104
106
const maybeVectorAnim = function (
105
- value : AnimatedValue | AnimatedValueXY ,
107
+ value : AnimatedValue | AnimatedValueXY | AnimatedColor ,
106
108
config : Object ,
107
109
anim : ( value : AnimatedValue , config : Object ) = > CompositeAnimation ,
108
110
) : ?CompositeAnimation {
@@ -121,16 +123,42 @@ const maybeVectorAnim = function (
121
123
// We use `stopTogether: false` here because otherwise tracking will break
122
124
// because the second animation will get stopped before it can update.
123
125
return parallel ( [ aX , aY ] , { stopTogether : false } ) ;
126
+ } else if ( value instanceof AnimatedColor ) {
127
+ const configR = { ...config } ;
128
+ const configG = { ...config } ;
129
+ const configB = { ...config } ;
130
+ const configA = { ...config } ;
131
+ for ( const key in config ) {
132
+ const { r, g, b, a} = config [ key ] ;
133
+ if (
134
+ r !== undefined &&
135
+ g !== undefined &&
136
+ b !== undefined &&
137
+ a !== undefined
138
+ ) {
139
+ configR [ key ] = r ;
140
+ configG [ key ] = g ;
141
+ configB [ key ] = b ;
142
+ configA [ key ] = a ;
143
+ }
144
+ }
145
+ const aR = anim ( ( value : AnimatedColor ) . r , configR ) ;
146
+ const aG = anim ( ( value : AnimatedColor ) . g , configG ) ;
147
+ const aB = anim ( ( value : AnimatedColor ) . b , configB ) ;
148
+ const aA = anim ( ( value : AnimatedColor ) . a , configA ) ;
149
+ // We use `stopTogether: false` here because otherwise tracking will break
150
+ // because the second animation will get stopped before it can update.
151
+ return parallel ( [ aR , aG , aB , aA ] , { stopTogether : false } ) ;
124
152
}
125
153
return null ;
126
154
} ;
127
155
128
156
const spring = function (
129
- value : AnimatedValue | AnimatedValueXY ,
157
+ value : AnimatedValue | AnimatedValueXY | AnimatedColor ,
130
158
config : SpringAnimationConfig ,
131
159
) : CompositeAnimation {
132
160
const start = function (
133
- animatedValue : AnimatedValue | AnimatedValueXY ,
161
+ animatedValue : AnimatedValue | AnimatedValueXY | AnimatedColor ,
134
162
configuration : SpringAnimationConfig ,
135
163
callback ?: ?EndCallback ,
136
164
) : void {
@@ -179,11 +207,11 @@ const spring = function (
179
207
} ;
180
208
181
209
const timing = function (
182
- value : AnimatedValue | AnimatedValueXY ,
210
+ value : AnimatedValue | AnimatedValueXY | AnimatedColor ,
183
211
config : TimingAnimationConfig ,
184
212
) : CompositeAnimation {
185
213
const start = function (
186
- animatedValue : AnimatedValue | AnimatedValueXY ,
214
+ animatedValue : AnimatedValue | AnimatedValueXY | AnimatedColor ,
187
215
configuration : TimingAnimationConfig ,
188
216
callback ?: ?EndCallback ,
189
217
) : void {
@@ -233,11 +261,11 @@ const timing = function (
233
261
} ;
234
262
235
263
const decay = function (
236
- value : AnimatedValue | AnimatedValueXY ,
264
+ value : AnimatedValue | AnimatedValueXY | AnimatedColor ,
237
265
config : DecayAnimationConfig ,
238
266
) : CompositeAnimation {
239
267
const start = function (
240
- animatedValue : AnimatedValue | AnimatedValueXY ,
268
+ animatedValue : AnimatedValue | AnimatedValueXY | AnimatedColor ,
241
269
configuration : DecayAnimationConfig ,
242
270
callback ?: ?EndCallback ,
243
271
) : void {
@@ -547,6 +575,10 @@ module.exports = {
547
575
* See https://reactnative.dev/docs/animatedvaluexy
548
576
*/
549
577
ValueXY : AnimatedValueXY ,
578
+ /**
579
+ * Value class for driving color animations.
580
+ */
581
+ Color : AnimatedColor ,
550
582
/**
551
583
* Exported to use the Interpolation type in flow.
552
584
*
0 commit comments