Skip to content

Commit

Permalink
fix(ios): properly set tint-color on image-view (#11070)
Browse files Browse the repository at this point in the history
* fix(ios): properly set tint-color on image-view

* fix(ios): restored tintColor property
  • Loading branch information
hansemannn authored and ssekhri committed Sep 25, 2019
1 parent 4d96ddc commit 7d96b81
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions iphone/Classes/TiUIImageView.m
Expand Up @@ -309,9 +309,11 @@ - (void)setURLImageOnUIThread:(UIImage *)image
// but after we've detached our view. In which case, we need to just ignore this
return;
}
UIImageView *iv = [self imageView];
iv.image = image;

[self setTintedImage:image];

if (placeholderLoading) {
UIImageView *iv = [self imageView];
iv.alpha = 0;

[(TiViewProxy *)[self proxy] contentsWillChange];
Expand Down Expand Up @@ -450,7 +452,7 @@ - (void)loadDefaultImage:(CGSize)imageSize
// TODO: Use the full image size here? Auto width/height is going to be changed once the image is loaded.
autoWidth = imageToUse.size.width;
autoHeight = imageToUse.size.height;
[self imageView].image = imageToUse;
[self setTintedImage:imageToUse];
}
}

Expand Down Expand Up @@ -507,7 +509,7 @@ - (void)loadUrl:(NSURL *)img
UIImage *imageToUse = [self rotatedImage:image];
autoWidth = imageToUse.size.width;
autoHeight = imageToUse.size.height;
[self imageView].image = imageToUse;
[self setTintedImage:imageToUse];
[self fireLoadEventWithState:@"image"];
} else {
[self loadDefaultImage:imageSize];
Expand All @@ -533,12 +535,24 @@ - (void)loadUrl:(NSURL *)img
autoWidth = autoWidth / 2;
autoHeight = autoHeight / 2;
}
[self imageView].image = imageToUse;
[self setTintedImage:imageToUse];
[self fireLoadEventWithState:@"image"];
}
}
}

- (void)setTintedImage:(UIImage *)image
{
id tintColor = [self.proxy valueForUndefinedKey:@"tintColor"];

if (tintColor != nil) {
[[self imageView] setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
[[self imageView] setTintColor:[TiUtils colorValue:tintColor].color];
} else {
[[self imageView] setImage:image];
}
}

- (UIView *)container
{
if (container == nil) {
Expand Down Expand Up @@ -656,6 +670,15 @@ - (void)setHeight_:(id)height_
[self updateContentMode];
}

- (void)setTintColor_:(id)value
{
ENSURE_TYPE_OR_NIL(value, NSObject);
UIImageRenderingMode renderingMode = value ? UIImageRenderingModeAlwaysTemplate : UIImageRenderingModeAlwaysOriginal;

[imageView setImage:[[imageView image] imageWithRenderingMode:renderingMode]];
[imageView setTintColor:value ? [[TiUtils colorValue:value] color] : nil];
}

- (void)setImage_:(id)arg
{
id currentImage = [self.proxy valueForUndefinedKey:@"image"];
Expand Down Expand Up @@ -683,23 +706,15 @@ - (void)setImage_:(id)arg
return;
}

[imageview setImage:image];
[self setTintedImage:image];

[(TiViewProxy *)[self proxy] contentsWillChange]; // Have to resize the proxy view to fit new subview size, if necessary

if (currentImage != image) {
[self fireLoadEventWithState:@"image"];
}
}

- (void)setTintColor_:(id)value
{
ENSURE_TYPE_OR_NIL(value, NSObject);
UIImageRenderingMode renderingMode = value ? UIImageRenderingModeAlwaysTemplate : UIImageRenderingModeAlwaysOriginal;

[imageView setImage:[[imageView image] imageWithRenderingMode:renderingMode]];
[imageView setTintColor:value ? [[TiUtils colorValue:value] color] : nil];
}

- (void)setImages_:(id)args
{
BOOL running = (timer != nil);
Expand Down

0 comments on commit 7d96b81

Please sign in to comment.