feat:add Popover and supoort headViews for iOS
This commit is contained in:
parent
a04dcf2212
commit
38a06c9658
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class DoricViewNode;
|
||||||
@class DoricRootNode;
|
@class DoricRootNode;
|
||||||
|
|
||||||
@interface DoricContext : NSObject
|
@interface DoricContext : NSObject
|
||||||
@ -35,10 +36,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@property(nonatomic, strong) NSString *contextId;
|
@property(nonatomic, strong) NSString *contextId;
|
||||||
@property(nonatomic, strong) DoricDriver *driver;
|
@property(nonatomic, strong) DoricDriver *driver;
|
||||||
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
||||||
@property(nonatomic, strong) DoricRootNode *rootNode;
|
|
||||||
@property(nonatomic, strong) NSString *source;
|
@property(nonatomic, strong) NSString *source;
|
||||||
@property(nonatomic, strong) NSString *script;;
|
@property(nonatomic, strong) NSString *script;;
|
||||||
@property(nonatomic, strong) NSMutableDictionary *initialParams;
|
@property(nonatomic, strong) NSMutableDictionary *initialParams;
|
||||||
|
@property(nonatomic, strong) DoricRootNode *rootNode;
|
||||||
|
@property(nonatomic, strong) NSMutableSet <DoricViewNode *> *headNodes;
|
||||||
|
|
||||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source;
|
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source;
|
||||||
|
|
||||||
|
@ -31,9 +31,12 @@ @implementation DoricContext
|
|||||||
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
|
- (instancetype)initWithScript:(NSString *)script source:(NSString *)source {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_driver = [DoricDriver instance];
|
_driver = [DoricDriver instance];
|
||||||
_pluginInstanceMap = [[NSMutableDictionary alloc] init];
|
_pluginInstanceMap = [NSMutableDictionary new];
|
||||||
[[DoricContextManager instance] createContext:self script:script source:source];
|
[[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;
|
_script = script;
|
||||||
_source = source;
|
_source = source;
|
||||||
_initialParams = [@{@"width": @(0), @"height": @(0)} mutableCopy];
|
_initialParams = [@{@"width": @(0), @"height": @(0)} mutableCopy];
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#import "DoricRefreshableNode.h"
|
#import "DoricRefreshableNode.h"
|
||||||
#import "DoricFlowLayoutItemNode.h"
|
#import "DoricFlowLayoutItemNode.h"
|
||||||
#import "DoricFlowLayoutNode.h"
|
#import "DoricFlowLayoutNode.h"
|
||||||
|
#import "DoricPopoverPlugin.h"
|
||||||
|
|
||||||
@interface DoricRegistry ()
|
@interface DoricRegistry ()
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ - (void)innerRegister {
|
|||||||
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
[self registerNativePlugin:DoricStoragePlugin.class withName:@"storage"];
|
||||||
[self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"];
|
[self registerNativePlugin:DoricNavigatorPlugin.class withName:@"navigator"];
|
||||||
[self registerNativePlugin:DoricNavBarPlugin.class withName:@"navbar"];
|
[self registerNativePlugin:DoricNavBarPlugin.class withName:@"navbar"];
|
||||||
|
[self registerNativePlugin:DoricPopoverPlugin.class withName:@"popover"];
|
||||||
|
|
||||||
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
[self registerViewNode:DoricStackNode.class withName:@"Stack"];
|
||||||
[self registerViewNode:DoricVLayoutNode.class withName:@"VLayout"];
|
[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 {
|
- (id)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||||
NSArray *viewIds = argument[@"viewIds"];
|
NSArray *viewIds = argument[@"viewIds"];
|
||||||
id args = argument[@"args"];
|
id args = argument[@"args"];
|
||||||
@ -50,7 +59,7 @@ - (id)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
|||||||
DoricViewNode *viewNode = nil;
|
DoricViewNode *viewNode = nil;
|
||||||
for (NSString *viewId in viewIds) {
|
for (NSString *viewId in viewIds) {
|
||||||
if (!viewNode) {
|
if (!viewNode) {
|
||||||
viewNode = self.doricContext.rootNode;
|
viewNode = [self headViewNodeByViewId:viewId];
|
||||||
} else {
|
} else {
|
||||||
if ([viewNode isKindOfClass:[DoricSuperNode class]]) {
|
if ([viewNode isKindOfClass:[DoricSuperNode class]]) {
|
||||||
viewNode = [((DoricSuperNode *) viewNode) subNodeWithViewId:viewId];
|
viewNode = [((DoricSuperNode *) viewNode) subNodeWithViewId:viewId];
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright [2019] [Doric.Pub]
|
* Copyright [2019] [Doric.Pub]
|
||||||
*
|
*
|
||||||
|
28
js-framework/src/native/popover.ts
Normal file
28
js-framework/src/native/popover.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright [2019] [Doric.Pub]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
import { BridgeContext } from "../runtime/global"
|
||||||
|
import { View } from "../ui/view"
|
||||||
|
|
||||||
|
export function popover(context: BridgeContext) {
|
||||||
|
return {
|
||||||
|
show: (view: View) => {
|
||||||
|
return context.popover.show(view)
|
||||||
|
},
|
||||||
|
dismiss: () => {
|
||||||
|
return context.popover.dismiss()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user