+ [ios] add extend call native
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/6225ed13 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/6225ed13 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/6225ed13 Branch: refs/heads/0.16-dev Commit: 6225ed13d9ae3dda08c848abe3ba8f669037b296 Parents: b3e4049 Author: é½å±± <sunjjb...@163.com> Authored: Thu Jul 27 12:16:51 2017 +0800 Committer: é½å±± <sunjjb...@163.com> Committed: Thu Jul 27 12:16:51 2017 +0800 ---------------------------------------------------------------------- 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 +++ ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m | 7 ++- .../Sources/Manager/WXExtendCallNativeManager.h | 15 ++++++ .../Sources/Manager/WXExtendCallNativeManager.m | 28 ++++++++++ .../Protocol/WXExtendCallNativeProtocol.h | 22 +++++++- 9 files changed, 182 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/examples/vue/hello.vue ---------------------------------------------------------------------- diff --git a/examples/vue/hello.vue b/examples/vue/hello.vue index 76272f7..e387e5a 100644 --- a/examples/vue/hello.vue +++ b/examples/vue/hello.vue @@ -1,5 +1,53 @@ +<!-- + * <template>: html-like syntax + * CSS-like inline style + * <style scoped>: only support single-class selector + * <script>: define the behavior of component + * :attr data-binding support + * @xxx syntax to bind event with a component method +--> + +<!-- + notes: + * <template> only could have just one child + * the text node is only allowed as the child of <text> as the shorthand of its `value` attribute + * the style is not inherited from parent (for example: `font-size`) + * <script> support ECMAScript 5 + * all component options assigns to `module.exports` +--> + <template> - <div> - <text style="font-size: 100px;">Hello World.</text> + <div class="wrapper" @click="update"> + <image :src="logoUrl" class="logo"></image> + <text class="title">Hello {{target}}</text> </div> -</template> \ No newline at end of file +</template> + +<style scoped> + .wrapper {align-items: center; margin-top: 120px;} + .title {font-size: 48px;} + .logo {width: 360px; height: 82px;} +</style> + +<script> + var modal = weex.requireModule('modal') + module.exports = { + data: { + logoUrl: 'https://alibaba.github.io/weex/img/weex_logo_b...@3x.png', + target: 'World' + }, + methods: { + update: function (e) { + this.target = 'Weex' + console.log('target:', this.target) + var dict = extendCallNative({ + 'className':'WXExtendCallNativeTest' + }) + modal.toast({ + 'message': dict['value'], + 'duration': 1000 + }) + } + } + } +</script> http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/ios/playground/WeexDemo.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/ios/playground/WeexDemo.xcodeproj/project.pbxproj b/ios/playground/WeexDemo.xcodeproj/project.pbxproj index 76d1423..b9695e7 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 = "<group>"; }; 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 = "<group>"; }; + C47B78D01F299E27001D3B0C /* WXExtendCallNativeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeTest.h; sourceTree = "<group>"; }; + C47B78D11F299E27001D3B0C /* WXExtendCallNativeTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXExtendCallNativeTest.m; sourceTree = "<group>"; }; DC20B8E41ECADA2500845F39 /* WXConfigCenterDefaultImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXConfigCenterDefaultImpl.h; sourceTree = "<group>"; }; DC20B8E51ECADA2500845F39 /* WXConfigCenterDefaultImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXConfigCenterDefaultImpl.m; sourceTree = "<group>"; }; DC5B53671E8CED9400E02125 /* WXScannerHistoryVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WXScannerHistoryVC.h; path = Scanner/WXScannerHistoryVC.h; sourceTree = "<group>"; }; @@ -250,6 +253,8 @@ 747DF6661E2F176A005C53A8 /* UIView+UIThreadCheck.h */, 747DF6671E2F176A005C53A8 /* UIView+UIThreadCheck.m */, 7453E3641C9FA971001EB427 /* DemoDefine.h */, + C47B78D01F299E27001D3B0C /* WXExtendCallNativeTest.h */, + C47B78D11F299E27001D3B0C /* WXExtendCallNativeTest.m */, ); name = Source; sourceTree = "<group>"; @@ -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; }; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/ios/playground/WeexDemo/WXExtendCallNativeTest.h ---------------------------------------------------------------------- diff --git a/ios/playground/WeexDemo/WXExtendCallNativeTest.h b/ios/playground/WeexDemo/WXExtendCallNativeTest.h new file mode 100644 index 0000000..50d2c2a --- /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 <Foundation/Foundation.h> +#import "WXExtendCallNativeProtocol.h" + +@interface WXExtendCallNativeTest : NSObject<WXExtendCallNativeProtocol> + +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/ios/playground/WeexDemo/WXExtendCallNativeTest.m ---------------------------------------------------------------------- diff --git a/ios/playground/WeexDemo/WXExtendCallNativeTest.m b/ios/playground/WeexDemo/WXExtendCallNativeTest.m new file mode 100644 index 0000000..afedde1 --- /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 http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/ios/sdk/WeexSDK.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj index 46f7adb..1238614 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 = "<group>"; }; C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPrerenderManager.m; sourceTree = "<group>"; }; C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeProtocol.h; sourceTree = "<group>"; }; + C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXExtendCallNativeManager.h; sourceTree = "<group>"; }; + C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXExtendCallNativeManager.m; sourceTree = "<group>"; }; C4B3D6D21E6954300013F38D /* WXEditComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXEditComponent.h; sourceTree = "<group>"; }; C4B3D6D31E6954300013F38D /* WXEditComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXEditComponent.m; sourceTree = "<group>"; }; C4B834251DE69B09007AD27E /* WXPickerModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPickerModule.m; sourceTree = "<group>"; }; @@ -970,6 +974,8 @@ 741081221CED6756001BC6E5 /* WXComponentFactory.m */, DCAB35FC1D658EB700C0EA70 /* WXRuleManager.h */, DCAB35FD1D658EB700C0EA70 /* WXRuleManager.m */, + C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */, + C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */, ); path = Manager; sourceTree = "<group>"; @@ -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 */, http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXJSCoreBridge.m index f241502..bdcb874 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 <dlfcn.h> @@ -503,9 +503,8 @@ -(id)extendCallNative:(NSDictionary *)dict { - id extendCallNative = [WXSDKEngine handlerForProtocol:@protocol(WXExtendCallNativeProtocol)]; - if(extendCallNative){ - return [extendCallNative excuteCallNative:dict]; + if(dict){ + return [WXExtendCallNativeManager sendExtendCallNativeEvent:dict]; } return @(-1); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/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 new file mode 100644 index 0000000..20c3e7d --- /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 <Foundation/Foundation.h> + +@interface WXExtendCallNativeManager : NSObject + ++(id)sendExtendCallNativeEvent:(NSDictionary *)parameters; + +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/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 new file mode 100644 index 0000000..6fbdd02 --- /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 <objc/runtime.h> + +@implementation WXExtendCallNativeManager + ++(id)sendExtendCallNativeEvent:(NSDictionary *)parameters +{ + if(parameters[@"className"]){ + Class<WXExtendCallNativeProtocol> receiveClass = NSClassFromString(parameters[@"className"]); + if(class_conformsToProtocol(receiveClass,@protocol(WXExtendCallNativeProtocol))){ + BOOL receivedItem = [receiveClass checkParameters:parameters]; + if(receivedItem){ + return [receiveClass excuteCallNative:parameters]; + } + } + } + return @(-1); +} +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6225ed13/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h b/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h index 5afb1dc..c920b73 100644 --- a/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h +++ b/ios/sdk/WeexSDK/Sources/Protocol/WXExtendCallNativeProtocol.h @@ -22,6 +22,26 @@ @protocol WXExtendCallNativeProtocol <NSObject> -- (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