Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

NativeDrawable: save tint info on image - fixes #460 (#461)

The view is the singleton so once tint was set the hasTint was always true.
  • Loading branch information
chrmod committed Aug 26, 2019
1 parent 6113c34 commit a4ef3cc1e6f9e78d89254f791fad6fdae43df989
Showing with 17 additions and 13 deletions.
  1. +17 −13 Cliqz/React Components/Modules/NativeDrawable.m
@@ -10,47 +10,51 @@
#import <UIKit/UIKit.h>
#import <React/RCTViewManager.h>

@interface NativeDrawable : RCTViewManager
@interface NativeDrawableImageView : UIImageView
@property BOOL hasTint;
@end

@implementation NativeDrawableImageView
@end

@interface NativeDrawable : RCTViewManager
@end

@implementation NativeDrawable

RCT_EXPORT_MODULE()

- (UIImageView *)view
{
UIImageView* imageView = [[UIImageView alloc] init];
NativeDrawableImageView* imageView = [[NativeDrawableImageView alloc] init];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
return imageView;
}

RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIImageView) {
NSString *color_str = (NSString*)json;
UIColor* color = [NativeDrawable colorFromHexString:color_str];
if (color != nil) {
UIColor* uicolor = [NativeDrawable colorFromHexString:color_str];
if (uicolor) {
view.image = [view.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[view setTintColor: color];
[self setHasTint:YES];
}
else {
[view setTintColor: uicolor];
[(NativeDrawableImageView*)view setHasTint:YES];
} else {
NSLog(@"color %@ is not valid", json);
}
}

RCT_CUSTOM_VIEW_PROPERTY(source, NSString, UIImageView)
{
NSString *imageName = (NSString*)json;
if (imageName != nil) {
if (imageName) {
UIImage* image = [UIImage imageNamed:imageName];
if (self.hasTint) {
if (((NativeDrawableImageView*) view).hasTint) {
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}

if (image != nil) {
if (image) {
[view setImage:image];
}
else {
} else {
NSLog(@"image %@ is missing", imageName);
}
}

0 comments on commit a4ef3cc

Please sign in to comment.