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 <UIKit/UIKit.h>
#import <React/RCTViewManager.h> #import <React/RCTViewManager.h>


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


@implementation NativeDrawableImageView
@end

@interface NativeDrawable : RCTViewManager
@end

@implementation NativeDrawable @implementation NativeDrawable


RCT_EXPORT_MODULE() RCT_EXPORT_MODULE()


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


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


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


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

0 comments on commit a4ef3cc

Please sign in to comment.