2019-07-25 21:03:31 +08:00
|
|
|
//
|
|
|
|
// DoricContext.m
|
|
|
|
// Doric
|
|
|
|
//
|
|
|
|
// Created by pengfei.zhou on 2019/7/25.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DoricContext.h"
|
2019-07-29 13:48:27 +08:00
|
|
|
#import "DoricContextManager.h"
|
2019-07-31 14:18:20 +08:00
|
|
|
#import "DoricRootNode.h"
|
2019-08-13 18:13:54 +08:00
|
|
|
#import "DoricConstant.h"
|
2019-07-25 21:03:31 +08:00
|
|
|
|
|
|
|
@implementation DoricContext
|
|
|
|
|
2019-07-29 14:51:35 +08:00
|
|
|
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
|
2019-10-12 14:48:19 +08:00
|
|
|
if (self = [super init]) {
|
2019-07-29 13:48:27 +08:00
|
|
|
_driver = [DoricDriver instance];
|
2019-07-29 20:51:53 +08:00
|
|
|
_pluginInstanceMap = [[NSMutableDictionary alloc] init];
|
2019-07-29 14:51:35 +08:00
|
|
|
[[DoricContextManager instance] createContext:self script:script source:source];
|
2019-07-31 14:18:20 +08:00
|
|
|
_rootNode = [[DoricRootNode alloc] initWithContext:self];
|
2019-08-13 18:13:54 +08:00
|
|
|
_script = script;
|
|
|
|
_source = source;
|
2019-10-12 14:48:19 +08:00
|
|
|
_initialParams = [@{@"width": @(LAYOUT_MATCH_PARENT), @"height": @(LAYOUT_MATCH_PARENT)} mutableCopy];
|
|
|
|
[self callEntity:DORIC_ENTITY_CREATE, nil];
|
2019-07-29 13:48:27 +08:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2019-10-12 14:48:19 +08:00
|
|
|
[self callEntity:DORIC_ENTITY_DESTROY, nil];
|
2019-07-29 13:48:27 +08:00
|
|
|
[[DoricContextManager instance] destroyContext:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (DoricAsyncResult *)callEntity:(NSString *)method, ... {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, method);
|
|
|
|
DoricAsyncResult *ret = [self.driver invokeContextEntity:self.contextId method:method arguments:args];
|
|
|
|
va_end(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-07-30 21:05:27 +08:00
|
|
|
- (DoricAsyncResult *)callEntity:(NSString *)method withArguments:(va_list)args {
|
|
|
|
return [self.driver invokeContextEntity:self.contextId method:method arguments:args];
|
|
|
|
}
|
2019-08-13 18:13:54 +08:00
|
|
|
|
2019-07-30 21:05:27 +08:00
|
|
|
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args {
|
|
|
|
return [self.driver invokeContextEntity:self.contextId method:method argumentsArray:args];
|
|
|
|
}
|
2019-08-13 18:13:54 +08:00
|
|
|
|
|
|
|
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height {
|
|
|
|
[self.initialParams setValue:@(width) forKey:@"width"];
|
|
|
|
[self.initialParams setValue:@(height) forKey:@"height"];
|
2019-10-12 14:48:19 +08:00
|
|
|
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, nil];
|
2019-08-13 18:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)reload:(NSString *)script {
|
|
|
|
self.script = script;
|
|
|
|
[self.driver createContext:self.contextId script:script source:self.source];
|
2019-10-12 14:48:19 +08:00
|
|
|
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, nil];
|
2019-08-13 18:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)onShow {
|
2019-10-12 14:48:19 +08:00
|
|
|
[self callEntity:DORIC_ENTITY_SHOW, nil];
|
2019-08-13 18:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)onHidden {
|
2019-10-12 14:48:19 +08:00
|
|
|
[self callEntity:DORIC_ENTITY_HIDDEN, nil];
|
2019-08-13 18:13:54 +08:00
|
|
|
}
|
|
|
|
|
2019-07-25 21:03:31 +08:00
|
|
|
@end
|