fix: image's contentMode bug when displayed again after an image loading error.
This commit is contained in:
parent
371f18c6f5
commit
e7332f1db1
@ -75,7 +75,6 @@ @implementation DoricImageView
|
|||||||
@interface DoricImageNode ()
|
@interface DoricImageNode ()
|
||||||
@property(nonatomic, copy) NSString *loadCallbackId;
|
@property(nonatomic, copy) NSString *loadCallbackId;
|
||||||
@property(nonatomic, copy) NSString *animationEndCallbackId;
|
@property(nonatomic, copy) NSString *animationEndCallbackId;
|
||||||
@property(nonatomic, assign) UIViewContentMode contentMode;
|
|
||||||
@property(nonatomic, strong) NSNumber *placeHolderColor;
|
@property(nonatomic, strong) NSNumber *placeHolderColor;
|
||||||
@property(nonatomic, strong) NSString *placeHolderImage;
|
@property(nonatomic, strong) NSString *placeHolderImage;
|
||||||
@property(nonatomic, strong) NSString *placeHolderImageBase64;
|
@property(nonatomic, strong) NSString *placeHolderImageBase64;
|
||||||
@ -163,7 +162,6 @@ - (UIImage *)currentPlaceHolderImage {
|
|||||||
UIColor *color = DoricColor(self.placeHolderColor);
|
UIColor *color = DoricColor(self.placeHolderColor);
|
||||||
CGRect rect = CGRectMake(0, 0, 1, 1);
|
CGRect rect = CGRectMake(0, 0, 1, 1);
|
||||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||||
self.scaleType = 0;
|
|
||||||
if (@available(iOS 10.0, *)) {
|
if (@available(iOS 10.0, *)) {
|
||||||
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
||||||
format.scale = [UIScreen mainScreen].scale;
|
format.scale = [UIScreen mainScreen].scale;
|
||||||
@ -219,7 +217,6 @@ - (UIImage *)currentErrorImage {
|
|||||||
UIColor *color = DoricColor(self.errorColor);
|
UIColor *color = DoricColor(self.errorColor);
|
||||||
CGRect rect = CGRectMake(0, 0, 1, 1);
|
CGRect rect = CGRectMake(0, 0, 1, 1);
|
||||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||||
self.scaleType = 0;
|
|
||||||
if (@available(iOS 10.0, *)) {
|
if (@available(iOS 10.0, *)) {
|
||||||
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
||||||
format.scale = [UIScreen mainScreen].scale;
|
format.scale = [UIScreen mainScreen].scale;
|
||||||
@ -248,7 +245,6 @@ - (UIImage *)currentErrorImage {
|
|||||||
UIColor *color = UIColor.clearColor;
|
UIColor *color = UIColor.clearColor;
|
||||||
CGRect rect = CGRectMake(0, 0, 1, 1);
|
CGRect rect = CGRectMake(0, 0, 1, 1);
|
||||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||||
self.scaleType = 0;
|
|
||||||
if (@available(iOS 10.0, *)) {
|
if (@available(iOS 10.0, *)) {
|
||||||
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
|
||||||
format.scale = [UIScreen mainScreen].scale;
|
format.scale = [UIScreen mainScreen].scale;
|
||||||
@ -336,9 +332,6 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
|
|
||||||
[view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:image options:0 completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
|
[view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:image options:0 completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
if (self.placeHolderColor || self.errorColor) {
|
|
||||||
self.view.contentMode = self.contentMode;
|
|
||||||
}
|
|
||||||
self.view.doricLayout.undefined = NO;
|
self.view.doricLayout.undefined = NO;
|
||||||
if (error) {
|
if (error) {
|
||||||
[[self currentErrorImage] also:^(UIImage *it) {
|
[[self currentErrorImage] also:^(UIImage *it) {
|
||||||
@ -348,6 +341,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
[self callJSResponse:self.loadCallbackId, nil];
|
[self callJSResponse:self.loadCallbackId, nil];
|
||||||
}
|
}
|
||||||
} else if (image && stage == YYWebImageStageFinished) {
|
} else if (image && stage == YYWebImageStageFinished) {
|
||||||
|
[self updateScaleType];
|
||||||
if (image.scale != self.imageScale) {
|
if (image.scale != self.imageScale) {
|
||||||
if ([image isKindOfClass:YYImage.class] && ((YYImage *) image).animatedImageData != nil) {
|
if ([image isKindOfClass:YYImage.class] && ((YYImage *) image).animatedImageData != nil) {
|
||||||
image = [YYImage imageWithData:((YYImage *) image).animatedImageData scale:self.imageScale];
|
image = [YYImage imageWithData:((YYImage *) image).animatedImageData scale:self.imageScale];
|
||||||
@ -383,9 +377,6 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
progress:nil
|
progress:nil
|
||||||
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
if (self.placeHolderColor || self.errorColor) {
|
|
||||||
self.view.contentMode = self.contentMode;
|
|
||||||
}
|
|
||||||
self.view.doricLayout.undefined = NO;
|
self.view.doricLayout.undefined = NO;
|
||||||
if (error) {
|
if (error) {
|
||||||
[[self currentErrorImage] also:^(UIImage *it) {
|
[[self currentErrorImage] also:^(UIImage *it) {
|
||||||
@ -395,6 +386,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
[self callJSResponse:self.loadCallbackId, nil];
|
[self callJSResponse:self.loadCallbackId, nil];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
[self updateScaleType];
|
||||||
if (self.loadCallbackId.length > 0) {
|
if (self.loadCallbackId.length > 0) {
|
||||||
[self callJSResponse:self.loadCallbackId,
|
[self callJSResponse:self.loadCallbackId,
|
||||||
@{
|
@{
|
||||||
@ -419,25 +411,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
async = YES;
|
async = YES;
|
||||||
} else if ([@"scaleType" isEqualToString:name]) {
|
} else if ([@"scaleType" isEqualToString:name]) {
|
||||||
self.scaleType = [prop integerValue];
|
self.scaleType = [prop integerValue];
|
||||||
switch (self.scaleType) {
|
[self updateScaleType];
|
||||||
case 1: {
|
|
||||||
self.view.contentMode = UIViewContentModeScaleAspectFit;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2: {
|
|
||||||
self.view.contentMode = UIViewContentModeScaleAspectFill;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 3: { // image tile
|
|
||||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
self.view.contentMode = UIViewContentModeScaleToFill;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.contentMode = self.view.contentMode;
|
|
||||||
} else if ([@"loadCallback" isEqualToString:name]) {
|
} else if ([@"loadCallback" isEqualToString:name]) {
|
||||||
// Do not need set
|
// Do not need set
|
||||||
} else if ([@"imageBase64" isEqualToString:name]) {
|
} else if ([@"imageBase64" isEqualToString:name]) {
|
||||||
@ -729,6 +703,28 @@ - (void)resizingImageIfNeeded {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateScaleType {
|
||||||
|
if (!self.view) return;
|
||||||
|
switch (self.scaleType) {
|
||||||
|
case 1: {
|
||||||
|
self.view.contentMode = UIViewContentModeScaleAspectFit;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
self.view.contentMode = UIViewContentModeScaleAspectFill;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: { // image tile
|
||||||
|
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
self.view.contentMode = UIViewContentModeScaleToFill;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (NSNumber *)isAnimating {
|
- (NSNumber *)isAnimating {
|
||||||
if (self.view.animating) {
|
if (self.view.animating) {
|
||||||
return @(YES);
|
return @(YES);
|
||||||
|
Reference in New Issue
Block a user