From 31fb5186d32c1b6f530ad37d75e8a45f1eb9a438 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 7 Sep 2021 11:19:03 +0800 Subject: [PATCH] iOS:use macro to control use of image and cache library --- .../Pod/Classes/Plugin/DoricStoragePlugin.m | 7 +-- doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 29 ++++++------ doric-iOS/Pod/Classes/Util/DoricThirdParty.h | 46 +++++++++++++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 doric-iOS/Pod/Classes/Util/DoricThirdParty.h diff --git a/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m index d9872860..cbfd9565 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m @@ -20,8 +20,9 @@ #import "DoricStoragePlugin.h" #import "DoricExtensions.h" #import "DoricSingleton.h" +#import "DoricThirdParty.h" -#if __has_include() +#if DORIC_USE_PINCACHE #import @@ -64,7 +65,7 @@ - (void)removeAllObjectsWithBlock:(void (^)(void))block { } @end -#elif __has_include() +#elif DORIC_USE_YYCACHE #import @@ -79,7 +80,7 @@ - (instancetype)initWithName:(NSString *)prefix rootPath:(NSString *)path { } @end -#elif __has_include() +#elif DORIC_USE_TMCACHE #import diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 1cd96fd6..f17c1867 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -24,8 +24,9 @@ #import "DoricExtensions.h" #import "DoricUtil.h" #import "DoricSuperNode.h" +#import "DoricThirdParty.h" -#if __has_include() +#if DORIC_USE_YYWEBIMAGE #import #import @@ -47,7 +48,7 @@ - (void)displayLayer:(CALayer *)layer { } @end -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE #import @@ -131,9 +132,9 @@ - (UIImage *)currentPlaceHolderImage { } NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 options:NSDataBase64DecodingIgnoreUnknownCharacters]; -#if __has_include() +#if DORIC_USE_YYWEBIMAGE YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE UIImage *image = [SDAnimatedImage imageWithData:imageData scale:self.imageScale]; if (!image) { image = [UIImage imageWithData:imageData scale:self.imageScale]; @@ -187,9 +188,9 @@ - (UIImage *)currentErrorImage { } NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 options:NSDataBase64DecodingIgnoreUnknownCharacters]; -#if __has_include() +#if DORIC_USE_YYWEBIMAGE YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE UIImage *image = [SDAnimatedImage imageWithData:imageData scale:self.imageScale]; if (!image) { image = [UIImage imageWithData:imageData scale:self.imageScale]; @@ -236,7 +237,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id __weak typeof(self) _self = self; __block BOOL async = NO; view.doricLayout.undefined = YES; -#if __has_include() +#if DORIC_USE_YYWEBIMAGE dispatch_async([_YYWebImageSetter setterQueue], ^{ [view yy_cancelCurrentImageRequest]; @@ -273,7 +274,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id } }]; }); -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE [view sd_setImageWithURL:[NSURL URLWithString:prop] placeholderImage:[self currentPlaceHolderImage] options:0 @@ -336,9 +337,9 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id } NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 options:NSDataBase64DecodingIgnoreUnknownCharacters]; -#if __has_include() +#if DORIC_USE_YYWEBIMAGE YYImage *image = [YYImage imageWithData:imageData scale:self.imageScale]; -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE UIImage *image = [SDAnimatedImage imageWithData:imageData scale:self.imageScale]; if (!image) { image = [UIImage imageWithData:imageData scale:self.imageScale]; @@ -433,9 +434,9 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id } - (UIImage *)imageNamed:(NSString *)name { -#if __has_include() +#if DORIC_USE_YYWEBIMAGE YYImage *image = [YYImage imageNamed:name]; -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE UIImage *image = [SDAnimatedImage imageNamed:name]; if (!image) { image = [UIImage imageNamed:name]; @@ -447,9 +448,9 @@ - (UIImage *)imageNamed:(NSString *)name { } - (UIImage *)imageFromData:(NSData *)imgData { -#if __has_include() +#if DORIC_USE_YYWEBIMAGE YYImage *image = [YYImage imageWithData:imgData scale:self.imageScale]; -#elif __has_include() +#elif DORIC_USE_SDWEBIMAGE UIImage *image = [SDAnimatedImage imageWithData:imgData scale:self.imageScale]; if (!image) { image = [UIImage imageWithData:imgData scale:self.imageScale]; diff --git a/doric-iOS/Pod/Classes/Util/DoricThirdParty.h b/doric-iOS/Pod/Classes/Util/DoricThirdParty.h new file mode 100644 index 00000000..e5cc69e8 --- /dev/null +++ b/doric-iOS/Pod/Classes/Util/DoricThirdParty.h @@ -0,0 +1,46 @@ +/* + * Copyright [2021] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// +// DoricThirdParty.h +// Doric +// +// Created by pengfei.zhou on 2021/9/6. +// + + +#if __has_include() +#ifndef DORIC_USE_SDWEBIMAGE +#define DORIC_USE_SDWEBIMAGE 1 +#endif +#elif __has_include() +#ifndef DORIC_USE_YYWEBIMAGE +#define DORIC_USE_YYWEBIMAGE 1 +#endif +#endif + +#if __has_include() +#ifndef DORIC_USE_PINCACHE +#define DORIC_USE_PINCACHE 1 +#endif +#elif __has_include() +#ifndef DORIC_USE_YYCACHE +#define DORIC_USE_YYCACHE 1 +#endif +#elif __has_include() +#ifndef DORIC_USE_TMCACHE +#define DORIC_USE_TMCACHE 1 +#endif +#endif \ No newline at end of file