feat:add Popover demo
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#import "Doric.h"
|
||||
|
||||
@interface DoricPopoverPlugin ()
|
||||
@property(nonatomic, strong) DoricRootNode *popoverNode;
|
||||
@property(nonatomic, strong) DoricViewNode *popoverNode;
|
||||
@property(nonatomic, strong) UIView *fullScreenView;
|
||||
@end
|
||||
|
||||
@@ -20,19 +20,26 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||
it.width = superView.width;
|
||||
it.height = superView.height;
|
||||
it.top = it.left = 0;
|
||||
[superView addSubview:self.fullScreenView];
|
||||
[superView addSubview:it];
|
||||
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPopover)];
|
||||
[it addGestureRecognizer:gestureRecognizer];
|
||||
}];
|
||||
}
|
||||
[superView bringSubviewToFront:self.fullScreenView];
|
||||
self.fullScreenView.hidden = NO;
|
||||
if (!self.popoverNode) {
|
||||
self.popoverNode = [[DoricRootNode alloc] initWithContext:self.doricContext];
|
||||
DoricStackView *view = [[DoricStackView alloc] initWithFrame:self.fullScreenView.frame];
|
||||
[self.popoverNode setupRootView:view];
|
||||
if (self.popoverNode) {
|
||||
[self dismissPopover];
|
||||
}
|
||||
[self.popoverNode render:params[@"props"]];
|
||||
self.fullScreenView.hidden = NO;
|
||||
NSString *viewId = params[@"id"];
|
||||
NSString *type = params[@"type"];
|
||||
self.popoverNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||
it.viewId = viewId;
|
||||
[it initWithSuperNode:nil];
|
||||
it.view.layoutConfig = [DoricLayoutConfig new];
|
||||
[it blend:params[@"props"]];
|
||||
[self.fullScreenView addSubview:it.view];
|
||||
[self.doricContext.headNodes addObject:it];
|
||||
}];
|
||||
[promise resolve:nil];
|
||||
});
|
||||
}
|
||||
@@ -45,10 +52,12 @@ - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||
}
|
||||
|
||||
- (void)dismissPopover {
|
||||
[self.doricContext.headNodes removeObject:self.popoverNode];
|
||||
self.popoverNode.view.hidden = YES;
|
||||
self.fullScreenView.hidden = YES;
|
||||
[self.popoverNode.view.subviews forEach:^(__kindof UIView *obj) {
|
||||
[obj removeFromSuperview];
|
||||
}];
|
||||
self.popoverNode = nil;
|
||||
}
|
||||
@end
|
||||
@end
|
||||
|
@@ -36,10 +36,15 @@ - (void)render:(NSDictionary *)argument {
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__strong typeof(_self) self = _self;
|
||||
[self.doricContext.rootNode also:^(DoricRootNode *it) {
|
||||
it.viewId = argument[@"id"];
|
||||
[it render:argument[@"props"]];
|
||||
}];
|
||||
|
||||
NSString *viewId = argument[@"id"];
|
||||
if ([self.doricContext.rootNode.viewId isEqualToString:viewId]) {
|
||||
[self.doricContext.rootNode render:argument[@"props"]];
|
||||
} else {
|
||||
DoricViewNode *viewNode = [self headViewNodeByViewId:viewId];
|
||||
[viewNode blend:argument[@"props"]];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,6 +54,7 @@ - (DoricViewNode *)headViewNodeByViewId:(NSString *)viewId {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
self.doricContext.rootNode.viewId = viewId;
|
||||
return self.doricContext.rootNode;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user