web head node logic changed

This commit is contained in:
王劲鹏
2020-01-09 19:31:50 +08:00
committed by osborn
parent 7378ce8449
commit 15e292b894
6 changed files with 120 additions and 59 deletions

View File

@@ -3,6 +3,8 @@ import { DVModel, DoricViewNode } from '../shader/DoricViewNode';
import { DoricContext } from '../DoricContext';
export class PopoverPlugin extends DoricPlugin {
static TYPE = "popover"
fullScreen = document.createElement('div')
constructor(context: DoricContext) {
super(context)
@@ -22,7 +24,16 @@ export class PopoverPlugin extends DoricPlugin {
viewNode.init()
viewNode.blend(model.props)
this.fullScreen.appendChild(viewNode.view)
this.context.headNodes.set(model.id, viewNode)
let map = this.context.headNodes.get(PopoverPlugin.TYPE)
if (map) {
map.set(model.id, viewNode)
} else {
map = new Map
map.set(model.id, viewNode)
this.context.headNodes.set(PopoverPlugin.TYPE, map)
}
if (!document.body.contains(this.fullScreen)) {
document.body.appendChild(this.fullScreen)
}
@@ -31,12 +42,16 @@ export class PopoverPlugin extends DoricPlugin {
dismiss(args?: { id: string }) {
if (args) {
const viewNode = this.context.headNodes.get(args.id)
if (viewNode) {
this.fullScreen.removeChild(viewNode.view)
}
if (this.context.headNodes.size === 0) {
document.body.removeChild(this.fullScreen)
let map = this.context.headNodes.get(PopoverPlugin.TYPE)
if (map) {
const viewNode = map.get(args.id)
if (viewNode) {
this.fullScreen.removeChild(viewNode.view)
}
if (map.size === 0) {
document.body.removeChild(this.fullScreen)
}
}
} else {
this.dismissAll()
@@ -44,10 +59,14 @@ export class PopoverPlugin extends DoricPlugin {
return Promise.resolve()
}
dismissAll() {
for (let node of this.context.headNodes.values()) {
this.context.headNodes.delete(node.viewId)
this.fullScreen.removeChild(node.view)
let map = this.context.headNodes.get(PopoverPlugin.TYPE)
if (map) {
for (let node of map.values()) {
map.delete(node.viewId)
this.fullScreen.removeChild(node.view)
}
}
if (document.body.contains(this.fullScreen)) {
document.body.removeChild(this.fullScreen)
}

View File

@@ -7,9 +7,11 @@ export class ShaderPlugin extends DoricPlugin {
if (this.context.rootNode.viewId === ret.id) {
this.context.rootNode.blend(ret.props)
} else {
const viewNode = this.context.headNodes.get(ret.id)
if (viewNode) {
viewNode.blend(ret.props)
for (let map of this.context.headNodes.values()) {
const viewNode = map.get(ret.id)
if (viewNode) {
viewNode.blend(ret.props)
}
}
}
} else {