Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit a4ef3cc

Browse files
authored
NativeDrawable: save tint info on image - fixes #460 (#461)
The view is the singleton so once tint was set the hasTint was always true.
1 parent 6113c34 commit a4ef3cc

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

Cliqz/React Components/Modules/NativeDrawable.m

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,51 @@
1010
#import <UIKit/UIKit.h>
1111
#import <React/RCTViewManager.h>
1212

13-
@interface NativeDrawable : RCTViewManager
13+
@interface NativeDrawableImageView : UIImageView
1414
@property BOOL hasTint;
1515
@end
1616

17+
@implementation NativeDrawableImageView
18+
@end
19+
20+
@interface NativeDrawable : RCTViewManager
21+
@end
22+
1723
@implementation NativeDrawable
1824

1925
RCT_EXPORT_MODULE()
2026

2127
- (UIImageView *)view
2228
{
23-
UIImageView* imageView = [[UIImageView alloc] init];
29+
NativeDrawableImageView* imageView = [[NativeDrawableImageView alloc] init];
2430
[imageView setContentMode:UIViewContentModeScaleAspectFit];
2531
return imageView;
2632
}
2733

2834
RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIImageView) {
2935
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) {
3238
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 {
3742
NSLog(@"color %@ is not valid", json);
3843
}
3944
}
4045

4146
RCT_CUSTOM_VIEW_PROPERTY(source, NSString, UIImageView)
4247
{
4348
NSString *imageName = (NSString*)json;
44-
if (imageName != nil) {
49+
if (imageName) {
4550
UIImage* image = [UIImage imageNamed:imageName];
46-
if (self.hasTint) {
51+
if (((NativeDrawableImageView*) view).hasTint) {
4752
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
4853
}
4954

50-
if (image != nil) {
55+
if (image) {
5156
[view setImage:image];
52-
}
53-
else {
57+
} else {
5458
NSLog(@"image %@ is missing", imageName);
5559
}
5660
}

0 commit comments

Comments
 (0)