From 1830acf977d7ba9c777194de50098490d707502d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Mon, 11 May 2020 11:29:04 +0800 Subject: [PATCH] iOS: implements base64 for placeholder & error in image --- doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 56a95eb6..59eb2496 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -37,8 +37,10 @@ @interface DoricImageNode () @property(nonatomic, assign) UIViewContentMode contentMode; @property(nonatomic, strong) NSNumber *placeHolderColor; @property(nonatomic, strong) NSString *placeHolderImage; +@property(nonatomic, strong) NSString *placeHolderImageBase64; @property(nonatomic, strong) NSNumber *errorColor; @property(nonatomic, strong) NSString *errorImage; +@property(nonatomic, strong) NSString *errorImageBase64; @property(nonatomic, strong) UIVisualEffectView *blurEffectView; @property(nonatomic, strong) NSDictionary *stretchInsetDic; @property(nonatomic, assign) CGFloat imageScale; @@ -61,12 +63,18 @@ - (void)blend:(NSDictionary *)props { [props[@"placeHolderImage"] also:^(id it) { self.placeHolderImage = it; }]; + [props[@"placeHolderImageBase64"] also:^(id it) { + self.placeHolderImageBase64 = it; + }]; [props[@"errorColor"] also:^(id it) { self.errorColor = it; }]; [props[@"errorImage"] also:^(id it) { self.errorImage = it; }]; + [props[@"errorImageBase64"] also:^(id it) { + self.errorImageBase64 = it; + }]; [props[@"imageScale"] also:^(NSNumber *it) { self.imageScale = it.floatValue; }]; @@ -77,6 +85,18 @@ - (UIImage *)currentPlaceHolderImage { if (self.placeHolderImage) { return [UIImage imageNamed:self.placeHolderImage]; } + + if (self.placeHolderImageBase64) { + NSString *base64 = self.placeHolderImageBase64; + if (YES == [base64 hasPrefix:@"data:image"]) { + base64 = [base64 componentsSeparatedByString:@","].lastObject; + } + NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 + options:NSDataBase64DecodingIgnoreUnknownCharacters]; + YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; + return image; + } + if (self.placeHolderColor) { UIColor *color = DoricColor(self.placeHolderColor); CGRect rect = CGRectMake(0, 0, 1, 1); @@ -98,6 +118,18 @@ - (UIImage *)currentErrorImage { if (self.errorImage) { return [UIImage imageNamed:self.errorImage]; } + + if (self.errorImageBase64) { + NSString *base64 = self.errorImageBase64; + if (YES == [base64 hasPrefix:@"data:image"]) { + base64 = [base64 componentsSeparatedByString:@","].lastObject; + } + NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 + options:NSDataBase64DecodingIgnoreUnknownCharacters]; + YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; + return image; + } + if (self.errorColor) { UIColor *color = DoricColor(self.errorColor); CGRect rect = CGRectMake(0, 0, 1, 1);