feat:add Popover demo
This commit is contained in:
parent
38a06c9658
commit
a79e288679
@ -14,4 +14,5 @@ export default [
|
|||||||
'src/NavbarDemo',
|
'src/NavbarDemo',
|
||||||
'src/RefreshableDemo',
|
'src/RefreshableDemo',
|
||||||
'src/FlowLayoutDemo',
|
'src/FlowLayoutDemo',
|
||||||
|
'src/PopoverDemo'
|
||||||
]
|
]
|
46
demo/src/PopoverDemo.ts
Normal file
46
demo/src/PopoverDemo.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { Group, Panel, popover, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, modal, IText, network } from "doric";
|
||||||
|
import { title, label, colors } from "./utils";
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
class PopoverDemo extends Panel {
|
||||||
|
build(rootView: Group): void {
|
||||||
|
scroller(vlayout([
|
||||||
|
title("Popover Demo"),
|
||||||
|
label('Popover').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly(),
|
||||||
|
onClick: () => {
|
||||||
|
popover(context).show(text({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly().a(Gravity.Center),
|
||||||
|
text: "This is PopOver Window",
|
||||||
|
onClick: () => {
|
||||||
|
modal(context).toast('Dismissed after 3 seconds')
|
||||||
|
setTimeout(() => {
|
||||||
|
popover(context).dismiss()
|
||||||
|
}, 3000)
|
||||||
|
},
|
||||||
|
}).also(v => {
|
||||||
|
let idx = 0
|
||||||
|
v.onClick = () => {
|
||||||
|
v.bgColor = colors[(++idx) % colors.length]
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} as IText),
|
||||||
|
]).apply({
|
||||||
|
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||||
|
gravity: gravity().center(),
|
||||||
|
space: 10,
|
||||||
|
} as IVLayout)).apply({
|
||||||
|
layoutConfig: layoutConfig().atmost(),
|
||||||
|
}).in(rootView)
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
#import "Doric.h"
|
#import "Doric.h"
|
||||||
|
|
||||||
@interface DoricPopoverPlugin ()
|
@interface DoricPopoverPlugin ()
|
||||||
@property(nonatomic, strong) DoricRootNode *popoverNode;
|
@property(nonatomic, strong) DoricViewNode *popoverNode;
|
||||||
@property(nonatomic, strong) UIView *fullScreenView;
|
@property(nonatomic, strong) UIView *fullScreenView;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -20,19 +20,26 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
it.width = superView.width;
|
it.width = superView.width;
|
||||||
it.height = superView.height;
|
it.height = superView.height;
|
||||||
it.top = it.left = 0;
|
it.top = it.left = 0;
|
||||||
[superView addSubview:self.fullScreenView];
|
[superView addSubview:it];
|
||||||
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPopover)];
|
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissPopover)];
|
||||||
[it addGestureRecognizer:gestureRecognizer];
|
[it addGestureRecognizer:gestureRecognizer];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
[superView bringSubviewToFront:self.fullScreenView];
|
[superView bringSubviewToFront:self.fullScreenView];
|
||||||
self.fullScreenView.hidden = NO;
|
if (self.popoverNode) {
|
||||||
if (!self.popoverNode) {
|
[self dismissPopover];
|
||||||
self.popoverNode = [[DoricRootNode alloc] initWithContext:self.doricContext];
|
|
||||||
DoricStackView *view = [[DoricStackView alloc] initWithFrame:self.fullScreenView.frame];
|
|
||||||
[self.popoverNode setupRootView:view];
|
|
||||||
}
|
}
|
||||||
[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];
|
[promise resolve:nil];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -45,10 +52,12 @@ - (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dismissPopover {
|
- (void)dismissPopover {
|
||||||
|
[self.doricContext.headNodes removeObject:self.popoverNode];
|
||||||
self.popoverNode.view.hidden = YES;
|
self.popoverNode.view.hidden = YES;
|
||||||
self.fullScreenView.hidden = YES;
|
self.fullScreenView.hidden = YES;
|
||||||
[self.popoverNode.view.subviews forEach:^(__kindof UIView *obj) {
|
[self.popoverNode.view.subviews forEach:^(__kindof UIView *obj) {
|
||||||
[obj removeFromSuperview];
|
[obj removeFromSuperview];
|
||||||
}];
|
}];
|
||||||
|
self.popoverNode = nil;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -36,10 +36,15 @@ - (void)render:(NSDictionary *)argument {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
[self.doricContext.rootNode also:^(DoricRootNode *it) {
|
|
||||||
it.viewId = argument[@"id"];
|
NSString *viewId = argument[@"id"];
|
||||||
[it render:argument[@"props"]];
|
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;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.doricContext.rootNode.viewId = viewId;
|
||||||
return self.doricContext.rootNode;
|
return self.doricContext.rootNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#import "DoricLayouts.h"
|
#import "DoricLayouts.h"
|
||||||
#import "UIView+Doric.h"
|
#import "UIView+Doric.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
|
||||||
@class DoricSuperNode;
|
@class DoricSuperNode;
|
||||||
|
|
||||||
@interface DoricViewNode <V:UIView *> : DoricContextHolder
|
@interface DoricViewNode <V:UIView *> : DoricContextHolder
|
||||||
@ -55,5 +54,3 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
- (void)requestLayout;
|
- (void)requestLayout;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
|
||||||
|
@ -126,6 +126,8 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
|||||||
} else if ([name isEqualToString:@"layoutConfig"]) {
|
} else if ([name isEqualToString:@"layoutConfig"]) {
|
||||||
if (self.superNode && [prop isKindOfClass:[NSDictionary class]]) {
|
if (self.superNode && [prop isKindOfClass:[NSDictionary class]]) {
|
||||||
[self.superNode blendSubNode:self layoutConfig:prop];
|
[self.superNode blendSubNode:self layoutConfig:prop];
|
||||||
|
} else {
|
||||||
|
[self blendLayoutConfig:prop];
|
||||||
}
|
}
|
||||||
} else if ([name isEqualToString:@"onClick"]) {
|
} else if ([name isEqualToString:@"onClick"]) {
|
||||||
self.callbackIds[@"onClick"] = prop;
|
self.callbackIds[@"onClick"] = prop;
|
||||||
@ -246,4 +248,36 @@ - (NSNumber *)getRotation {
|
|||||||
return @(degree);
|
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
|
@end
|
||||||
|
@ -18,3 +18,4 @@ export * from './navbar'
|
|||||||
export * from './navigator'
|
export * from './navigator'
|
||||||
export * from './network'
|
export * from './network'
|
||||||
export * from './storage'
|
export * from './storage'
|
||||||
|
export * from './popover'
|
||||||
|
@ -15,13 +15,25 @@
|
|||||||
*/
|
*/
|
||||||
import { BridgeContext } from "../runtime/global"
|
import { BridgeContext } from "../runtime/global"
|
||||||
import { View } from "../ui/view"
|
import { View } from "../ui/view"
|
||||||
|
import { Panel } from "../ui/panel"
|
||||||
|
|
||||||
export function popover(context: BridgeContext) {
|
export function popover(context: BridgeContext) {
|
||||||
|
const entity = context.entity
|
||||||
|
let panel: Panel | undefined = undefined
|
||||||
|
if (entity instanceof Panel) {
|
||||||
|
panel = entity
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
show: (view: View) => {
|
show: (view: View) => {
|
||||||
return context.popover.show(view)
|
if (panel) {
|
||||||
|
panel.addHeadView(view)
|
||||||
|
}
|
||||||
|
return context.popover.show(view.toModel())
|
||||||
},
|
},
|
||||||
dismiss: () => {
|
dismiss: (view: View | undefined = undefined) => {
|
||||||
|
if (panel && view) {
|
||||||
|
panel.removeHeadView(view)
|
||||||
|
}
|
||||||
return context.popover.dismiss()
|
return context.popover.dismiss()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -137,15 +137,19 @@ export abstract class Panel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private hookBeforeNativeCall() {
|
private hookBeforeNativeCall() {
|
||||||
this.__root__.clean()
|
for (let v of this.headviews.values()) {
|
||||||
|
v.clean()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private hookAfterNativeCall() {
|
private hookAfterNativeCall() {
|
||||||
//Here insert a native call to ensure the promise is resolved done.
|
//Here insert a native call to ensure the promise is resolved done.
|
||||||
nativeEmpty()
|
nativeEmpty()
|
||||||
if (this.__root__.isDirty()) {
|
for (let v of this.headviews.values()) {
|
||||||
const model = this.__root__.toModel()
|
if (v.isDirty()) {
|
||||||
this.nativeRender(model)
|
const model = v.toModel()
|
||||||
|
this.nativeRender(model)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user