iOS head node logic changed

This commit is contained in:
王劲鹏 2020-01-09 19:00:53 +08:00 committed by osborn
parent 9a77578b9b
commit 7378ce8449
3 changed files with 21 additions and 6 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) NSMutableDictionary <NSString *, DoricViewNode *> *headNodes; @property(nonatomic, strong) NSMutableDictionary <NSString *, NSMutableDictionary <NSString *, DoricViewNode *> *> *headNodes;
@property(nonatomic, copy) NSString *extra; @property(nonatomic, copy) NSString *extra;
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra; - (instancetype)initWithScript:(NSString *)script source:(NSString *)source extra:(NSString *)extra;

View File

@ -49,9 +49,14 @@ - (DoricViewNode *)targetViewNode:(NSString *)viewId {
if ([self.rootNode.viewId isEqualToString:viewId]) { if ([self.rootNode.viewId isEqualToString:viewId]) {
return self.rootNode; return self.rootNode;
} else { } else {
return self.headNodes[viewId]; for (NSMutableDictionary <NSString *, DoricViewNode *> *map in self.headNodes.allValues) {
if ([[map allKeys] containsObject:viewId]) {
return map[viewId];
} }
} }
}
return nil;
}
- (void)dealloc { - (void)dealloc {
[self callEntity:DORIC_ENTITY_DESTROY, nil]; [self callEntity:DORIC_ENTITY_DESTROY, nil];

View File

@ -11,6 +11,8 @@ @interface DoricPopoverPlugin ()
@end @end
@implementation DoricPopoverPlugin @implementation DoricPopoverPlugin
static NSString *TYPE = @"popover";
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise { - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
UIView *superView = [UIApplication sharedApplication].windows.lastObject; UIView *superView = [UIApplication sharedApplication].windows.lastObject;
@ -33,7 +35,15 @@ - (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[viewId] = it;
NSMutableDictionary <NSString *, DoricViewNode *> *map = self.doricContext.headNodes[TYPE];
if (map != nil) {
self.doricContext.headNodes[TYPE][viewId] = it;
} else {
map = [[NSMutableDictionary alloc] init];
map[viewId] = it;
self.doricContext.headNodes[TYPE] = map;
}
}]; }];
} }
[viewNode blend:params[@"props"]]; [viewNode blend:params[@"props"]];
@ -55,15 +65,15 @@ - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
} }
- (void)dismissViewNode:(DoricViewNode *)node { - (void)dismissViewNode:(DoricViewNode *)node {
[self.doricContext.headNodes removeObjectForKey:node.viewId]; [self.doricContext.headNodes[TYPE] removeObjectForKey:node.viewId];
[node.view removeFromSuperview]; [node.view removeFromSuperview];
if (self.doricContext.headNodes.count == 0) { if (self.doricContext.headNodes[TYPE].count == 0) {
self.fullScreenView.hidden = YES; self.fullScreenView.hidden = YES;
} }
} }
- (void)dismissPopover { - (void)dismissPopover {
for (DoricViewNode *node in self.doricContext.headNodes.allValues) { for (DoricViewNode *node in self.doricContext.headNodes[TYPE].allValues) {
[self dismissViewNode:node]; [self dismissViewNode:node];
} }
} }