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;
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#import "DoricLayouts.h"
|
||||
#import "UIView+Doric.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@class DoricSuperNode;
|
||||
|
||||
@interface DoricViewNode <V:UIView *> : DoricContextHolder
|
||||
@@ -55,5 +54,3 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)requestLayout;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -126,6 +126,8 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
||||
} else if ([name isEqualToString:@"layoutConfig"]) {
|
||||
if (self.superNode && [prop isKindOfClass:[NSDictionary class]]) {
|
||||
[self.superNode blendSubNode:self layoutConfig:prop];
|
||||
} else {
|
||||
[self blendLayoutConfig:prop];
|
||||
}
|
||||
} else if ([name isEqualToString:@"onClick"]) {
|
||||
self.callbackIds[@"onClick"] = prop;
|
||||
@@ -246,4 +248,36 @@ - (NSNumber *)getRotation {
|
||||
return @(degree);
|
||||
}
|
||||
|
||||
- (void)blendLayoutConfig:(NSDictionary *)params {
|
||||
[params[@"widthSpec"] also:^(NSNumber *it) {
|
||||
if (it) {
|
||||
self.layoutConfig.widthSpec = (DoricLayoutSpec) [it integerValue];
|
||||
}
|
||||
}];
|
||||
|
||||
[params[@"heightSpec"] also:^(NSNumber *it) {
|
||||
if (it) {
|
||||
self.layoutConfig.heightSpec = (DoricLayoutSpec) [it integerValue];
|
||||
}
|
||||
}];
|
||||
|
||||
NSDictionary *margin = params[@"margin"];
|
||||
if (margin) {
|
||||
self.layoutConfig.margin = DoricMarginMake(
|
||||
[(NSNumber *) margin[@"left"] floatValue],
|
||||
[(NSNumber *) margin[@"top"] floatValue],
|
||||
[(NSNumber *) margin[@"right"] floatValue],
|
||||
[(NSNumber *) margin[@"bottom"] floatValue]);
|
||||
}
|
||||
|
||||
NSNumber *alignment = params[@"alignment"];
|
||||
if (alignment) {
|
||||
self.layoutConfig.alignment = (DoricGravity) [alignment integerValue];
|
||||
}
|
||||
NSNumber *weight = params[@"weight"];
|
||||
if (weight) {
|
||||
self.layoutConfig.weight = (DoricGravity) [weight integerValue];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user