add some api for doric context
This commit is contained in:
parent
1ddbfcf8e4
commit
ba2a90a6c1
@ -9,7 +9,6 @@ import com.github.penfeizhou.doric.Doric;
|
|||||||
import com.github.penfeizhou.doric.DoricContext;
|
import com.github.penfeizhou.doric.DoricContext;
|
||||||
import com.github.penfeizhou.doric.dev.LocalServer;
|
import com.github.penfeizhou.doric.dev.LocalServer;
|
||||||
import com.github.penfeizhou.doric.utils.DoricUtils;
|
import com.github.penfeizhou.doric.utils.DoricUtils;
|
||||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ - (void)viewDidLoad {
|
|||||||
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
||||||
self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"Snake"];
|
self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"Snake"];
|
||||||
self.doricContext.rootNode.view = self.view;
|
self.doricContext.rootNode.view = self.view;
|
||||||
[self.doricContext callEntity:@"__init__",@{@"width": [NSNumber numberWithFloat:self.view.width],
|
[self.doricContext initContextWithWidth:self.view.width height:self.view.height];
|
||||||
@"height":[NSNumber numberWithFloat:self.view.height]},nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@property (nonatomic,strong) DoricDriver *driver;
|
@property (nonatomic,strong) DoricDriver *driver;
|
||||||
@property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap;
|
@property (nonatomic,strong) NSMutableDictionary *pluginInstanceMap;
|
||||||
@property (nonatomic,strong) DoricRootNode *rootNode;
|
@property (nonatomic,strong) DoricRootNode *rootNode;
|
||||||
|
@property (nonatomic,strong) NSString *source;
|
||||||
|
@property (nonatomic,strong) NSString *script;;
|
||||||
|
@property (nonatomic,strong) NSDictionary *initialParams;
|
||||||
|
|
||||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source;
|
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source;
|
||||||
|
|
||||||
@ -27,6 +30,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args;
|
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args;
|
||||||
|
|
||||||
|
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height;
|
||||||
|
|
||||||
|
- (void)reload:(NSString *)script;
|
||||||
|
|
||||||
|
- (void)onShow;
|
||||||
|
|
||||||
|
- (void)onHidden;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#import "DoricContext.h"
|
#import "DoricContext.h"
|
||||||
#import "DoricContextManager.h"
|
#import "DoricContextManager.h"
|
||||||
#import "DoricRootNode.h"
|
#import "DoricRootNode.h"
|
||||||
|
#import "DoricConstant.h"
|
||||||
|
|
||||||
@implementation DoricContext
|
@implementation DoricContext
|
||||||
|
|
||||||
@ -17,11 +18,16 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
|
|||||||
_pluginInstanceMap = [[NSMutableDictionary alloc] init];
|
_pluginInstanceMap = [[NSMutableDictionary alloc] init];
|
||||||
[[DoricContextManager instance] createContext:self script:script source:source];
|
[[DoricContextManager instance] createContext:self script:script source:source];
|
||||||
_rootNode = [[DoricRootNode alloc] initWithContext:self];
|
_rootNode = [[DoricRootNode alloc] initWithContext:self];
|
||||||
|
_script = script;
|
||||||
|
_source = source;
|
||||||
|
_initialParams =[@{@"width":@(LAYOUT_MATCH_PARENT) ,@"height":@(LAYOUT_MATCH_PARENT)} mutableCopy];
|
||||||
|
[self callEntity:DORIC_ENTITY_CREATE,nil];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
|
[self callEntity:DORIC_ENTITY_DESTROY,nil];
|
||||||
[[DoricContextManager instance] destroyContext:self];
|
[[DoricContextManager instance] destroyContext:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +42,29 @@ - (DoricAsyncResult *)callEntity:(NSString *)method, ... {
|
|||||||
- (DoricAsyncResult *)callEntity:(NSString *)method withArguments:(va_list)args {
|
- (DoricAsyncResult *)callEntity:(NSString *)method withArguments:(va_list)args {
|
||||||
return [self.driver invokeContextEntity:self.contextId method:method arguments:args];
|
return [self.driver invokeContextEntity:self.contextId method:method arguments:args];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args {
|
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args {
|
||||||
return [self.driver invokeContextEntity:self.contextId method:method argumentsArray:args];
|
return [self.driver invokeContextEntity:self.contextId method:method argumentsArray:args];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height {
|
||||||
|
[self.initialParams setValue:@(width) forKey:@"width"];
|
||||||
|
[self.initialParams setValue:@(height) forKey:@"height"];
|
||||||
|
[self callEntity:DORIC_ENTITY_INIT,self.initialParams,nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)reload:(NSString *)script {
|
||||||
|
self.script = script;
|
||||||
|
[self.driver createContext:self.contextId script:script source:self.source];
|
||||||
|
[self callEntity:DORIC_ENTITY_INIT,self.initialParams,nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)onShow {
|
||||||
|
[self callEntity:DORIC_ENTITY_SHOW,nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)onHidden {
|
||||||
|
[self callEntity:DORIC_ENTITY_HIDDEN,nil];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -37,3 +37,13 @@ extern NSString * const DORIC_BRIDGE_RESOLVE;
|
|||||||
extern NSString * const DORIC_BRIDGE_REJECT;
|
extern NSString * const DORIC_BRIDGE_REJECT;
|
||||||
|
|
||||||
extern NSString * const DORIC_ENTITY_RESPONSE;
|
extern NSString * const DORIC_ENTITY_RESPONSE;
|
||||||
|
|
||||||
|
extern NSString * const DORIC_ENTITY_INIT;
|
||||||
|
|
||||||
|
extern NSString * const DORIC_ENTITY_CREATE;
|
||||||
|
|
||||||
|
extern NSString * const DORIC_ENTITY_DESTROY;
|
||||||
|
|
||||||
|
extern NSString * const DORIC_ENTITY_SHOW;
|
||||||
|
|
||||||
|
extern NSString * const DORIC_ENTITY_HIDDEN;
|
||||||
|
@ -54,3 +54,13 @@
|
|||||||
NSString * const DORIC_BRIDGE_REJECT = @"jsCallReject";
|
NSString * const DORIC_BRIDGE_REJECT = @"jsCallReject";
|
||||||
|
|
||||||
NSString * const DORIC_ENTITY_RESPONSE = @"__response__";
|
NSString * const DORIC_ENTITY_RESPONSE = @"__response__";
|
||||||
|
|
||||||
|
NSString * const DORIC_ENTITY_INIT = @"__init__";
|
||||||
|
|
||||||
|
NSString * const DORIC_ENTITY_CREATE = @"__onCreate__";
|
||||||
|
|
||||||
|
NSString * const DORIC_ENTITY_DESTROY = @"__onDestroy__";
|
||||||
|
|
||||||
|
NSString * const DORIC_ENTITY_SHOW = @"__onShow__";
|
||||||
|
|
||||||
|
NSString * const DORIC_ENTITY_HIDDEN = @"__onHidden__";
|
||||||
|
Reference in New Issue
Block a user