Doric Bridge
This commit is contained in:
16
iOS/Pod/Classes/DoricBridgeExtension.h
Normal file
16
iOS/Pod/Classes/DoricBridgeExtension.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// DoricBridgeExtension.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
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
|
27
iOS/Pod/Classes/DoricBridgeExtension.m
Normal file
27
iOS/Pod/Classes/DoricBridgeExtension.m
Normal file
@@ -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
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -10,10 +10,12 @@
|
||||
#import "DoricJSCoreExecutor.h"
|
||||
#import "DoricConstant.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricBridgeExtension.h"
|
||||
|
||||
@interface DoricJSEngine()
|
||||
@property(nonatomic,strong) id<DoricJSExecutorProtocal> 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 {
|
||||
|
17
iOS/Pod/Classes/DoricShaderPlugin.h
Normal file
17
iOS/Pod/Classes/DoricShaderPlugin.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// DoricShaderPlugin.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricShaderPlugin : DoricNativePlugin
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
12
iOS/Pod/Classes/DoricShaderPlugin.m
Normal file
12
iOS/Pod/Classes/DoricShaderPlugin.m
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// DoricShaderPlugin.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricShaderPlugin.h"
|
||||
|
||||
@implementation DoricShaderPlugin
|
||||
|
||||
@end
|
Reference in New Issue
Block a user