feat:HeadNodes use Dictionary instead of set

This commit is contained in:
pengfei.zhou 2019-11-29 09:43:14 +08:00
parent 35d377f9b9
commit c0eae0f8a2
3 changed files with 6 additions and 11 deletions

View File

@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong) NSString *script;;
@property(nonatomic, strong) NSMutableDictionary *initialParams;
@property(nonatomic, strong) DoricRootNode *rootNode;
@property(nonatomic, strong) NSMutableSet <DoricViewNode *> *headNodes;
@property(nonatomic, strong) NSMutableDictionary <NSString *, DoricViewNode *> *headNodes;
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source;

View File

@ -33,7 +33,7 @@ - (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
_driver = [DoricDriver instance];
_pluginInstanceMap = [NSMutableDictionary new];
[[DoricContextManager instance] createContext:self script:script source:source];
_headNodes = [NSMutableSet new];
_headNodes = [NSMutableDictionary new];
DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:self];
_rootNode = rootNode;
_script = script;
@ -48,12 +48,7 @@ - (DoricViewNode *)targetViewNode:(NSString *)viewId {
if ([self.rootNode.viewId isEqualToString:viewId]) {
return self.rootNode;
} else {
for (DoricViewNode *node in self.headNodes) {
if ([viewId isEqualToString:node.viewId]) {
return node;
}
}
return nil;
return self.headNodes[viewId];
}
}

View File

@ -33,7 +33,7 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
[it initWithSuperNode:nil];
it.view.layoutConfig = [DoricLayoutConfig new];
[self.fullScreenView addSubview:it.view];
[self.doricContext.headNodes addObject:it];
self.doricContext.headNodes[viewId] = it;
}];
}
[viewNode blend:params[@"props"]];
@ -55,7 +55,7 @@ - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
}
- (void)dismissViewNode:(DoricViewNode *)node {
[self.doricContext.headNodes removeObject:node];
[self.doricContext.headNodes removeObjectForKey:node.viewId];
[node.view removeFromSuperview];
if (self.doricContext.headNodes.count == 0) {
self.fullScreenView.hidden = YES;
@ -63,7 +63,7 @@ - (void)dismissViewNode:(DoricViewNode *)node {
}
- (void)dismissPopover {
for (DoricViewNode *node in self.doricContext.headNodes) {
for (DoricViewNode *node in self.doricContext.headNodes.allValues) {
[self dismissViewNode:node];
}
}