From 1fd631f0049e0876b775ed84f186278fc8f7492f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 17 Jun 2020 10:28:00 -0400 Subject: [PATCH 1/3] image registry --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h | 13 +++++- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 43 +++++++++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 9d97932..0289b31 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -20,6 +20,9 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO @property (nullable, strong, nonatomic, readonly) NSDictionary *staticStringCache; @property (nonnull, strong, nonatomic) NSOperationQueue *completionQueue; +/// Contains all bundles to search for images. +@property (nonnull, strong, nonatomic) NSMutableArray* imageBundles; + // Returns the shared instance of this singleton + (nullable instancetype)sharedCache; @@ -108,8 +111,14 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO #pragma mark Image Functions -// Subclass to return the bundle to use -- (nonnull NSBundle *)bundleToUseForImages; +/// Register a bundle as one to search for images in. +- (void)registerBundleForImages:(nonnull NSBundle *)bundle; + +/// Tries to create an image from a registered bundle. +- (nullable UIImage *)getImageFromRegisteredBundles:(nonnull NSString *)imageName; + +/// Tries to get image data from a registered bundle. Can specify the type of extension if desired. +- (nullable NSData *)getImageDataFromRegisteredBundles:(nonnull NSString *)imageName type:(nullable NSString *)type; /// Returns if the imageName pointing to a local image. Currently just checks if it begins with http. + (BOOL)isHostedImage:(nullable NSString *)imageName; diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 0d552c3..3ea004d 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -57,6 +57,8 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; self.moduleQueue.maxConcurrentOperationCount = 1; self.imageCacheQueue = dispatch_queue_create("imgCache", DISPATCH_QUEUE_CONCURRENT); + + self.imageBundles = [NSMutableArray array]; } return self; } @@ -374,8 +376,30 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; #pragma mark - Image Functions -- (nonnull NSBundle *)bundleToUseForImages { - return [MVMCoreGetterUtility bundleForMVMCore]; +- (void)registerBundleForImages:(nonnull NSBundle *)bundle { + [self.imageBundles addObject:bundle]; +} + +- (nullable UIImage *)getImageFromRegisteredBundles:(nonnull NSString *)imageName { + UIImage *image = nil; + for (NSBundle *bundle in self.imageBundles) { + image = [UIImage imageNamed:imageName inBundle:bundle withConfiguration:nil]; + if (image) { + break; + } + } + return image; +} + +- (nullable NSData *)getImageDataFromRegisteredBundles:(nonnull NSString *)imageName type:(nullable NSString *)type { + NSData *imageData = nil; + for (NSBundle *bundle in self.imageBundles) { + imageData = [NSData dataWithContentsOfFile:[bundle pathForResource:imageName ofType:type]]; + if (imageData) { + break; + } + } + return imageData; } - (NSMutableDictionary *)imgCache { @@ -487,8 +511,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; // Try Local. Check in memory cache imageData = [self getCachedDataWithName:pathOrName]; if (!imageData) { - NSBundle *imageBundle = localBundle ? : [self bundleToUseForImages]; - imageData = [NSData dataWithContentsOfFile:[imageBundle pathForResource:pathOrName ofType:@"gif"]]; + if (localBundle) { + imageData = [NSData dataWithContentsOfFile:[localBundle pathForResource:pathOrName ofType:@"gif"]]; + } else { + imageData = [self getImageDataFromRegisteredBundles:pathOrName type:@"gif"]; + } if (imageData) { [self addDataToCache:imageData withName:pathOrName]; } @@ -525,7 +552,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; // Try native image. Check in memory cache image = [self getCachedImageWithName:pathOrName]; if (!image) { - image = [UIImage imageNamed:pathOrName inBundle:localBundle ?: [self bundleToUseForImages] compatibleWithTraitCollection:nil]; + if (localBundle) { + image = [UIImage imageNamed:pathOrName inBundle:localBundle compatibleWithTraitCollection:nil]; + } else { + image = [self getImageFromRegisteredBundles:pathOrName]; + } if (image) { [self addImageToCache:image withName:pathOrName]; } @@ -585,7 +616,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; image = [self getCachedImageWithName:fallbackImageName]; if (!image) { - image = [UIImage imageNamed:fallbackImageName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil]; + image = [self getImageFromRegisteredBundles:fallbackImageName]; if (image) { // Cache the fallback image if not already cached. From 921fbe02fad35e357037fb721082f5feb02b72d0 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 17 Jun 2020 11:18:11 -0400 Subject: [PATCH 2/3] update --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 3ea004d..7d5efbb 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -383,7 +383,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; - (nullable UIImage *)getImageFromRegisteredBundles:(nonnull NSString *)imageName { UIImage *image = nil; for (NSBundle *bundle in self.imageBundles) { - image = [UIImage imageNamed:imageName inBundle:bundle withConfiguration:nil]; + image = [UIImage imageNamed:imageName inBundle:bundle compatibleWithTraitCollection:nil]; if (image) { break; } From 72a82d4d3782115d60d89db25f67c2b1aa3fa4a0 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Thu, 18 Jun 2020 00:05:43 -0400 Subject: [PATCH 3/3] oepn --- MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift index feb7b4c..7478e3a 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionOpenPageModel.swift @@ -8,7 +8,7 @@ import Foundation -@objcMembers public class ActionOpenPageModel: ActionModelProtocol { +@objcMembers open class ActionOpenPageModel: ActionModelProtocol { public static var identifier: String = "openPage" public var actionType: String = ActionOpenPageModel.identifier public var pageType: String