From 7978900a4fd84c9105406a091bf08e28f04c759a Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 18 Nov 2021 19:08:33 +0800 Subject: [PATCH] feat:iOS load Resource use NSDictionary --- .../Classes/Resource/DoricResourceManager.h | 4 +--- .../Classes/Resource/DoricResourceManager.m | 21 ++++++++++--------- doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 7 +------ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/doric-iOS/Pod/Classes/Resource/DoricResourceManager.h b/doric-iOS/Pod/Classes/Resource/DoricResourceManager.h index c1111dc8..cb075f9b 100644 --- a/doric-iOS/Pod/Classes/Resource/DoricResourceManager.h +++ b/doric-iOS/Pod/Classes/Resource/DoricResourceManager.h @@ -25,8 +25,6 @@ - (void)unRegisterLoader:(id )loader; -- (__kindof DoricResource *)load:(NSString *)resId - withIdentifier:(NSString *)identifier - withResourceType:(NSString *)resourceType +- (__kindof DoricResource *)load:(NSDictionary *)resource withContext:(DoricContext *)context; @end diff --git a/doric-iOS/Pod/Classes/Resource/DoricResourceManager.m b/doric-iOS/Pod/Classes/Resource/DoricResourceManager.m index caca861f..54be1830 100644 --- a/doric-iOS/Pod/Classes/Resource/DoricResourceManager.m +++ b/doric-iOS/Pod/Classes/Resource/DoricResourceManager.m @@ -49,20 +49,21 @@ - (void)unRegisterLoader:(id )loader { }); } -- (__kindof DoricResource *)load:(NSString *)resId - withIdentifier:(NSString *)identifier - withResourceType:(NSString *)resourceType +- (__kindof DoricResource *)load:(NSDictionary *)resource withContext:(DoricContext *)context { - __block __kindof DoricResource *resource; + NSString *type = resource[@"type"]; + NSString *identifier = resource[@"identifier"]; + NSString *resId = resource[@"resId"]; + __block __kindof DoricResource *doricResource; dispatch_sync(self.mapQueue, ^() { - resource = [self.cachedResources objectForKey:resId]; - if (!resource) { - id loader = self.loaders[resourceType]; - resource = [loader load:identifier withContext:context]; - [self.cachedResources setObject:resource forKey:resId]; + doricResource = [self.cachedResources objectForKey:resId]; + if (!doricResource) { + id loader = self.loaders[type]; + doricResource = [loader load:identifier withContext:context]; + [self.cachedResources setObject:doricResource forKey:resId]; } }); - return resource; + return doricResource; } @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 62569807..e3306974 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -236,13 +236,8 @@ - (UIImage *)currentErrorImage { - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop { if ([@"image" isEqualToString:name]) { - NSString *type = prop[@"type"]; - NSString *identifier = prop[@"identifier"]; - NSString *resId = prop[@"resId"]; DoricAsyncResult *asyncResult = [[self.doricContext.driver.registry.loaderManager - load:resId - withIdentifier:identifier - withResourceType:type + load:prop withContext:self.doricContext] fetchRaw]; [asyncResult setResultCallback:^(NSData *imageData) { [self.doricContext dispatchToMainQueue:^{