feat:add Popover and supoort headViews for iOS

This commit is contained in:
pengfei.zhou
2019-11-28 19:57:36 +08:00
parent a04dcf2212
commit 38a06c9658
8 changed files with 111 additions and 5 deletions

View File

@@ -0,0 +1,9 @@
//
// Created by pengfei.zhou on 2019/11/28.
//
#import <Foundation/Foundation.h>
#import "DoricNativePlugin.h"
@interface DoricPopoverPlugin : DoricNativePlugin
@end

View File

@@ -0,0 +1,54 @@
//
// Created by pengfei.zhou on 2019/11/28.
//
#import "DoricPopoverPlugin.h"
#import "DoricRootNode.h"
#import "Doric.h"
@interface DoricPopoverPlugin ()
@property(nonatomic, strong) DoricRootNode *popoverNode;
@property(nonatomic, strong) UIView *fullScreenView;
@end
@implementation DoricPopoverPlugin
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *superView = [UIApplication sharedApplication].windows.lastObject;
if (!self.fullScreenView) {
self.fullScreenView = [[DoricStackView new] also:^(UIView *it) {
it.width = superView.width;
it.height = superView.height;
it.top = it.left = 0;
[superView addSubview:self.fullScreenView];
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];
}
[self.popoverNode render:params[@"props"]];
[promise resolve:nil];
});
}
- (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissPopover];
[promise resolve:nil];
});
}
- (void)dismissPopover {
self.popoverNode.view.hidden = YES;
self.fullScreenView.hidden = YES;
[self.popoverNode.view.subviews forEach:^(__kindof UIView *obj) {
[obj removeFromSuperview];
}];
}
@end

View File

@@ -43,6 +43,15 @@ - (void)render:(NSDictionary *)argument {
});
}
- (DoricViewNode *)headViewNodeByViewId:(NSString *)viewId {
for (DoricViewNode *node in self.doricContext.headNodes) {
if ([viewId isEqualToString:node.viewId]) {
return node;
}
}
return self.doricContext.rootNode;
}
- (id)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
NSArray *viewIds = argument[@"viewIds"];
id args = argument[@"args"];
@@ -50,7 +59,7 @@ - (id)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
DoricViewNode *viewNode = nil;
for (NSString *viewId in viewIds) {
if (!viewNode) {
viewNode = self.doricContext.rootNode;
viewNode = [self headViewNodeByViewId:viewId];
} else {
if ([viewNode isKindOfClass:[DoricSuperNode class]]) {
viewNode = [((DoricSuperNode *) viewNode) subNodeWithViewId:viewId];