This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m

85 lines
2.9 KiB
Mathematica
Raw Normal View History

//
// Created by pengfei.zhou on 2019/11/28.
//
#import "DoricPopoverPlugin.h"
#import "DoricRootNode.h"
#import "Doric.h"
@interface DoricPopoverPlugin ()
@property(nonatomic, strong) UIView *fullScreenView;
@end
@implementation DoricPopoverPlugin
2020-01-09 19:00:53 +08:00
static NSString *TYPE = @"popover";
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *superView = self.doricContext.vc.view;
if (!self.fullScreenView) {
2020-04-03 16:36:43 +08:00
self.fullScreenView = [[UIView new] also:^(UIView *it) {
it.width = superView.width;
it.height = superView.height;
it.top = it.left = 0;
2020-04-08 16:16:57 +08:00
it.doricLayout.layoutType = DoricStack;
2019-11-28 21:04:27 +08:00
[superView addSubview:it];
}];
} else {
self.fullScreenView.doricLayout.width = superView.width;
self.fullScreenView.doricLayout.height = superView.height;
}
[superView bringSubviewToFront:self.fullScreenView];
2019-11-28 21:04:27 +08:00
self.fullScreenView.hidden = NO;
NSString *viewId = params[@"id"];
NSString *type = params[@"type"];
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
if (!viewNode) {
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
it.viewId = viewId;
[it initWithSuperNode:nil];
[self.fullScreenView addSubview:it.view];
2020-04-08 16:16:57 +08:00
2020-01-09 19:00:53 +08:00
NSMutableDictionary <NSString *, DoricViewNode *> *map = self.doricContext.headNodes[TYPE];
if (map != nil) {
2020-04-08 16:16:57 +08:00
self.doricContext.headNodes[TYPE][viewId] = it;
2020-01-09 19:00:53 +08:00
} else {
map = [[NSMutableDictionary alloc] init];
map[viewId] = it;
self.doricContext.headNodes[TYPE] = map;
}
}];
}
[viewNode blend:params[@"props"]];
2020-04-08 16:16:57 +08:00
[self.fullScreenView.doricLayout apply];
[promise resolve:nil];
});
}
- (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
NSString *viewId = params[@"id"];
dispatch_async(dispatch_get_main_queue(), ^{
if (viewId) {
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
[self dismissViewNode:viewNode];
} else {
[self dismissPopover];
}
[promise resolve:nil];
});
}
- (void)dismissViewNode:(DoricViewNode *)node {
2020-01-09 19:00:53 +08:00
[self.doricContext.headNodes[TYPE] removeObjectForKey:node.viewId];
[node.view removeFromSuperview];
2020-01-09 19:00:53 +08:00
if (self.doricContext.headNodes[TYPE].count == 0) {
self.fullScreenView.hidden = YES;
}
}
- (void)dismissPopover {
2020-01-09 19:00:53 +08:00
for (DoricViewNode *node in self.doricContext.headNodes[TYPE].allValues) {
[self dismissViewNode:node];
}
}
2019-11-28 21:04:27 +08:00
@end