feat:add Popover and supoort headViews for iOS
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class DoricViewNode;
|
||||
@class DoricRootNode;
|
||||
|
||||
@interface DoricContext : NSObject
|
||||
@@ -35,10 +36,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property(nonatomic, strong) NSString *contextId;
|
||||
@property(nonatomic, strong) DoricDriver *driver;
|
||||
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
||||
@property(nonatomic, strong) DoricRootNode *rootNode;
|
||||
@property(nonatomic, strong) NSString *source;
|
||||
@property(nonatomic, strong) NSString *script;;
|
||||
@property(nonatomic, strong) NSMutableDictionary *initialParams;
|
||||
@property(nonatomic, strong) DoricRootNode *rootNode;
|
||||
@property(nonatomic, strong) NSMutableSet <DoricViewNode *> *headNodes;
|
||||
|
||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source;
|
||||
|
||||
|
@@ -31,9 +31,12 @@ @implementation DoricContext
|
||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
|
||||
if (self = [super init]) {
|
||||
_driver = [DoricDriver instance];
|
||||
_pluginInstanceMap = [[NSMutableDictionary alloc] init];
|
||||
_pluginInstanceMap = [NSMutableDictionary new];
|
||||
[[DoricContextManager instance] createContext:self script:script source:source];
|
||||
_rootNode = [[DoricRootNode alloc] initWithContext:self];
|
||||
_headNodes = [NSMutableSet new];
|
||||
DoricRootNode *rootNode = [[DoricRootNode alloc] initWithContext:self];
|
||||
_rootNode = rootNode;
|
||||
[self.headNodes addObject:rootNode];
|
||||
_script = script;
|
||||
_source = source;
|
||||
_initialParams = [@{@"width": @(0), @"height": @(0)} mutableCopy];
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#import "DoricRefreshableNode.h"
|
||||
#import "DoricFlowLayoutItemNode.h"
|
||||
#import "DoricFlowLayoutNode.h"
|
||||
#import "DoricPopoverPlugin.h"
|
||||
|
||||
@interface DoricRegistry ()
|
||||
|
||||
@@ -68,6 +69,7 @@ - (void)innerRegister {
|
||||
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
||||
[self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"];
|
||||
[self registerNativePlugin:DoricNavBarPlugin.class withName:@"navbar"];
|
||||
[self registerNativePlugin:DoricPopoverPlugin.class withName:@"popover"];
|
||||
|
||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
||||
|
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