feat:add Popover and supoort headViews for iOS
This commit is contained in:
9
iOS/Pod/Classes/Plugin/DoricPopoverPlugin.h
Normal file
9
iOS/Pod/Classes/Plugin/DoricPopoverPlugin.h
Normal file
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/28.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricPopoverPlugin : DoricNativePlugin
|
||||
@end
|
54
iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m
Normal file
54
iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m
Normal 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
|
@@ -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];
|
||||
|
Reference in New Issue
Block a user