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

@ -2177,22 +2177,37 @@ class Panel {
onDestroy() { } onDestroy() { }
onShow() { } onShow() { }
onHidden() { } onHidden() { }
addHeadView(v) { addHeadView(type, v) {
this.headviews.set(v.viewId, v); let map = this.headviews.get(type);
if (map) {
map.set(v.viewId, v);
}
else {
map = new Map;
map.set(v.viewId, v);
this.headviews.set(type, map);
}
} }
allHeadViews() { allHeadViews() {
return this.headviews.values(); return this.headviews.values();
} }
removeHeadView(v) { removeHeadView(type, v) {
if (v instanceof View) { if (this.headviews.has(type)) {
this.headviews.delete(v.viewId); let map = this.headviews.get(type);
} if (map) {
else { if (v instanceof View) {
this.headviews.delete(v); map.delete(v.viewId);
}
else {
map.delete(v);
}
}
} }
} }
clearHeadViews() { clearHeadViews(type) {
this.headviews.clear(); if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -2259,8 +2274,10 @@ class Panel {
hookBeforeNativeCall() { hookBeforeNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
this.__root__.clean(); this.__root__.clean();
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
v.clean(); for (let v of map.values()) {
v.clean();
}
} }
} }
} }
@ -2272,10 +2289,12 @@ class Panel {
const model = this.__root__.toModel(); const model = this.__root__.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
this.nativeRender(model);
}
} }
} }
} }
@ -2286,11 +2305,13 @@ class Panel {
this.nativeRender(model); this.nativeRender(model);
this.__root__.clean(); this.__root__.clean();
} }
for (let v of this.headviews.values()) { for (let map of this.headviews.values()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
this.nativeRender(model); const model = v.toModel();
v.clean(); this.nativeRender(model);
v.clean();
}
} }
} }
}); });
@ -3450,17 +3471,17 @@ function popover(context) {
return { return {
show: (view) => { show: (view) => {
if (panel) { if (panel) {
panel.addHeadView(view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.popover.show(view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
if (view) { if (view) {
panel.removeHeadView(view); panel.removeHeadView("popover", view);
} }
else { else {
panel.clearHeadViews(); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.popover.dismiss(view ? { id: view.viewId } : undefined);
@ -3566,12 +3587,14 @@ function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
if (v.isDirty()) { for (let v of map.values()) {
const model = v.toModel(); if (v.isDirty()) {
const ret = it.animateRender(model); const model = v.toModel();
it.clean(); const ret = it.animateRender(model);
return ret; it.clean();
return ret;
}
} }
} }
throw new Error('Cannot find any animated elements'); throw new Error('Cannot find any animated elements');
@ -3777,9 +3800,11 @@ var doric_web = (function (exports, axios, sandbox) {
this.context.rootNode.blend(ret.props); this.context.rootNode.blend(ret.props);
} }
else { else {
const viewNode = this.context.headNodes.get(ret.id); for (let map of this.context.headNodes.values()) {
if (viewNode) { const viewNode = map.get(ret.id);
viewNode.blend(ret.props); if (viewNode) {
viewNode.blend(ret.props);
}
} }
} }
} }
@ -4708,7 +4733,15 @@ var doric_web = (function (exports, axios, sandbox) {
viewNode.init(); viewNode.init();
viewNode.blend(model.props); viewNode.blend(model.props);
this.fullScreen.appendChild(viewNode.view); 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)) { if (!document.body.contains(this.fullScreen)) {
document.body.appendChild(this.fullScreen); document.body.appendChild(this.fullScreen);
} }
@ -4716,12 +4749,15 @@ var doric_web = (function (exports, axios, sandbox) {
} }
dismiss(args) { dismiss(args) {
if (args) { if (args) {
const viewNode = this.context.headNodes.get(args.id); let map = this.context.headNodes.get(PopoverPlugin.TYPE);
if (viewNode) { if (map) {
this.fullScreen.removeChild(viewNode.view); const viewNode = map.get(args.id);
} if (viewNode) {
if (this.context.headNodes.size === 0) { this.fullScreen.removeChild(viewNode.view);
document.body.removeChild(this.fullScreen); }
if (map.size === 0) {
document.body.removeChild(this.fullScreen);
}
} }
} }
else { else {
@ -4730,9 +4766,12 @@ var doric_web = (function (exports, axios, sandbox) {
return Promise.resolve(); return Promise.resolve();
} }
dismissAll() { dismissAll() {
for (let node of this.context.headNodes.values()) { let map = this.context.headNodes.get(PopoverPlugin.TYPE);
this.context.headNodes.delete(node.viewId); if (map) {
this.fullScreen.removeChild(node.view); for (let node of map.values()) {
map.delete(node.viewId);
this.fullScreen.removeChild(node.view);
}
} }
if (document.body.contains(this.fullScreen)) { if (document.body.contains(this.fullScreen)) {
document.body.removeChild(this.fullScreen); document.body.removeChild(this.fullScreen);
@ -4743,6 +4782,7 @@ var doric_web = (function (exports, axios, sandbox) {
this.dismissAll(); this.dismissAll();
} }
} }
PopoverPlugin.TYPE = "popover";
class DoricListItemNode extends DoricStackNode { class DoricListItemNode extends DoricStackNode {
} }

File diff suppressed because one or more lines are too long

View File

@ -24,7 +24,7 @@
点击返回 点击返回
</h2> </h2>
</div> </div>
<doric-div src="../doric-demo/bundle/src/DraggableDemo.js" alias="test"> <doric-div src="../doric-demo/bundle/src/PopoverDemo.js" alias="test">
</doric-div> </doric-div>
</doric-navigation> </doric-navigation>
<script type="text/javascript" src="./dist/index.js"></script> <script type="text/javascript" src="./dist/index.js"></script>

View File

@ -19,7 +19,7 @@ export class DoricContext {
contextId = getContextId() contextId = getContextId()
pluginInstances: Map<string, DoricPlugin> = new Map pluginInstances: Map<string, DoricPlugin> = new Map
rootNode: DoricStackNode rootNode: DoricStackNode
headNodes: Map<string, DoricViewNode> = new Map headNodes: Map<string, Map<string, DoricViewNode>> = new Map
constructor(content: string) { constructor(content: string) {
createContext(this.contextId, content) createContext(this.contextId, content)

View File

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