iOS:Remove dependency of YYImage

This commit is contained in:
pengfeizhou 2021-01-28 19:14:04 +08:00 committed by osborn
parent bf96e5089a
commit a68155a0ec
3 changed files with 43 additions and 8 deletions

View File

@ -21,13 +21,7 @@ Doric iOS SDK for cross platform develpment
} }
s.public_header_files = 'doric-iOS/Pod/Classes/**/*.h' s.public_header_files = 'doric-iOS/Pod/Classes/**/*.h'
s.dependency 'YYWebImage'
#s.dependency 'YYImage/WebP'
s.dependency 'YYCache' s.dependency 'YYCache'
s.dependency 'YogaKit/Core' s.dependency 'YogaKit/Core'
s.dependency 'Yoga' s.dependency 'Yoga'
# https://github.com/CocoaPods/CocoaPods/issues/10065
#s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
#s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
end end

View File

@ -7,6 +7,11 @@ target 'Example' do
pod 'DoricCore', :path => '../../' pod 'DoricCore', :path => '../../'
pod 'DoricDevkit', :path => '../../' pod 'DoricDevkit', :path => '../../'
#pod 'YYWebImage'
#pod 'YYImage/WebP'
target 'ExampleTests' do target 'ExampleTests' do
inherit! :search_paths inherit! :search_paths
# Pods for testing # Pods for testing

View File

@ -21,10 +21,12 @@
// //
#import "DoricImageNode.h" #import "DoricImageNode.h"
#import "YYWebImage.h"
#import "DoricExtensions.h" #import "DoricExtensions.h"
#import "DoricUtil.h" #import "DoricUtil.h"
#import "DoricSuperNode.h"
#if __has_include(<YYWebImage/YYWebImage.h>)
#import <YYWebImage/YYWebImage.h>
@interface DoricImageView : YYAnimatedImageView @interface DoricImageView : YYAnimatedImageView
@end @end
@ -42,6 +44,16 @@ - (void)displayLayer:(CALayer *)layer {
} }
} }
@end @end
#else
@interface DoricImageView : UIImageView
@end
@implementation DoricImageView
@end
#endif
@interface DoricImageNode () @interface DoricImageNode ()
@property(nonatomic, copy) NSString *loadCallbackId; @property(nonatomic, copy) NSString *loadCallbackId;
@ -104,7 +116,11 @@ - (UIImage *)currentPlaceHolderImage {
} }
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64
options:NSDataBase64DecodingIgnoreUnknownCharacters]; options:NSDataBase64DecodingIgnoreUnknownCharacters];
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale];
#else
UIImage *image = [UIImage imageWithData:imageData scale:self.imageScale];
#endif
return image; return image;
} }
@ -137,7 +153,11 @@ - (UIImage *)currentErrorImage {
} }
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64
options:NSDataBase64DecodingIgnoreUnknownCharacters]; options:NSDataBase64DecodingIgnoreUnknownCharacters];
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale];
#else
UIImage *image = [UIImage imageWithData:imageData scale:self.imageScale];
#endif
return image; return image;
} }
@ -163,6 +183,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
__weak typeof(self) _self = self; __weak typeof(self) _self = self;
__block BOOL async = NO; __block BOOL async = NO;
view.doricLayout.undefined = YES; view.doricLayout.undefined = YES;
#if __has_include(<YYWebImage/YYWebImage.h>)
[view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:[self currentPlaceHolderImage] options:0 completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) { [view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:[self currentPlaceHolderImage] 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) { if (self.placeHolderColor || self.errorColor) {
@ -195,6 +216,9 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} }
} }
}]; }];
#else
DoricLog(@"Do not support load image url");
#endif
async = YES; async = YES;
} else if ([@"scaleType" isEqualToString:name]) { } else if ([@"scaleType" isEqualToString:name]) {
switch ([prop integerValue]) { switch ([prop integerValue]) {
@ -221,7 +245,11 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} }
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64
options:NSDataBase64DecodingIgnoreUnknownCharacters]; options:NSDataBase64DecodingIgnoreUnknownCharacters];
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale];
#else
UIImage *image = [UIImage imageWithData:imageData scale:self.imageScale];
#endif
view.image = image; view.image = image;
} else if ([@"isBlur" isEqualToString:name]) { } else if ([@"isBlur" isEqualToString:name]) {
NSInteger value = [prop intValue]; NSInteger value = [prop intValue];
@ -254,7 +282,11 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} }
} else if ([@"imageRes" isEqualToString:name]) { } else if ([@"imageRes" isEqualToString:name]) {
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageNamed:prop]; YYImage *image = [YYImage imageNamed:prop];
#else
UIImage *image = [UIImage imageNamed:prop];
#endif
if (image) { if (image) {
view.image = image; view.image = image;
} else { } else {
@ -275,7 +307,11 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *fullPath = [path stringByAppendingPathComponent:prop]; NSString *fullPath = [path stringByAppendingPathComponent:prop];
NSData *imgData = [[NSData alloc] initWithContentsOfFile:fullPath]; NSData *imgData = [[NSData alloc] initWithContentsOfFile:fullPath];
#if __has_include(<YYWebImage/YYWebImage.h>)
YYImage *image = [YYImage imageWithData:imgData scale:self.imageScale]; YYImage *image = [YYImage imageWithData:imgData scale:self.imageScale];
#else
UIImage *image = [UIImage imageWithData:imgData scale:self.imageScale];
#endif
view.image = image; view.image = image;
if (self.loadCallbackId.length > 0) { if (self.loadCallbackId.length > 0) {
if (image) { if (image) {