+ [ios] update native logic
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/4d78365d Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/4d78365d Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/4d78365d Branch: refs/heads/0.16-dev Commit: 4d78365d0099bebd598351959ac0c4a0e0a30dc0 Parents: 5100991 Author: é½å±± <sunjjb...@163.com> Authored: Tue Aug 8 16:38:23 2017 +0800 Committer: é½å±± <sunjjb...@163.com> Committed: Tue Aug 8 16:38:23 2017 +0800 ---------------------------------------------------------------------- examples/vue/hello.vue | 2 +- ios/playground/WeexDemo/AppDelegate.m | 2 + ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h | 10 +++++ ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 6 +++ .../Sources/Manager/WXExtendCallNativeManager.h | 5 ++- .../Sources/Manager/WXExtendCallNativeManager.m | 45 +++++++++++++++++++- 6 files changed, 65 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d78365d/examples/vue/hello.vue ---------------------------------------------------------------------- diff --git a/examples/vue/hello.vue b/examples/vue/hello.vue index e387e5a..8309aaa 100644 --- a/examples/vue/hello.vue +++ b/examples/vue/hello.vue @@ -41,7 +41,7 @@ this.target = 'Weex' console.log('target:', this.target) var dict = extendCallNative({ - 'className':'WXExtendCallNativeTest' + 'className':'test' }) modal.toast({ 'message': dict['value'], http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d78365d/ios/playground/WeexDemo/AppDelegate.m ---------------------------------------------------------------------- diff --git a/ios/playground/WeexDemo/AppDelegate.m b/ios/playground/WeexDemo/AppDelegate.m index 4d9b9cd..d8472cd 100644 --- a/ios/playground/WeexDemo/AppDelegate.m +++ b/ios/playground/WeexDemo/AppDelegate.m @@ -119,6 +119,8 @@ [WXSDKEngine registerComponent:@"select" withClass:NSClassFromString(@"WXSelectComponent")]; [WXSDKEngine registerModule:@"event" withClass:[WXEventModule class]]; [WXSDKEngine registerModule:@"syncTest" withClass:[WXSyncTestModule class]]; + [WXSDKEngine registerExtendCallNative:@"test" withClass:NSClassFromString(@"WXExtendCallNativeTest")]; + #if !(TARGET_IPHONE_SIMULATOR) [self checkUpdate]; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d78365d/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h index 32a26d1..5e7b1e7 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h @@ -49,6 +49,16 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz; /** + * @abstract Registers a extendCallNative Class for a given name + * + * @param name The extendCallNative name to register + * + * @param clazz The extendCallNative subclass to register + * + **/ ++ (void)registerExtendCallNative:(NSString *)name withClass:(Class)clazz; + +/** * @abstract Registers a component for a given name and specific properties * * @param name The component name to register http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d78365d/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m index b95ad9d..7e8d99c 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m @@ -37,6 +37,7 @@ #import "WXAssert.h" #import "WXLog.h" #import "WXUtility.h" +#import "WXExtendCallNativeManager.h" @implementation WXSDKEngine @@ -114,6 +115,11 @@ [self registerComponent:name withClass:clazz withProperties: @{@"append":@"tree"}]; } ++ (void)registerExtendCallNative:(NSString *)name withClass:(Class)clazz +{ + [WXExtendCallNativeManager registerExtendCallNative:name withClass:clazz]; +} + + (void)registerComponent:(NSString *)name withClass:(Class)clazz withProperties:(NSDictionary *)properties { if (!name || !clazz) { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d78365d/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h index 20c3e7d..cb5fea6 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h @@ -10,6 +10,7 @@ @interface WXExtendCallNativeManager : NSObject -+(id)sendExtendCallNativeEvent:(NSDictionary *)parameters; - ++ (id)sendExtendCallNativeEvent:(NSDictionary *)parameters; ++ (void)registerExtendCallNative:(NSString *)name withClass:(Class)clazz; ++ (Class)classWithComponentName:(NSString *)name; @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/4d78365d/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m index 6fbdd02..58a7cdd 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m @@ -10,13 +10,54 @@ #import "WXExtendCallNativeProtocol.h" #import <objc/runtime.h> +@interface WXExtendCallNativeManager () + +@property (nonatomic, strong) NSMutableDictionary *names; + +@end + @implementation WXExtendCallNativeManager +{ + NSLock *_configLock; +} ++ (instancetype) sharedInstance{ + + static WXExtendCallNativeManager *instance = nil; + static dispatch_once_t once; + + dispatch_once(&once, ^{ + instance = [[WXExtendCallNativeManager alloc] initPrivate]; + }); + + return instance; +} + +- (instancetype) initPrivate{ + self = [super init]; + if(self){ + _configLock = [[NSLock alloc] init]; + self.names = [NSMutableDictionary new]; + } + + return self; +} + ++ (void)registerExtendCallNative:(NSString *)name withClass:(Class)clazz +{ + [[WXExtendCallNativeManager sharedInstance].names setObject:NSStringFromClass(clazz) forKey:name]; +} + ++ (Class)classWithExtendCallNativeName:(NSString *)name +{ + NSString *clazz = [[WXExtendCallNativeManager sharedInstance].names objectForKey:name]; + return NSClassFromString(clazz); +} +(id)sendExtendCallNativeEvent:(NSDictionary *)parameters { if(parameters[@"className"]){ - Class<WXExtendCallNativeProtocol> receiveClass = NSClassFromString(parameters[@"className"]); - if(class_conformsToProtocol(receiveClass,@protocol(WXExtendCallNativeProtocol))){ + Class<WXExtendCallNativeProtocol> receiveClass = [self classWithExtendCallNativeName:parameters[@"className"]]; + if(receiveClass && class_conformsToProtocol(receiveClass,@protocol(WXExtendCallNativeProtocol))){ BOOL receivedItem = [receiveClass checkParameters:parameters]; if(receivedItem){ return [receiveClass excuteCallNative:parameters];