feat:adjust the inject timing of panel's initData

This commit is contained in:
pengfei.zhou
2020-03-19 13:35:04 +08:00
committed by osborn
parent 08454d53ea
commit 2b62e8bd3b
18 changed files with 87 additions and 65 deletions

View File

@@ -51,7 +51,9 @@ NS_ASSUME_NONNULL_BEGIN
- (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray *)args;
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height;
- (void)build:(CGSize)size;
- (void)init:(NSString *)initData;
- (void)reload:(NSString *)script;

View File

@@ -36,11 +36,11 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source extr
_script = script;
_source = source;
_initialParams = [@{@"width": @(0), @"height": @(0)} mutableCopy];
_extra = extra;
[[DoricContextManager instance] createContext:self script:script source:source];
_headNodes = [NSMutableDictionary new];
DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:self];
_rootNode = rootNode;
[self init:extra];
[self callEntity:DORIC_ENTITY_CREATE, nil];
}
return self;
@@ -80,20 +80,28 @@ - (DoricAsyncResult *)callEntity:(NSString *)method withArgumentsArray:(NSArray
return [self.driver invokeContextEntity:self.contextId method:method argumentsArray:args];
}
- (void)initContextWithWidth:(CGFloat)width height:(CGFloat)height {
- (void)init:(NSString *)initData {
self.extra = initData;
if (initData) {
[self callEntity:DORIC_ENTITY_INIT, initData, nil];
}
}
- (void)build:(CGSize)size {
[self.initialParams also:^(NSMutableDictionary *it) {
it[@"width"] = @(width);
it[@"height"] = @(height);
it[@"width"] = @(size.width);
it[@"height"] = @(size.height);
}];
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, self.extra, nil];
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
}
- (void)reload:(NSString *)script {
self.rootNode.viewId = nil;
self.script = script;
[self.driver createContext:self.contextId script:script source:self.source];
[self init:self.extra];
[self callEntity:DORIC_ENTITY_CREATE, nil];
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, self.extra, nil];
[self callEntity:DORIC_ENTITY_BUILD, self.initialParams, nil];
[self onShow];
}

View File

@@ -44,7 +44,7 @@ - (void)viewWillLayoutSubviews {
if (self.doricContext && self.renderedWidth != self.view.width && self.renderedHeight != self.view.height) {
self.renderedWidth = self.view.width;
self.renderedHeight = self.view.height;
[self.doricContext initContextWithWidth:self.renderedWidth height:self.renderedHeight];
[self.doricContext build:CGSizeMake(self.renderedWidth, self.renderedHeight)];
} else {
[self.doricContext.rootNode.view also:^(DoricStackView *it) {
if (it.width != self.renderedWidth || it.height != self.renderedHeight) {

View File

@@ -63,3 +63,5 @@ extern NSString *const DORIC_ENTITY_DESTROY;
extern NSString *const DORIC_ENTITY_SHOW;
extern NSString *const DORIC_ENTITY_HIDDEN;
extern NSString *const DORIC_ENTITY_BUILD;

View File

@@ -81,3 +81,5 @@
NSString *const DORIC_ENTITY_SHOW = @"__onShow__";
NSString *const DORIC_ENTITY_HIDDEN = @"__onHidden__";
NSString *const DORIC_ENTITY_BUILD = @"__build__";