|
10 | 10 | #import <UIKit/UIKit.h> |
11 | 11 | #import <React/RCTViewManager.h> |
12 | 12 |
|
13 | | -@interface NativeDrawable : RCTViewManager |
| 13 | +@interface NativeDrawableImageView : UIImageView |
14 | 14 | @property BOOL hasTint; |
15 | 15 | @end |
16 | 16 |
|
| 17 | +@implementation NativeDrawableImageView |
| 18 | +@end |
| 19 | + |
| 20 | +@interface NativeDrawable : RCTViewManager |
| 21 | +@end |
| 22 | + |
17 | 23 | @implementation NativeDrawable |
18 | 24 |
|
19 | 25 | RCT_EXPORT_MODULE() |
20 | 26 |
|
21 | 27 | - (UIImageView *)view |
22 | 28 | { |
23 | | - UIImageView* imageView = [[UIImageView alloc] init]; |
| 29 | + NativeDrawableImageView* imageView = [[NativeDrawableImageView alloc] init]; |
24 | 30 | [imageView setContentMode:UIViewContentModeScaleAspectFit]; |
25 | 31 | return imageView; |
26 | 32 | } |
27 | 33 |
|
28 | 34 | RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIImageView) { |
29 | 35 | NSString *color_str = (NSString*)json; |
30 | | - UIColor* color = [NativeDrawable colorFromHexString:color_str]; |
31 | | - if (color != nil) { |
| 36 | + UIColor* uicolor = [NativeDrawable colorFromHexString:color_str]; |
| 37 | + if (uicolor) { |
32 | 38 | view.image = [view.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
33 | | - [view setTintColor: color]; |
34 | | - [self setHasTint:YES]; |
35 | | - } |
36 | | - else { |
| 39 | + [view setTintColor: uicolor]; |
| 40 | + [(NativeDrawableImageView*)view setHasTint:YES]; |
| 41 | + } else { |
37 | 42 | NSLog(@"color %@ is not valid", json); |
38 | 43 | } |
39 | 44 | } |
40 | 45 |
|
41 | 46 | RCT_CUSTOM_VIEW_PROPERTY(source, NSString, UIImageView) |
42 | 47 | { |
43 | 48 | NSString *imageName = (NSString*)json; |
44 | | - if (imageName != nil) { |
| 49 | + if (imageName) { |
45 | 50 | UIImage* image = [UIImage imageNamed:imageName]; |
46 | | - if (self.hasTint) { |
| 51 | + if (((NativeDrawableImageView*) view).hasTint) { |
47 | 52 | image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
48 | 53 | } |
49 | 54 |
|
50 | | - if (image != nil) { |
| 55 | + if (image) { |
51 | 56 | [view setImage:image]; |
52 | | - } |
53 | | - else { |
| 57 | + } else { |
54 | 58 | NSLog(@"image %@ is missing", imageName); |
55 | 59 | } |
56 | 60 | } |
|
0 commit comments