Android and iOS add handling imageScale

This commit is contained in:
pengfei.zhou
2020-04-23 16:49:19 +08:00
committed by osborn
parent 8b1f5f6a43
commit 82fdd5e46c
8 changed files with 105 additions and 25 deletions

View File

@@ -41,11 +41,13 @@ @interface DoricImageNode ()
@property(nonatomic, strong) NSString *errorImage;
@property(nonatomic, strong) UIVisualEffectView *blurEffectView;
@property(nonatomic, strong) NSDictionary *stretchInsetDic;
@property(nonatomic, assign) CGFloat imageScale;
@end
@implementation DoricImageNode
- (UIImageView *)build {
self.imageScale = UIScreen.mainScreen.scale;
return [[DoricImageView new] also:^(UIImageView *it) {
it.clipsToBounds = YES;
it.contentMode = UIViewContentModeScaleAspectFill;
@@ -65,6 +67,9 @@ - (void)blend:(NSDictionary *)props {
[props[@"errorImage"] also:^(id it) {
self.errorImage = it;
}];
[props[@"imageScale"] also:^(NSNumber *it) {
self.imageScale = it.floatValue;
}];
[super blend:props];
}
@@ -129,6 +134,10 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
[self callJSResponse:self.loadCallbackId, nil];
}
} else {
if (image.scale != self.imageScale) {
image = [YYImage imageWithCGImage:image.CGImage scale:self.imageScale orientation:image.imageOrientation];
self.view.image = image;
}
if (self.loadCallbackId.length > 0) {
[self callJSResponse:self.loadCallbackId,
@{@"width": @(image.size.width), @"height": @(image.size.height)},
@@ -169,7 +178,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
}
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64
options:NSDataBase64DecodingIgnoreUnknownCharacters];
YYImage *image = [YYImage imageWithData:imageData scale:UIScreen.mainScreen.scale];
YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale];
view.image = image;
} else if ([@"isBlur" isEqualToString:name]) {
NSInteger value = [prop intValue];
@@ -218,7 +227,8 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} else if ([@"imagePath" isEqualToString:name]) {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *fullPath = [path stringByAppendingPathComponent:prop];
YYImage *image = [YYImage imageWithContentsOfFile:fullPath];
NSData *imgData = [[NSData alloc] initWithContentsOfFile:fullPath];
YYImage *image = [YYImage imageWithData:imgData scale:self.imageScale];
view.image = image;
if (self.loadCallbackId.length > 0) {
if (image) {
@@ -231,6 +241,8 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
}
} else if ([@"stretchInset" isEqualToString:name]) {
self.stretchInsetDic = (NSDictionary *)prop;
} else if ([@"imageScale" isEqualToString:name]) {
//Do not need set
} else {
[super blendView:view forPropName:name propValue:prop];
}
@@ -242,7 +254,8 @@ - (void)afterBlended:(NSDictionary *)props {
CGFloat top = [self.stretchInsetDic[@"top"] floatValue];
CGFloat right = [self.stretchInsetDic[@"right"] floatValue];
CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue];
UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top * self.view.image.size.height, left * self.view.image.size.width, bottom * self.view.image.size.height, right * self.view.image.size.width) resizingMode:UIImageResizingModeStretch];
CGFloat scale = self.imageScale;
UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top/scale, left/scale, bottom/scale, right/scale) resizingMode:UIImageResizingModeStretch];
self.view.image = result;
}
}