@@ -91,6 +91,7 @@ export default class AnimatedColor extends AnimatedWithChildren {
91
91
g : AnimatedValue ;
92
92
b : AnimatedValue ;
93
93
a : AnimatedValue ;
94
+ nativeColor : Object ;
94
95
_listeners : {
95
96
[ key : string ] : {
96
97
r : string ,
@@ -105,8 +106,16 @@ export default class AnimatedColor extends AnimatedWithChildren {
105
106
constructor ( valueIn ?: ?( RgbaValue | RgbaAnimatedValue | ColorValue ) ) {
106
107
super ( ) ;
107
108
let value : RgbaValue | RgbaAnimatedValue | ColorValue =
108
- valueIn || defaultColor ;
109
+ valueIn ?? defaultColor ;
110
+ this . setValue ( value ) ;
111
+ this . _listeners = { } ;
112
+ }
109
113
114
+ /**
115
+ * Directly set the value. This will stop any animations running on the value
116
+ * and update all the bound properties.
117
+ */
118
+ setValue ( value : RgbaValue | RgbaAnimatedValue | ColorValue ) : void {
110
119
if ( isRgbaAnimatedValue ( value ) ) {
111
120
// $FlowIgnore[incompatible-cast] - Type is verified above
112
121
const rgbaAnimatedValue : RgbaAnimatedValue = ( value : RgbaAnimatedValue ) ;
@@ -118,37 +127,58 @@ export default class AnimatedColor extends AnimatedWithChildren {
118
127
// Handle potential parsable string color or platform color object
119
128
if ( ! isRgbaValue ( value ) ) {
120
129
// $FlowIgnore[incompatible-cast] - Type is verified via conditionals
121
- value = processColor ( ( value : ColorValue ) ) || { r : 0 , g : 0 , b : 0 , a : 1.0 } ;
122
- // TODO: support platform color
130
+ value = processColor ( ( value : ColorValue ) ) ?? defaultColor ;
123
131
}
124
132
125
- // $FlowIgnore[incompatible-cast] - Type is verified via conditionals
126
- const rgbaValue : RgbaValue = ( value : RgbaValue ) ;
127
- this . r = new AnimatedValue ( rgbaValue . r ) ;
128
- this . g = new AnimatedValue ( rgbaValue . g ) ;
129
- this . b = new AnimatedValue ( rgbaValue . b ) ;
130
- this . a = new AnimatedValue ( rgbaValue . a ) ;
131
- }
132
- this . _listeners = { } ;
133
- }
133
+ if ( ! isRgbaValue ( value ) ) {
134
+ // We are using a platform color
135
+ this . nativeColor = value ;
136
+ value = defaultColor ;
137
+ }
134
138
135
- /**
136
- * Directly set the value. This will stop any animations running on the value
137
- * and update all the bound properties.
138
- */
139
- setValue ( value : { r : number , g : number , b : number , a : number , ...} ) : void {
140
- this . r . setValue ( value . r ) ;
141
- this . g . setValue ( value . g ) ;
142
- this . b . setValue ( value . b ) ;
143
- this . a . setValue ( value . a ) ;
139
+ if ( isRgbaValue ( value ) ) {
140
+ // $FlowIgnore[incompatible-cast] - Type is verified via conditionals
141
+ const rgbaValue : RgbaValue = ( value : RgbaValue ) ;
142
+
143
+ if ( this . r ) {
144
+ this . r . setValue ( rgbaValue . r ) ;
145
+ } else {
146
+ this . r = new AnimatedValue ( rgbaValue . r ) ;
147
+ }
148
+
149
+ if ( this . g ) {
150
+ this . g . setValue ( rgbaValue . g ) ;
151
+ } else {
152
+ this . g = new AnimatedValue ( rgbaValue . g ) ;
153
+ }
154
+
155
+ if ( this . b ) {
156
+ this . b . setValue ( rgbaValue . b ) ;
157
+ } else {
158
+ this . b = new AnimatedValue ( rgbaValue . b ) ;
159
+ }
160
+
161
+ if ( this . a ) {
162
+ this . a . setValue ( rgbaValue . a ) ;
163
+ } else {
164
+ this . a = new AnimatedValue ( rgbaValue . a ) ;
165
+ }
166
+ }
167
+
168
+ if ( this . nativeColor ) {
169
+ this . __makeNative ( ) ;
170
+ // TODO (T111170195): In order to support setValue() with a platform color, update the
171
+ // native AnimatedNode (if it exists) with a new config.
172
+ }
173
+ }
144
174
}
145
175
146
176
/**
147
177
* Sets an offset that is applied on top of whatever value is set, whether
148
178
* via `setValue`, an animation, or `Animated.event`. Useful for compensating
149
179
* things like the start of a pan gesture.
150
180
*/
151
- setOffset ( offset : { r : number , g : number , b : number , a : number , ... } ) : void {
181
+ setOffset ( offset : RgbaValue ) : void {
152
182
this . r . setOffset ( offset . r ) ;
153
183
this . g . setOffset ( offset . g ) ;
154
184
this . b . setOffset ( offset . b ) ;
@@ -280,6 +310,7 @@ export default class AnimatedColor extends AnimatedWithChildren {
280
310
g : this . g . __getNativeTag ( ) ,
281
311
b : this . b . __getNativeTag ( ) ,
282
312
a : this . a . __getNativeTag ( ) ,
313
+ nativeColor : this . nativeColor ,
283
314
} ;
284
315
}
285
316
}
0 commit comments