Doric bridge
This commit is contained in:
@@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)createContext:(DoricContext *)context script:(NSString *)script source:(NSString *)source;
|
||||
|
||||
- (void)destroyContext:(DoricContext *)context;
|
||||
|
||||
- (DoricContext *)getContext:(NSString *)contextId;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -44,6 +44,14 @@ - (void)createContext:(DoricContext *)context script:(NSString *)script source:(
|
||||
});
|
||||
}
|
||||
|
||||
- (DoricContext *)getContext:(NSString *)contextId {
|
||||
__block DoricContext *context;
|
||||
dispatch_sync(self.mapQueue, ^{
|
||||
NSValue *value = [self.doricContextMap valueForKey:contextId];
|
||||
context = value.nonretainedObjectValue;
|
||||
});
|
||||
return context;
|
||||
}
|
||||
|
||||
- (void)destroyContext:(DoricContext *)context {
|
||||
NSString *contextId = context.contextId;
|
||||
|
16
iOS/Pod/Classes/DoricModalPlugin.h
Normal file
16
iOS/Pod/Classes/DoricModalPlugin.h
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// DoricModalPlugin.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricModalPlugin : DoricNativePlugin
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
20
iOS/Pod/Classes/DoricModalPlugin.m
Normal file
20
iOS/Pod/Classes/DoricModalPlugin.m
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// DoricModalPlugin.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricModalPlugin.h"
|
||||
#import "DoricRegistry.h"
|
||||
|
||||
|
||||
@implementation DoricModalPlugin
|
||||
|
||||
- (void)toast:(NSString *)message promise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSLog(@"toast:%@",message);
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
@@ -7,6 +7,9 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricComponent.h"
|
||||
#import "DoricPromise.h"
|
||||
#import "DoricRegistry.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricNativePlugin : DoricComponent
|
||||
|
21
iOS/Pod/Classes/DoricPromise.h
Normal file
21
iOS/Pod/Classes/DoricPromise.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// DoricPromise.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricContext.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricPromise : NSObject
|
||||
- (instancetype)initWithContext: (DoricContext *)context callbackId:(NSString *)callbackId;
|
||||
|
||||
- (void)resolve:(id) result;
|
||||
|
||||
- (void)reject:(id) result;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
34
iOS/Pod/Classes/DoricPromise.m
Normal file
34
iOS/Pod/Classes/DoricPromise.m
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// DoricPromise.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricPromise.h"
|
||||
#import "DoricConstant.h"
|
||||
|
||||
@interface DoricPromise()
|
||||
@property (nonatomic,strong) DoricContext *context;
|
||||
@property (nonatomic,strong) NSString *callbackId;
|
||||
|
||||
@end
|
||||
|
||||
@implementation DoricPromise
|
||||
|
||||
- (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId {
|
||||
if(self = [super init]){
|
||||
_context = context;
|
||||
_callbackId = callbackId;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)resolve:(id)result {
|
||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE,self.context.contextId,self.callbackId,result,nil];
|
||||
}
|
||||
|
||||
- (void)reject:(id)result {
|
||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT,self.context.contextId,self.callbackId,result,nil];
|
||||
}
|
||||
@end
|
@@ -11,7 +11,14 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricRegistry : NSObject
|
||||
|
||||
- (NSString *)acquireJSBundle:(NSString *)bundleName;
|
||||
- (NSString *)acquireJSBundle:(NSString *)name;
|
||||
|
||||
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name;
|
||||
|
||||
|
||||
- (void)registerNativePlugin:(Class)pluginClass withName:(NSString *)name;
|
||||
|
||||
- (Class)acquireNativePlugin:(NSString *)name;
|
||||
|
||||
@end
|
||||
|
||||
|
@@ -6,7 +6,45 @@
|
||||
//
|
||||
|
||||
#import "DoricRegistry.h"
|
||||
#import "DoricModalPlugin.h"
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@interface DoricRegistry ()
|
||||
|
||||
@property (nonatomic,strong) NSMutableDictionary *bundles;
|
||||
@property (nonatomic,strong) NSMutableDictionary *plugins;
|
||||
|
||||
@end
|
||||
|
||||
@implementation DoricRegistry
|
||||
|
||||
- (instancetype)init {
|
||||
if(self = [super init]){
|
||||
_bundles = [[NSMutableDictionary alloc] init];
|
||||
_plugins = [[NSMutableDictionary alloc] init];
|
||||
[self innerRegister];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)innerRegister {
|
||||
[self registerNativePlugin:DoricModalPlugin.class withName:@"modal"];
|
||||
}
|
||||
|
||||
- (void)registerJSBundle:(NSString *)bundle withName:(NSString *)name {
|
||||
[self.bundles setObject:bundle forKey:name];
|
||||
}
|
||||
|
||||
- (NSString *)acquireJSBundle:(NSString *)name {
|
||||
return [self.bundles objectForKey:name];
|
||||
}
|
||||
|
||||
- (void)registerNativePlugin:(Class)pluginClass withName:(NSString *)name {
|
||||
[self.plugins setObject:pluginClass forKey:name];
|
||||
}
|
||||
|
||||
- (Class)acquireNativePlugin:(NSString *)name {
|
||||
return [self.plugins objectForKey:name];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user