From b3e404937bafa77cee4544c97598c1c4ec6ef2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=B1=B1?= Date: Sun, 23 Jul 2017 21:30:45 +0800 Subject: [PATCH 1/5] + [ios] support extend call native for third part --- ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 4 +++ .../WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 14 ++++++++++ .../Protocol/WXExtendCallNativeProtocol.h | 27 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj index d16e63055b..46f7adbde3 100644 --- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj +++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj @@ -238,6 +238,7 @@ C41E1A981DC1FD15009C7F90 /* WXDatePickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C41E1A961DC1FD15009C7F90 /* WXDatePickerManager.m */; }; C43C03E81EC8ACA40044C7FF /* WXPrerenderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; C43C03E91EC8ACA40044C7FF /* WXPrerenderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */; }; + C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; }; C4B3D6D41E6954300013F38D /* WXEditComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = C4B3D6D21E6954300013F38D /* WXEditComponent.h */; }; C4B3D6D51E6954300013F38D /* WXEditComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B3D6D31E6954300013F38D /* WXEditComponent.m */; }; C4B834271DE69B09007AD27E /* WXPickerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B834251DE69B09007AD27E /* WXPickerModule.m */; }; @@ -555,6 +556,7 @@ C41E1A961DC1FD15009C7F90 /* WXDatePickerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXDatePickerManager.m; sourceTree = ""; }; C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXPrerenderManager.h; sourceTree = ""; }; C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPrerenderManager.m; sourceTree = ""; }; + C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeProtocol.h; sourceTree = ""; }; C4B3D6D21E6954300013F38D /* WXEditComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXEditComponent.h; sourceTree = ""; }; C4B3D6D31E6954300013F38D /* WXEditComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXEditComponent.m; sourceTree = ""; }; C4B834251DE69B09007AD27E /* WXPickerModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPickerModule.m; sourceTree = ""; }; @@ -1002,6 +1004,7 @@ 74EF31A91DE58AE600667A07 /* WXURLRewriteProtocol.h */, 042013AC1E66CD6A001FC79C /* WXValidateProtocol.h */, DC6836E51EBB12B200AD2D84 /* WXConfigCenterProtocol.h */, + C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */, ); path = Protocol; sourceTree = ""; @@ -1338,6 +1341,7 @@ 744BEA551D05178F00452B5D /* WXComponent+Display.h in Headers */, 741081231CED6756001BC6E5 /* WXComponentFactory.h in Headers */, 59D3CA4A1CFC3CE1008835DC /* NSTimer+Weex.h in Headers */, + C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */, D334510C1D3E19B80083598A /* WXCanvasModule.h in Headers */, 742AD73A1DF98C8B007DC46C /* WXResourceLoader.h in Headers */, 746319291C71B92600EFEBD4 /* WXModalUIModule.h in Headers */, diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m index ee9406a05f..f2415020b9 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m @@ -34,6 +34,7 @@ #import "JSValue+Weex.h" #import "WXJSExceptionProtocol.h" #import "WXSDKManager.h" +#import "WXExtendCallNativeProtocol.h" #import @@ -103,6 +104,9 @@ - (instancetype)init initWithData:nsdataFromBase64String encoding:NSUTF8StringEncoding]; return base64Decoded; }; + _jsContext[@"extendCallNative"] = ^(JSValue *value ) { + return [weakSelf extendCallNative:[value toDictionary]]; + }; _jsContext[@"nativeLog"] = ^() { static NSDictionary *levelMap; @@ -496,4 +500,14 @@ - (void)triggerClearTimeout:(NSString *)ret [_timers removeObject:ret]; } } + +-(id)extendCallNative:(NSDictionary *)dict +{ + id extendCallNative = [WXSDKEngine handlerForProtocol:@protocol(WXExtendCallNativeProtocol)]; + if(extendCallNative){ + return [extendCallNative excuteCallNative:dict]; + } + return @(-1); +} + @end diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h b/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h new file mode 100644 index 0000000000..5afb1dcc80 --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +#import + +@protocol WXExtendCallNativeProtocol + +- (id)excuteCallNative:(NSDictionary *)dict; + +@end From 6225ed13d9ae3dda08c848abe3ba8f669037b296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=B1=B1?= Date: Thu, 27 Jul 2017 12:16:51 +0800 Subject: [PATCH 2/5] + [ios] add extend call native --- examples/vue/hello.vue | 54 +++++++++++++++++-- .../WeexDemo.xcodeproj/project.pbxproj | 6 +++ .../WeexDemo/WXExtendCallNativeTest.h | 14 +++++ .../WeexDemo/WXExtendCallNativeTest.m | 36 +++++++++++++ ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 8 +++ .../WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 7 ++- .../Manager/WXExtendCallNativeManager.h | 15 ++++++ .../Manager/WXExtendCallNativeManager.m | 28 ++++++++++ .../Protocol/WXExtendCallNativeProtocol.h | 22 +++++++- 9 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 ios/playground/WeexDemo/WXExtendCallNativeTest.h create mode 100644 ios/playground/WeexDemo/WXExtendCallNativeTest.m create mode 100644 ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h create mode 100644 ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m diff --git a/examples/vue/hello.vue b/examples/vue/hello.vue index 76272f7cbc..e387e5a79d 100644 --- a/examples/vue/hello.vue +++ b/examples/vue/hello.vue @@ -1,5 +1,53 @@ + + + + \ No newline at end of file + + + + + diff --git a/ios/playground/WeexDemo.xcodeproj/project.pbxproj b/ios/playground/WeexDemo.xcodeproj/project.pbxproj index 76d1423f0d..b9695e79d6 100644 --- a/ios/playground/WeexDemo.xcodeproj/project.pbxproj +++ b/ios/playground/WeexDemo.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 846FC8DB1E1B853600949E7D /* WXATViewHierarchyPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = DCABAFF21D029685001C8592 /* WXATViewHierarchyPlugin.m */; }; 84D7CAC71CE3266C00D48D46 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7475ACA01CD8444A0044E96C /* libsqlite3.0.tbd */; }; 8A0B5EFFF75BF82EA481983D /* libPods-WeexUITestDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E48C20F443AA337D1FE97622 /* libPods-WeexUITestDemo.a */; }; + C47B78D21F299E27001D3B0C /* WXExtendCallNativeTest.m in Sources */ = {isa = PBXBuildFile; fileRef = C47B78D11F299E27001D3B0C /* WXExtendCallNativeTest.m */; }; DC20B8E61ECADA2500845F39 /* WXConfigCenterDefaultImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = DC20B8E51ECADA2500845F39 /* WXConfigCenterDefaultImpl.m */; }; DC5B53691E8CED9400E02125 /* WXScannerHistoryVC.m in Sources */ = {isa = PBXBuildFile; fileRef = DC5B53681E8CED9400E02125 /* WXScannerHistoryVC.m */; }; DC5E503E1D0D97130059F0EB /* weex.png in Resources */ = {isa = PBXBuildFile; fileRef = DC5E503C1D0D97130059F0EB /* weex.png */; }; @@ -89,6 +90,8 @@ 775BEE9A1C1E8ECC008D1629 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84361D751CA10F8E00F43825 /* WeexUITestDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WeexUITestDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9420131417A731ED089B0814 /* Pods-WeexDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeexDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-WeexDemo/Pods-WeexDemo.release.xcconfig"; sourceTree = ""; }; + C47B78D01F299E27001D3B0C /* WXExtendCallNativeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeTest.h; sourceTree = ""; }; + C47B78D11F299E27001D3B0C /* WXExtendCallNativeTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXExtendCallNativeTest.m; sourceTree = ""; }; DC20B8E41ECADA2500845F39 /* WXConfigCenterDefaultImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXConfigCenterDefaultImpl.h; sourceTree = ""; }; DC20B8E51ECADA2500845F39 /* WXConfigCenterDefaultImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXConfigCenterDefaultImpl.m; sourceTree = ""; }; DC5B53671E8CED9400E02125 /* WXScannerHistoryVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WXScannerHistoryVC.h; path = Scanner/WXScannerHistoryVC.h; sourceTree = ""; }; @@ -250,6 +253,8 @@ 747DF6661E2F176A005C53A8 /* UIView+UIThreadCheck.h */, 747DF6671E2F176A005C53A8 /* UIView+UIThreadCheck.m */, 7453E3641C9FA971001EB427 /* DemoDefine.h */, + C47B78D01F299E27001D3B0C /* WXExtendCallNativeTest.h */, + C47B78D11F299E27001D3B0C /* WXExtendCallNativeTest.m */, ); name = Source; sourceTree = ""; @@ -574,6 +579,7 @@ 775BEE801C1E8ECC008D1629 /* main.m in Sources */, DCABAFFE1D029753001C8592 /* WXImgLoaderDefaultImpl.m in Sources */, 747DF6681E2F176A005C53A8 /* UIView+UIThreadCheck.m in Sources */, + C47B78D21F299E27001D3B0C /* WXExtendCallNativeTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ios/playground/WeexDemo/WXExtendCallNativeTest.h b/ios/playground/WeexDemo/WXExtendCallNativeTest.h new file mode 100644 index 0000000000..50d2c2a63d --- /dev/null +++ b/ios/playground/WeexDemo/WXExtendCallNativeTest.h @@ -0,0 +1,14 @@ +// +// WXExtendCallNativeTest.h +// WeexDemo +// +// Created by 齐山 on 2017/7/27. +// Copyright © 2017年 taobao. All rights reserved. +// + +#import +#import "WXExtendCallNativeProtocol.h" + +@interface WXExtendCallNativeTest : NSObject + +@end diff --git a/ios/playground/WeexDemo/WXExtendCallNativeTest.m b/ios/playground/WeexDemo/WXExtendCallNativeTest.m new file mode 100644 index 0000000000..afedde186f --- /dev/null +++ b/ios/playground/WeexDemo/WXExtendCallNativeTest.m @@ -0,0 +1,36 @@ +// +// WXExtendCallNativeTest.m +// WeexDemo +// +// Created by 齐山 on 2017/7/27. +// Copyright © 2017年 taobao. All rights reserved. +// + +#import "WXExtendCallNativeTest.h" + +@implementation WXExtendCallNativeTest + +#pragma mark - +#pragma WXExtendCallNativeProtocol + ++ (BOOL)checkParameters:(NSDictionary *)parameters +{ + if(!parameters || ![parameters isKindOfClass:[NSDictionary class]]){ + return NO; + } + + if(!parameters[@"className"]){ + return NO; + } + + return YES; +} + + ++ (id)excuteCallNative:(NSDictionary *)parameters +{ + NSLog(@"weex test"); + return @{@"value":@"test"}; +} + +@end diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj index 46f7adbde3..1238614c53 100644 --- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj +++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj @@ -239,6 +239,8 @@ C43C03E81EC8ACA40044C7FF /* WXPrerenderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; C43C03E91EC8ACA40044C7FF /* WXPrerenderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */; }; C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; }; + C47B78CE1F2998EE001D3B0C /* WXExtendCallNativeManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */; }; + C47B78CF1F2998EE001D3B0C /* WXExtendCallNativeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */; }; C4B3D6D41E6954300013F38D /* WXEditComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = C4B3D6D21E6954300013F38D /* WXEditComponent.h */; }; C4B3D6D51E6954300013F38D /* WXEditComponent.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B3D6D31E6954300013F38D /* WXEditComponent.m */; }; C4B834271DE69B09007AD27E /* WXPickerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B834251DE69B09007AD27E /* WXPickerModule.m */; }; @@ -557,6 +559,8 @@ C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXPrerenderManager.h; sourceTree = ""; }; C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPrerenderManager.m; sourceTree = ""; }; C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeProtocol.h; sourceTree = ""; }; + C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeManager.h; sourceTree = ""; }; + C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXExtendCallNativeManager.m; sourceTree = ""; }; C4B3D6D21E6954300013F38D /* WXEditComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXEditComponent.h; sourceTree = ""; }; C4B3D6D31E6954300013F38D /* WXEditComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXEditComponent.m; sourceTree = ""; }; C4B834251DE69B09007AD27E /* WXPickerModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPickerModule.m; sourceTree = ""; }; @@ -970,6 +974,8 @@ 741081221CED6756001BC6E5 /* WXComponentFactory.m */, DCAB35FC1D658EB700C0EA70 /* WXRuleManager.h */, DCAB35FD1D658EB700C0EA70 /* WXRuleManager.m */, + C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */, + C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */, ); path = Manager; sourceTree = ""; @@ -1259,6 +1265,7 @@ 77D161621C02ED790010B15B /* WXLog.h in Headers */, 77D1614B1C02E3790010B15B /* WXConvert.h in Headers */, 59A596221CB6311F0012CD52 /* WXNavigatorModule.h in Headers */, + C47B78CE1F2998EE001D3B0C /* WXExtendCallNativeManager.h in Headers */, 745B2D6A1E5A8E1E0092D38A /* WXRecyclerComponent.h in Headers */, 749DC27B1D40827B009E1C91 /* WXMonitor.h in Headers */, 77E659DA1C07F594008B8775 /* WXDomModule.h in Headers */, @@ -1558,6 +1565,7 @@ C4F012831E1502E9003378D0 /* WXWebSocketModule.m in Sources */, 59D3CA401CF9ED57008835DC /* Layout.c in Sources */, DCF087621DCAE161005CD6EB /* WXInvocationConfig.m in Sources */, + C47B78CF1F2998EE001D3B0C /* WXExtendCallNativeManager.m in Sources */, 77D161311C02DE4E0010B15B /* WXComponent.m in Sources */, 74862F7A1E02B88D00B7A041 /* JSValue+Weex.m in Sources */, 740451EB1E14BB26004157CB /* WXServiceFactory.m in Sources */, diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m index f2415020b9..bdcb874e2d 100644 --- a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m +++ b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m @@ -34,7 +34,7 @@ #import "JSValue+Weex.h" #import "WXJSExceptionProtocol.h" #import "WXSDKManager.h" -#import "WXExtendCallNativeProtocol.h" +#import "WXExtendCallNativeManager.h" #import @@ -503,9 +503,8 @@ - (void)triggerClearTimeout:(NSString *)ret -(id)extendCallNative:(NSDictionary *)dict { - id extendCallNative = [WXSDKEngine handlerForProtocol:@protocol(WXExtendCallNativeProtocol)]; - if(extendCallNative){ - return [extendCallNative excuteCallNative:dict]; + if(dict){ + return [WXExtendCallNativeManager sendExtendCallNativeEvent:dict]; } return @(-1); } diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h new file mode 100644 index 0000000000..20c3e7d26c --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h @@ -0,0 +1,15 @@ +// +// WXExtendCallNativeManager.h +// WeexSDK +// +// Created by 齐山 on 2017/7/27. +// Copyright © 2017年 taobao. All rights reserved. +// + +#import + +@interface WXExtendCallNativeManager : NSObject + ++(id)sendExtendCallNativeEvent:(NSDictionary *)parameters; + +@end diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m new file mode 100644 index 0000000000..6fbdd02b74 --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m @@ -0,0 +1,28 @@ +// +// WXExtendCallNativeManager.m +// WeexSDK +// +// Created by 齐山 on 2017/7/27. +// Copyright © 2017年 taobao. All rights reserved. +// + +#import "WXExtendCallNativeManager.h" +#import "WXExtendCallNativeProtocol.h" +#import + +@implementation WXExtendCallNativeManager + ++(id)sendExtendCallNativeEvent:(NSDictionary *)parameters +{ + if(parameters[@"className"]){ + Class receiveClass = NSClassFromString(parameters[@"className"]); + if(class_conformsToProtocol(receiveClass,@protocol(WXExtendCallNativeProtocol))){ + BOOL receivedItem = [receiveClass checkParameters:parameters]; + if(receivedItem){ + return [receiveClass excuteCallNative:parameters]; + } + } + } + return @(-1); +} +@end diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h b/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h index 5afb1dcc80..c920b73f5d 100644 --- a/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h +++ b/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h @@ -22,6 +22,26 @@ @protocol WXExtendCallNativeProtocol -- (id)excuteCallNative:(NSDictionary *)dict; +@required + +/** + * @abstract check parameters + * + * @param parameters the checked parameters. + * + * @return YES or NO. + * + */ ++ (BOOL)checkParameters:(NSDictionary *)parameters; + +/** + * @abstract excuteCallNative + * + * @param parameters the checked parameters. + * + * @return A value. + * + */ ++ (id)excuteCallNative:(NSDictionary *)parameters; @end From 4d78365d0099bebd598351959ac0c4a0e0a30dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=B1=B1?= Date: Tue, 8 Aug 2017 16:38:23 +0800 Subject: [PATCH 3/5] + [ios] update native logic --- 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 +++ .../Manager/WXExtendCallNativeManager.h | 5 ++- .../Manager/WXExtendCallNativeManager.m | 45 ++++++++++++++++++- 6 files changed, 65 insertions(+), 5 deletions(-) diff --git a/examples/vue/hello.vue b/examples/vue/hello.vue index e387e5a79d..8309aaa2e0 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'], diff --git a/ios/playground/WeexDemo/AppDelegate.m b/ios/playground/WeexDemo/AppDelegate.m index 4d9b9cd242..d8472cd92f 100644 --- a/ios/playground/WeexDemo/AppDelegate.m +++ b/ios/playground/WeexDemo/AppDelegate.m @@ -119,6 +119,8 @@ - (void)initWeexSDK [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]; diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h index 32a26d185d..5e7b1e7db6 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.h @@ -48,6 +48,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 * diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m index b95ad9dd79..7e8d99ce5d 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 @@ + (void)registerComponent:(NSString *)name withClass:(Class)clazz [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) { diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h index 20c3e7d26c..cb5fea6cff 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 diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m index 6fbdd02b74..58a7cdd059 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 +@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 receiveClass = NSClassFromString(parameters[@"className"]); - if(class_conformsToProtocol(receiveClass,@protocol(WXExtendCallNativeProtocol))){ + Class receiveClass = [self classWithExtendCallNativeName:parameters[@"className"]]; + if(receiveClass && class_conformsToProtocol(receiveClass,@protocol(WXExtendCallNativeProtocol))){ BOOL receivedItem = [receiveClass checkParameters:parameters]; if(receivedItem){ return [receiveClass excuteCallNative:parameters]; From 816bde1bdedfdc79d4f6ae4f3404564d4fa60741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=B1=B1?= Date: Thu, 10 Aug 2017 16:10:46 +0800 Subject: [PATCH 4/5] + [ios] add license @notdanger --- examples/vue/hello.vue | 54 ++----------------- .../WeexDemo/WXExtendCallNativeTest.h | 25 ++++++--- .../WeexDemo/WXExtendCallNativeTest.m | 25 ++++++--- .../Manager/WXExtendCallNativeManager.h | 26 ++++++--- .../Manager/WXExtendCallNativeManager.m | 25 ++++++--- 5 files changed, 75 insertions(+), 80 deletions(-) diff --git a/examples/vue/hello.vue b/examples/vue/hello.vue index 8309aaa2e0..76272f7cbc 100644 --- a/examples/vue/hello.vue +++ b/examples/vue/hello.vue @@ -1,53 +1,5 @@ - - - - - - - - + \ No newline at end of file diff --git a/ios/playground/WeexDemo/WXExtendCallNativeTest.h b/ios/playground/WeexDemo/WXExtendCallNativeTest.h index 50d2c2a63d..4671779782 100644 --- a/ios/playground/WeexDemo/WXExtendCallNativeTest.h +++ b/ios/playground/WeexDemo/WXExtendCallNativeTest.h @@ -1,10 +1,21 @@ -// -// WXExtendCallNativeTest.h -// WeexDemo -// -// Created by 齐山 on 2017/7/27. -// Copyright © 2017年 taobao. All rights reserved. -// +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #import #import "WXExtendCallNativeProtocol.h" diff --git a/ios/playground/WeexDemo/WXExtendCallNativeTest.m b/ios/playground/WeexDemo/WXExtendCallNativeTest.m index afedde186f..ba11caf39c 100644 --- a/ios/playground/WeexDemo/WXExtendCallNativeTest.m +++ b/ios/playground/WeexDemo/WXExtendCallNativeTest.m @@ -1,10 +1,21 @@ -// -// WXExtendCallNativeTest.m -// WeexDemo -// -// Created by 齐山 on 2017/7/27. -// Copyright © 2017年 taobao. All rights reserved. -// +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #import "WXExtendCallNativeTest.h" diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h index cb5fea6cff..ded9bc7895 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h +++ b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.h @@ -1,10 +1,21 @@ -// -// WXExtendCallNativeManager.h -// WeexSDK -// -// Created by 齐山 on 2017/7/27. -// Copyright © 2017年 taobao. All rights reserved. -// +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #import @@ -12,5 +23,4 @@ + (id)sendExtendCallNativeEvent:(NSDictionary *)parameters; + (void)registerExtendCallNative:(NSString *)name withClass:(Class)clazz; -+ (Class)classWithComponentName:(NSString *)name; @end diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m index 58a7cdd059..17b15417d8 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXExtendCallNativeManager.m @@ -1,10 +1,21 @@ -// -// WXExtendCallNativeManager.m -// WeexSDK -// -// Created by 齐山 on 2017/7/27. -// Copyright © 2017年 taobao. All rights reserved. -// +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ #import "WXExtendCallNativeManager.h" #import "WXExtendCallNativeProtocol.h" From 4df48bccd61ca4ccadb26861dd8a98036024f25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BD=90=E5=B1=B1?= Date: Thu, 10 Aug 2017 19:36:38 +0800 Subject: [PATCH 5/5] + [ios] add file to weexsdk @notdanger --- ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 12 +++++++++++- ios/sdk/WeexSDK/Sources/WeexSDK.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj index 1164250eae..7f19a7cf47 100644 --- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj +++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj @@ -236,9 +236,14 @@ C401945E1E344E8300D19C31 /* WXFloatCompareTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C401945D1E344E8300D19C31 /* WXFloatCompareTests.m */; }; C41E1A971DC1FD15009C7F90 /* WXDatePickerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C41E1A951DC1FD15009C7F90 /* WXDatePickerManager.h */; }; C41E1A981DC1FD15009C7F90 /* WXDatePickerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C41E1A961DC1FD15009C7F90 /* WXDatePickerManager.m */; }; + C42E8FAB1F3C7C09001EBE9D /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + C42E8FAC1F3C7C3B001EBE9D /* WXExtendCallNativeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */; }; + C42E8FAD1F3C7C3F001EBE9D /* WXExtendCallNativeManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */; }; + C42E8FAE1F3C7C49001EBE9D /* WXRecyclerDragController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC7764911F3C2CA300B5727E /* WXRecyclerDragController.m */; }; + C42E8FAF1F3C7C4B001EBE9D /* WXRecyclerDragController.h in Headers */ = {isa = PBXBuildFile; fileRef = DC7764921F3C2CA300B5727E /* WXRecyclerDragController.h */; }; C43C03E81EC8ACA40044C7FF /* WXPrerenderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; C43C03E91EC8ACA40044C7FF /* WXPrerenderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */; }; - C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; }; + C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; C47B78CE1F2998EE001D3B0C /* WXExtendCallNativeManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */; }; C47B78CF1F2998EE001D3B0C /* WXExtendCallNativeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */; }; C4B3D6D41E6954300013F38D /* WXEditComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = C4B3D6D21E6954300013F38D /* WXEditComponent.h */; }; @@ -1652,6 +1657,7 @@ DCA445B21EFA576D00D0CFA8 /* WXListComponent.h in Headers */, DCA445A51EFA571600D0CFA8 /* WXSDKError.h in Headers */, DCA445AD1EFA575100D0CFA8 /* WXNavigationProtocol.h in Headers */, + C42E8FAF1F3C7C4B001EBE9D /* WXRecyclerDragController.h in Headers */, DCA445B01EFA576200D0CFA8 /* WXModalUIModule.h in Headers */, DCA445A61EFA571E00D0CFA8 /* WXSDKEngine.h in Headers */, DCA445AA1EFA573900D0CFA8 /* WXResourceRequest.h in Headers */, @@ -1703,6 +1709,7 @@ DCA4461F1EFA5AB100D0CFA8 /* WXRuleManager.h in Headers */, DCA445E31EFA59DA00D0CFA8 /* WXEmbedComponent.h in Headers */, DCA445DF1EFA59BC00D0CFA8 /* WXLoadingComponent.h in Headers */, + C42E8FAD1F3C7C3F001EBE9D /* WXExtendCallNativeManager.h in Headers */, DCA445CB1EFA590600D0CFA8 /* WXComponent+Layout.h in Headers */, DCA4460F1EFA5A8100D0CFA8 /* WXDiffUtil.h in Headers */, DCA445F91EFA5A3700D0CFA8 /* WXClipboardModule.h in Headers */, @@ -1750,6 +1757,7 @@ DCA446061EFA5A5B00D0CFA8 /* NSTimer+Weex.h in Headers */, DCA445D61EFA598600D0CFA8 /* WXView.h in Headers */, DCA445FF1EFA5A4600D0CFA8 /* WXInstanceWrap.h in Headers */, + C42E8FAB1F3C7C09001EBE9D /* WXExtendCallNativeProtocol.h in Headers */, DCA445F31EFA5A2500D0CFA8 /* WXFooterComponent.h in Headers */, DCA446151EFA5A9000D0CFA8 /* WXBridgeContext.h in Headers */, DCA4461A1EFA5AA000D0CFA8 /* WXInvocationConfig.h in Headers */, @@ -2193,6 +2201,7 @@ DCA445661EFA55B300D0CFA8 /* WXNavigatorModule.m in Sources */, DCA445671EFA55B300D0CFA8 /* WXStorageModule.m in Sources */, DCA445681EFA55B300D0CFA8 /* WXStreamModule.m in Sources */, + C42E8FAC1F3C7C3B001EBE9D /* WXExtendCallNativeManager.m in Sources */, DCA445691EFA55B300D0CFA8 /* WXAnimationModule.m in Sources */, DCA4456A1EFA55B300D0CFA8 /* WXAnimationLayout.m in Sources */, DCA4456B1EFA55B300D0CFA8 /* WXInstanceWrap.m in Sources */, @@ -2213,6 +2222,7 @@ DCA4457A1EFA55B300D0CFA8 /* WXSimulatorShortcutManager.m in Sources */, DCA4457B1EFA55B300D0CFA8 /* WXAssert.m in Sources */, DCA4457C1EFA55B300D0CFA8 /* WXAppConfiguration.m in Sources */, + C42E8FAE1F3C7C49001EBE9D /* WXRecyclerDragController.m in Sources */, DCA4457D1EFA55B300D0CFA8 /* WXThreadSafeMutableDictionary.m in Sources */, DCA4457E1EFA55B300D0CFA8 /* WXThreadSafeMutableArray.m in Sources */, DCA4457F1EFA55B300D0CFA8 /* NSObject+WXSwizzle.m in Sources */, diff --git a/ios/sdk/WeexSDK/Sources/WeexSDK.h b/ios/sdk/WeexSDK/Sources/WeexSDK.h index ec9b2ccaeb..959369d02e 100644 --- a/ios/sdk/WeexSDK/Sources/WeexSDK.h +++ b/ios/sdk/WeexSDK/Sources/WeexSDK.h @@ -48,6 +48,7 @@ #import "WXJSExceptionInfo.h" #import "WXIndicatorComponent.h" #import "WXImgLoaderProtocol.h" +#import "WXExtendCallNativeProtocol.h" #import "WXEventModuleProtocol.h" #import "WXErrorView.h" #import "WXDefine.h"