feat:iOS load Resource use NSDictionary

This commit is contained in:
pengfei.zhou 2021-11-18 19:08:33 +08:00 committed by osborn
parent e270b9c520
commit 7978900a4f
3 changed files with 13 additions and 19 deletions

View File

@ -25,8 +25,6 @@
- (void)unRegisterLoader:(id <DoricResourceLoader>)loader; - (void)unRegisterLoader:(id <DoricResourceLoader>)loader;
- (__kindof DoricResource *)load:(NSString *)resId - (__kindof DoricResource *)load:(NSDictionary *)resource
withIdentifier:(NSString *)identifier
withResourceType:(NSString *)resourceType
withContext:(DoricContext *)context; withContext:(DoricContext *)context;
@end @end

View File

@ -49,20 +49,21 @@ - (void)unRegisterLoader:(id <DoricResourceLoader>)loader {
}); });
} }
- (__kindof DoricResource *)load:(NSString *)resId - (__kindof DoricResource *)load:(NSDictionary *)resource
withIdentifier:(NSString *)identifier
withResourceType:(NSString *)resourceType
withContext:(DoricContext *)context { 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, ^() { dispatch_sync(self.mapQueue, ^() {
resource = [self.cachedResources objectForKey:resId]; doricResource = [self.cachedResources objectForKey:resId];
if (!resource) { if (!doricResource) {
id <DoricResourceLoader> loader = self.loaders[resourceType]; id <DoricResourceLoader> loader = self.loaders[type];
resource = [loader load:identifier withContext:context]; doricResource = [loader load:identifier withContext:context];
[self.cachedResources setObject:resource forKey:resId]; [self.cachedResources setObject:doricResource forKey:resId];
} }
}); });
return resource; return doricResource;
} }
@end @end

View File

@ -236,13 +236,8 @@ - (UIImage *)currentErrorImage {
- (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([@"image" isEqualToString:name]) { if ([@"image" isEqualToString:name]) {
NSString *type = prop[@"type"];
NSString *identifier = prop[@"identifier"];
NSString *resId = prop[@"resId"];
DoricAsyncResult <NSData *> *asyncResult = [[self.doricContext.driver.registry.loaderManager DoricAsyncResult <NSData *> *asyncResult = [[self.doricContext.driver.registry.loaderManager
load:resId load:prop
withIdentifier:identifier
withResourceType:type
withContext:self.doricContext] fetchRaw]; withContext:self.doricContext] fetchRaw];
[asyncResult setResultCallback:^(NSData *imageData) { [asyncResult setResultCallback:^(NSData *imageData) {
[self.doricContext dispatchToMainQueue:^{ [self.doricContext dispatchToMainQueue:^{