diff --git a/iOS/Example/Example/ViewController.m b/iOS/Example/Example/ViewController.m index d42f0548..331913a0 100644 --- a/iOS/Example/Example/ViewController.m +++ b/iOS/Example/Example/ViewController.m @@ -13,7 +13,7 @@ #import "DoricNativePlugin.h" @interface ViewController () - +@property (nonatomic,strong) DoricContext *doricContext; @end @implementation ViewController @@ -30,15 +30,13 @@ - (void)viewDidLoad { UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test:)]; [label addGestureRecognizer:recognizer]; label.userInteractionEnabled = YES; + NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"demo" ofType:@"js"]; + NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; + self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"demo"]; } - (void)test:(UIView *)view { NSLog(@"test"); - NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"demo" ofType:@"js"]; - NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; - DoricContext *context = [[DoricContext alloc] initWithScript:jsContent source:@"demo"]; - [context callEntity:@"log",nil]; - DoricNativePlugin *doricNativePlugin = [[DoricNativePlugin alloc] initWithContext:context]; - NSLog(@"%@",doricNativePlugin.doricContext); + [self.doricContext callEntity:@"log",nil]; } @end diff --git a/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj b/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj index 6b2a778c..75fa7935 100644 --- a/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/iOS/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -34,6 +34,10 @@ D94DF789BBDA69CD5F0FC22532A79854 /* DoricContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CDE936E82BE58F942B70B497594478B /* DoricContext.m */; }; DD1DAF6642494A855DAE74D362720651 /* DoricAsyncResult.h in Headers */ = {isa = PBXBuildFile; fileRef = EEB05D1EBAA7E85630CF8F03A39DF5F8 /* DoricAsyncResult.h */; settings = {ATTRIBUTES = (Project, ); }; }; DE7BD11FE70F73948D13DD76D3E2E16C /* DoricJSEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AA81F2935A334697F48CBDB8740D388 /* DoricJSEngine.m */; }; + E26688DE22EF1CCA00B642BF /* DoricBridgeExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = E26688DC22EF1CCA00B642BF /* DoricBridgeExtension.h */; }; + E26688DF22EF1CCA00B642BF /* DoricBridgeExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = E26688DD22EF1CCA00B642BF /* DoricBridgeExtension.m */; }; + E26688E222EF20C800B642BF /* DoricShaderPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = E26688E022EF20C800B642BF /* DoricShaderPlugin.h */; }; + E26688E322EF20C800B642BF /* DoricShaderPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = E26688E122EF20C800B642BF /* DoricShaderPlugin.m */; }; E38E30B01791A73269065FF350CE8F9E /* DoricContextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 836213D547B4CC487A1D695AE45E537D /* DoricContextManager.m */; }; E6B45CF2CBF030A7D3F0B0478A82B2F5 /* DoricModalPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = E6CE2723B5B70C2BEE87FB815A98198D /* DoricModalPlugin.h */; settings = {ATTRIBUTES = (Project, ); }; }; F05E878CFD11812D9A3B4AC60A842A70 /* DoricNativePlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AAD292ADAAA87A469C532D73C91F53F /* DoricNativePlugin.m */; }; @@ -72,8 +76,8 @@ 0D4AE84D8B99C78ADA1D97555B6E0AA6 /* DoricJSEngine.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricJSEngine.h; path = Pod/Classes/DoricJSEngine.h; sourceTree = ""; }; 187C991D10D332CBA27B8131BB835B4D /* DoricModalPlugin.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricModalPlugin.m; path = Pod/Classes/DoricModalPlugin.m; sourceTree = ""; }; 1DC97F881F42239F4D5EE57FE5266B1F /* Pods-ExampleUITests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleUITests-acknowledgements.plist"; sourceTree = ""; }; - 1F667CC0E19EAF34E5A4119E2121F585 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-Example.a"; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 27D9E07AFE355507D16C97DC14384F97 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; path = LICENSE; sourceTree = ""; }; + 1F667CC0E19EAF34E5A4119E2121F585 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 27D9E07AFE355507D16C97DC14384F97 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 35D3ADD1FF0C9A33D86DB110C181048B /* Pods-ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleTests.debug.xcconfig"; sourceTree = ""; }; 370041BF0D7D7ACAE40AD2C204415225 /* DoricAsyncResult.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricAsyncResult.m; path = Pod/Classes/DoricAsyncResult.m; sourceTree = ""; }; 3A9A613917F5AEB180F8DFE148FB29B3 /* DoricRegistry.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricRegistry.h; path = Pod/Classes/DoricRegistry.h; sourceTree = ""; }; @@ -82,9 +86,9 @@ 4CDE936E82BE58F942B70B497594478B /* DoricContext.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricContext.m; path = Pod/Classes/DoricContext.m; sourceTree = ""; }; 50CE420621B9D9ED01E06A8EDBD3E990 /* Pods-ExampleUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-ExampleUITests.release.xcconfig"; sourceTree = ""; }; 57728CFE03A4D88821681C3D55A1FA85 /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.release.xcconfig"; sourceTree = ""; }; - 5955445DDA8D64608454778602A35351 /* doric-lib.js */ = {isa = PBXFileReference; includeInIndex = 1; name = "doric-lib.js"; path = "../js-framework/bundle/doric-lib.js"; sourceTree = ""; }; + 5955445DDA8D64608454778602A35351 /* doric-lib.js */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.javascript; name = "doric-lib.js"; path = "../js-framework/bundle/doric-lib.js"; sourceTree = ""; }; 60EC5610A252BA9DF7184B4E19E11532 /* DoricRegistry.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricRegistry.m; path = Pod/Classes/DoricRegistry.m; sourceTree = ""; }; - 630CABE8F692FCDBFD1B122A2D0CE388 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-ExampleTests.a"; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 630CABE8F692FCDBFD1B122A2D0CE388 /* libPods-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 674AA61D65F8AA0A85296F972EB84840 /* Pods-Example-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-Example-dummy.m"; sourceTree = ""; }; 6AA81F2935A334697F48CBDB8740D388 /* DoricJSEngine.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricJSEngine.m; path = Pod/Classes/DoricJSEngine.m; sourceTree = ""; }; 71A4D70BBB72CFA82515EEF18706137D /* DoricJSCoreExecutor.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricJSCoreExecutor.h; path = Pod/Classes/DoricJSCoreExecutor.h; sourceTree = ""; }; @@ -99,7 +103,7 @@ 9A3426DFFADF2536E625E1F41C102D46 /* DoricConstant.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricConstant.h; path = Pod/Classes/DoricConstant.h; sourceTree = ""; }; 9CF6301AAD07F98FE89F30E7B5A07161 /* Pods-ExampleTests-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-ExampleTests-acknowledgements.plist"; sourceTree = ""; }; 9D82ECD010D50338BFE8FC73B7B396BF /* DoricDriver.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricDriver.m; path = Pod/Classes/DoricDriver.m; sourceTree = ""; }; - 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 9D9C355251F1C95056C0AD3889BA16FB /* Doric-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Doric-dummy.m"; sourceTree = ""; }; 9F5214BB1AD82A72740162D009BB3033 /* DoricDriver.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricDriver.h; path = Pod/Classes/DoricDriver.h; sourceTree = ""; }; A12EA2D6D6F629978F16C0E458152B6E /* Pods-ExampleTests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-ExampleTests-acknowledgements.markdown"; sourceTree = ""; }; @@ -107,22 +111,26 @@ A40ADF15E3DFA8134B77828C29A63223 /* DoricJSExecutorProtocal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricJSExecutorProtocal.h; path = Pod/Classes/DoricJSExecutorProtocal.h; sourceTree = ""; }; B1060ECA09FD9217BD3B163A76A4ED07 /* Doric.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Doric.xcconfig; sourceTree = ""; }; BB9A5DA1337269F5CA470FB0303C1DFB /* DoricJSCoreExecutor.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricJSCoreExecutor.m; path = Pod/Classes/DoricJSCoreExecutor.m; sourceTree = ""; }; - C118B04AAC2A054C315A0037D71775B4 /* Doric.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; path = Doric.podspec; sourceTree = ""; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; - C232398D4E3A40F2337F8A40D7F8D751 /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = "libPods-ExampleUITests.a"; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + C118B04AAC2A054C315A0037D71775B4 /* Doric.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; path = Doric.podspec; sourceTree = ""; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + C232398D4E3A40F2337F8A40D7F8D751 /* libPods-ExampleUITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ExampleUITests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C2FBC49D9D916E1118C72A0CF4EB5DFB /* Doric-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Doric-prefix.pch"; sourceTree = ""; }; - CB6504BD07E3990E6F058E4073421ADA /* libDoric.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libDoric.a; path = libDoric.a; sourceTree = BUILT_PRODUCTS_DIR; }; + CB6504BD07E3990E6F058E4073421ADA /* libDoric.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libDoric.a; sourceTree = BUILT_PRODUCTS_DIR; }; D308B1A3EBD5172711E9710931028210 /* DoricUtil.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricUtil.m; path = Pod/Classes/DoricUtil.m; sourceTree = ""; }; D502FFC8F1F6CAD0438218C3351FCE89 /* DoricContext.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContext.h; path = Pod/Classes/DoricContext.h; sourceTree = ""; }; DE9C1619DD2BF2EB40727BEE4F274563 /* DoricPromise.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricPromise.h; path = Pod/Classes/DoricPromise.h; sourceTree = ""; }; DF85D0F6D5C5A87373DA57643C41DEEF /* DoricPromise.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricPromise.m; path = Pod/Classes/DoricPromise.m; sourceTree = ""; }; DFFAD17E7567EE856A59F246D50A9B0B /* Pods-Example-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-Example-acknowledgements.plist"; sourceTree = ""; }; + E26688DC22EF1CCA00B642BF /* DoricBridgeExtension.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DoricBridgeExtension.h; path = Pod/Classes/DoricBridgeExtension.h; sourceTree = ""; }; + E26688DD22EF1CCA00B642BF /* DoricBridgeExtension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = DoricBridgeExtension.m; path = Pod/Classes/DoricBridgeExtension.m; sourceTree = ""; }; + E26688E022EF20C800B642BF /* DoricShaderPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DoricShaderPlugin.h; path = Pod/Classes/DoricShaderPlugin.h; sourceTree = ""; }; + E26688E122EF20C800B642BF /* DoricShaderPlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = DoricShaderPlugin.m; path = Pod/Classes/DoricShaderPlugin.m; sourceTree = ""; }; E340F908A05867E06E975FDCDD32315C /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-Example.debug.xcconfig"; sourceTree = ""; }; E6CE2723B5B70C2BEE87FB815A98198D /* DoricModalPlugin.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricModalPlugin.h; path = Pod/Classes/DoricModalPlugin.h; sourceTree = ""; }; E7087950EBA89F1C9090E789AE37E3FC /* DoricComponent.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = DoricComponent.m; path = Pod/Classes/DoricComponent.m; sourceTree = ""; }; EADD53921A6F5930D1CFAB4544A0423D /* DoricContextManager.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricContextManager.h; path = Pod/Classes/DoricContextManager.h; sourceTree = ""; }; EEB05D1EBAA7E85630CF8F03A39DF5F8 /* DoricAsyncResult.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricAsyncResult.h; path = Pod/Classes/DoricAsyncResult.h; sourceTree = ""; }; F5B65FC39854121EA72E6D5D158F4C58 /* DoricComponent.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = DoricComponent.h; path = Pod/Classes/DoricComponent.h; sourceTree = ""; }; - F8954C920908870B4AB5D7268B386777 /* doric-sandbox.js */ = {isa = PBXFileReference; includeInIndex = 1; name = "doric-sandbox.js"; path = "../js-framework/bundle/doric-sandbox.js"; sourceTree = ""; }; + F8954C920908870B4AB5D7268B386777 /* doric-sandbox.js */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.javascript; name = "doric-sandbox.js"; path = "../js-framework/bundle/doric-sandbox.js"; sourceTree = ""; }; FE99AB24E829DD35491764E2DED6ED75 /* Pods-ExampleUITests-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-ExampleUITests-dummy.m"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -222,6 +230,10 @@ 4DD5682E7390ADCEDC24AB860E654B03 /* Pod */, 628FE0ECE2D6CC5EEB68FDFC7B8F83B3 /* Resources */, DDBE73454928656D85164075BB584FEB /* Support Files */, + E26688DC22EF1CCA00B642BF /* DoricBridgeExtension.h */, + E26688DD22EF1CCA00B642BF /* DoricBridgeExtension.m */, + E26688E022EF20C800B642BF /* DoricShaderPlugin.h */, + E26688E122EF20C800B642BF /* DoricShaderPlugin.m */, ); name = Doric; path = ../..; @@ -339,9 +351,11 @@ 455ED5C6B2C89EEB909B6604269994A3 /* DoricComponent.h in Headers */, 9B2E635BA24B4C96C85699A83B4A0698 /* DoricConstant.h in Headers */, 9AAFEEC7DAEF1971041D227A4B6BB6B0 /* DoricContext.h in Headers */, + E26688E222EF20C800B642BF /* DoricShaderPlugin.h in Headers */, A616FE47EFBB2A4B0629D9B101AF02A0 /* DoricContextManager.h in Headers */, B5E4694D3D3243AF3FE6D9EF78D76501 /* DoricDriver.h in Headers */, 9451930505ADC63C2B860614A3AB5C1F /* DoricJSCoreExecutor.h in Headers */, + E26688DE22EF1CCA00B642BF /* DoricBridgeExtension.h in Headers */, A69253C685B9486F435DA00B0D74F49C /* DoricJSEngine.h in Headers */, C19CCCC9983463B36493148ADD28B997 /* DoricJSExecutorProtocal.h in Headers */, E6B45CF2CBF030A7D3F0B0478A82B2F5 /* DoricModalPlugin.h in Headers */, @@ -504,8 +518,10 @@ 422DCC3A36D2E500F8EB7657AE96D807 /* DoricModalPlugin.m in Sources */, F05E878CFD11812D9A3B4AC60A842A70 /* DoricNativePlugin.m in Sources */, 6F4D61B7B563DAD837D2EB8B9EAA2600 /* DoricPromise.m in Sources */, + E26688DF22EF1CCA00B642BF /* DoricBridgeExtension.m in Sources */, 6A2989333795DEE250369A3519870480 /* DoricRegistry.m in Sources */, 4370AE1C064A9A78AFFFE9171687885B /* DoricUtil.m in Sources */, + E26688E322EF20C800B642BF /* DoricShaderPlugin.m in Sources */, 701C9FC71418B5CF5097BA01B5C525EE /* UIView+Doric.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/iOS/Pod/Classes/DoricBridgeExtension.h b/iOS/Pod/Classes/DoricBridgeExtension.h new file mode 100644 index 00000000..32db965f --- /dev/null +++ b/iOS/Pod/Classes/DoricBridgeExtension.h @@ -0,0 +1,16 @@ +// +// DoricBridgeExtension.h +// Doric +// +// Created by pengfei.zhou on 2019/7/29. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface DoricBridgeExtension : NSObject +- (id)callNativeWithContextId: (NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument; +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/DoricBridgeExtension.m b/iOS/Pod/Classes/DoricBridgeExtension.m new file mode 100644 index 00000000..f53fde8e --- /dev/null +++ b/iOS/Pod/Classes/DoricBridgeExtension.m @@ -0,0 +1,27 @@ +// +// DoricBridgeExtension.m +// Doric +// +// Created by pengfei.zhou on 2019/7/29. +// + +#import "DoricBridgeExtension.h" +#import "DoricRegistry.h" +#import "DoricContextManager.h" +#import "DoricNativePlugin.h" + +@implementation DoricBridgeExtension + +- (id)callNativeWithContextId:(NSString *)contextId module:(NSString *)module method:(NSString *)method callbackId:(NSString *)callbackId argument:(id)argument { + DoricContext *context = [[DoricContextManager instance] getContext:contextId]; + DoricRegistry *registry = context.driver.registry; + Class pluginClass = [registry acquireNativePlugin:module]; + DoricNativePlugin *nativePlugin = [context.pluginInstanceMap objectForKey:module]; + if(nativePlugin == nil){ + nativePlugin = [[pluginClass alloc] initWithContext:context]; + [context.pluginInstanceMap setObject:nativePlugin forKey:module]; + } + + return nil; +} +@end diff --git a/iOS/Pod/Classes/DoricContext.h b/iOS/Pod/Classes/DoricContext.h index fb9dd871..f10ef6b3 100644 --- a/iOS/Pod/Classes/DoricContext.h +++ b/iOS/Pod/Classes/DoricContext.h @@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic,strong) NSString *contextId; @property (nonatomic,strong) DoricDriver *driver; +@property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source; diff --git a/iOS/Pod/Classes/DoricContext.m b/iOS/Pod/Classes/DoricContext.m index 579e0b54..761a71ac 100644 --- a/iOS/Pod/Classes/DoricContext.m +++ b/iOS/Pod/Classes/DoricContext.m @@ -13,6 +13,7 @@ @implementation DoricContext - (instancetype)initWithScript:(NSString *)script source:(NSString *)source { if(self = [super init]){ _driver = [DoricDriver instance]; + _pluginInstanceMap = [[NSMutableDictionary alloc] init]; [[DoricContextManager instance] createContext:self script:script source:source]; } return self; diff --git a/iOS/Pod/Classes/DoricJSEngine.m b/iOS/Pod/Classes/DoricJSEngine.m index 5f6c47fd..ca99363f 100644 --- a/iOS/Pod/Classes/DoricJSEngine.m +++ b/iOS/Pod/Classes/DoricJSEngine.m @@ -10,10 +10,12 @@ #import "DoricJSCoreExecutor.h" #import "DoricConstant.h" #import "DoricUtil.h" +#import "DoricBridgeExtension.h" @interface DoricJSEngine() @property(nonatomic,strong) id jsExecutor; @property(nonatomic,strong) NSMutableDictionary *timers; +@property(nonatomic,strong) DoricBridgeExtension *bridgeExtension; @end @implementation DoricJSEngine @@ -21,6 +23,7 @@ @implementation DoricJSEngine - (instancetype)init { if(self = [super init]){ _jsQueue = dispatch_queue_create("doric.jsengine", DISPATCH_QUEUE_SERIAL); + _bridgeExtension = [[DoricBridgeExtension alloc] init]; dispatch_async(_jsQueue, ^(){ self.timers = [[NSMutableDictionary alloc] init]; self.jsExecutor = [[DoricJSCoreExecutor alloc] init]; @@ -76,7 +79,10 @@ - (void)initJSExecutor { [self.timers removeObjectForKey:timerId]; } }]; - + + [self.jsExecutor injectGlobalJSObject:INJECT_BRIDGE obj:^(NSString *contextId, NSString *module, NSString *method, NSString *callbackId, id argument){ + return [self.bridgeExtension callNativeWithContextId:contextId module:module method:method callbackId:callbackId argument:argument]; + }]; } - (void)initDoricEnvironment { diff --git a/iOS/Pod/Classes/DoricShaderPlugin.h b/iOS/Pod/Classes/DoricShaderPlugin.h new file mode 100644 index 00000000..34b58565 --- /dev/null +++ b/iOS/Pod/Classes/DoricShaderPlugin.h @@ -0,0 +1,17 @@ +// +// DoricShaderPlugin.h +// Doric +// +// Created by pengfei.zhou on 2019/7/29. +// + +#import +#import "DoricNativePlugin.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DoricShaderPlugin : DoricNativePlugin + +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/DoricShaderPlugin.m b/iOS/Pod/Classes/DoricShaderPlugin.m new file mode 100644 index 00000000..ae7f4fab --- /dev/null +++ b/iOS/Pod/Classes/DoricShaderPlugin.m @@ -0,0 +1,12 @@ +// +// DoricShaderPlugin.m +// Doric +// +// Created by pengfei.zhou on 2019/7/29. +// + +#import "DoricShaderPlugin.h" + +@implementation DoricShaderPlugin + +@end