@@ -141,22 +141,12 @@ function requireNativeComponent(
141
141
viewConfig . directEventTypes = directEventTypes ;
142
142
143
143
for ( const key in nativeProps ) {
144
- let useAttribute = false ;
145
- const attribute = { } ;
144
+ const typeName = nativeProps [ key ] ;
145
+ const diff = getDifferForType ( typeName ) ;
146
+ const process = getProcessorForType ( typeName ) ;
146
147
147
- const differ = TypeToDifferMap [ nativeProps [ key ] ] ;
148
- if ( differ ) {
149
- attribute . diff = differ ;
150
- useAttribute = true ;
151
- }
152
-
153
- const processor = TypeToProcessorMap [ nativeProps [ key ] ] ;
154
- if ( processor ) {
155
- attribute . process = processor ;
156
- useAttribute = true ;
157
- }
158
-
159
- viewConfig . validAttributes [ key ] = useAttribute ? attribute : true ;
148
+ viewConfig . validAttributes [ key ] =
149
+ diff == null && process == null ? true : { diff, process} ;
160
150
}
161
151
162
152
// Unfortunately, the current set up puts the style properties on the top
@@ -186,32 +176,49 @@ function requireNativeComponent(
186
176
return createReactNativeComponentClass ( viewName , getViewConfig ) ;
187
177
}
188
178
189
- const TypeToDifferMap = {
190
- // iOS Types
191
- CATransform3D : matricesDiffer ,
192
- CGPoint : pointsDiffer ,
193
- CGSize : sizesDiffer ,
194
- UIEdgeInsets : insetsDiffer ,
195
- // Android Types
196
- // (not yet implemented)
197
- } ;
179
+ function getDifferForType (
180
+ typeName : string ,
181
+ ) : ?( prevProp : any , nextProp : any ) = > boolean {
182
+ switch ( typeName ) {
183
+ // iOS Types
184
+ case 'CATransform3D ':
185
+ return matricesDiffer ;
186
+ case 'CGPoint ':
187
+ return pointsDiffer ;
188
+ case 'CGSize ':
189
+ return sizesDiffer ;
190
+ case 'UIEdgeInsets ':
191
+ return insetsDiffer ;
192
+ // Android Types
193
+ // (not yet implemented)
194
+ }
195
+ return null ;
196
+ }
197
+
198
+ function getProcessorForType ( typeName : string ) : ?( nextProp : any ) = > any {
199
+ switch ( typeName ) {
200
+ // iOS Types
201
+ case 'CGColor ':
202
+ case 'UIColor ':
203
+ return processColor ;
204
+ case 'CGColorArray ':
205
+ case 'UIColorArray ':
206
+ return processColorArray ;
207
+ case 'CGImage ':
208
+ case 'UIImage ':
209
+ case 'RCTImageSource ':
210
+ return resolveAssetSource ;
211
+ // Android Types
212
+ case 'Color ':
213
+ return processColor ;
214
+ case 'ColorArray ':
215
+ return processColorArray ;
216
+ }
217
+ return null ;
218
+ }
198
219
199
220
function processColorArray ( colors : ?Array < any > ) : ?Array < ?number > {
200
- return colors && colors . map ( processColor ) ;
221
+ return colors == null ? null : colors . map ( processColor ) ;
201
222
}
202
223
203
- const TypeToProcessorMap = {
204
- // iOS Types
205
- CGColor : processColor ,
206
- CGColorArray : processColorArray ,
207
- UIColor : processColor ,
208
- UIColorArray : processColorArray ,
209
- CGImage : resolveAssetSource ,
210
- UIImage : resolveAssetSource ,
211
- RCTImageSource : resolveAssetSource ,
212
- // Android Types
213
- Color : processColor ,
214
- ColorArray : processColorArray ,
215
- } ;
216
-
217
224
module . exports = requireNativeComponent ;
0 commit comments