Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[IOS] support component method call in background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
hpop1994 committed May 24, 2019
1 parent 151c469 commit 8f5ebf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
+ (NSMutableDictionary *)componentMethodMapsWithName:(NSString *)name;
+ (NSMutableDictionary *)componentSelectorMapsWithName:(NSString *)name;

+ (SEL)methodWithComponentName:(NSString *)name withMethod:(NSString *)method;
+ (SEL)methodWithComponentName:(NSString *)name withMethod:(NSString *)method isSync:(BOOL *)isSync;

/**
* @abstract Unregister all the components
Expand Down
16 changes: 11 additions & 5 deletions ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ + (NSDictionary *)componentConfigs {
return [[self sharedInstance] getComponentConfigs];
}

+ (SEL)methodWithComponentName:(NSString *)name withMethod:(NSString *)method
+ (SEL)methodWithComponentName:(NSString *)name withMethod:(NSString *)method isSync:(BOOL *)isSync
{
return [[self sharedInstance] _methodWithComponetName:name withMethod:method];
return [[self sharedInstance] _methodWithComponetName:name withMethod:method isSync:isSync];
}

+ (NSMutableDictionary *)componentMethodMapsWithName:(NSString *)name
Expand Down Expand Up @@ -155,6 +155,7 @@ - (NSMutableDictionary *)_componentMethodMapsWithName:(NSString *)name
[methods addObject:mKey];
};
[config.asyncMethods enumerateKeysAndObjectsUsingBlock:mBlock];
[config.syncMethods enumerateKeysAndObjectsUsingBlock:mBlock];
[_configLock unlock];

return dict;
Expand All @@ -173,28 +174,33 @@ - (NSMutableDictionary *)_componentSelectorMapsWithName:(NSString *)name
[methods addObject:mObj];
};
[config.asyncMethods enumerateKeysAndObjectsUsingBlock:mBlock];
[config.syncMethods enumerateKeysAndObjectsUsingBlock:mBlock];
[_configLock unlock];

return dict;
}

- (SEL)_methodWithComponetName:(NSString *)name withMethod:(NSString *)method
- (SEL)_methodWithComponetName:(NSString *)name withMethod:(NSString *)method isSync:(BOOL *)isSync
{
WXAssert(name && method, @"Fail to find selector with module name and method, please check if the parameters are correct !");

NSString *selStr = nil; SEL selector = nil;
WXComponentConfig *config = nil;

[_configLock lock];
config = [_componentConfigs objectForKey:name];
if (config.asyncMethods) {
selStr = [config.asyncMethods objectForKey:method];
}
if (!selStr && config.syncMethods) {
selStr = [config.syncMethods objectForKey:method];
if (selStr.length > 0 && isSync) {
*isSync = YES;
}
}
if (selStr) {
selector = NSSelectorFromString(selStr);
}
[_configLock unlock];

return selector;
}

Expand Down

0 comments on commit 8f5ebf3

Please sign in to comment.