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) NSString *script;;
@property(nonatomic, strong) NSMutableDictionary *initialParams; @property(nonatomic, strong) NSMutableDictionary *initialParams;
@property(nonatomic, strong) DoricRootNode *rootNode; @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; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source;

View File

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

View File

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