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 (this.headviews.has(type)) {
let map = this.headviews.get(type);
if (map) {
if (v instanceof View) { if (v instanceof View) {
this.headviews.delete(v.viewId); map.delete(v.viewId);
} }
else { else {
this.headviews.delete(v); map.delete(v);
} }
} }
clearHeadViews() { }
this.headviews.clear(); }
clearHeadViews(type) {
if (this.headviews.has(type)) {
this.headviews.delete(type);
}
} }
getRootView() { getRootView() {
return this.__root__; return this.__root__;
@ -2259,11 +2274,13 @@ 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()) {
for (let v of map.values()) {
v.clean(); v.clean();
} }
} }
} }
}
hookAfterNativeCall() { hookAfterNativeCall() {
if (Environment.platform !== 'h5') { if (Environment.platform !== 'h5') {
//Here insert a native call to ensure the promise is resolved done. //Here insert a native call to ensure the promise is resolved done.
@ -2272,13 +2289,15 @@ 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()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
} }
} }
} }
}
else { else {
Promise.resolve().then(() => { Promise.resolve().then(() => {
if (this.__root__.isDirty()) { if (this.__root__.isDirty()) {
@ -2286,13 +2305,15 @@ 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()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
this.nativeRender(model); this.nativeRender(model);
v.clean(); 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,7 +3587,8 @@ function animate(context) {
root.clean(); root.clean();
return ret; return ret;
} }
for (let v of panel.allHeadViews()) { for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) { if (v.isDirty()) {
const model = v.toModel(); const model = v.toModel();
const ret = it.animateRender(model); const ret = it.animateRender(model);
@ -3574,6 +3596,7 @@ function animate(context) {
return ret; return ret;
} }
} }
}
throw new Error('Cannot find any animated elements'); throw new Error('Cannot find any animated elements');
}); });
}); });
@ -3777,12 +3800,14 @@ 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()) {
const viewNode = map.get(ret.id);
if (viewNode) { if (viewNode) {
viewNode.blend(ret.props); viewNode.blend(ret.props);
} }
} }
} }
}
else { else {
this.context.rootNode.viewId = ret.id; this.context.rootNode.viewId = ret.id;
this.context.rootNode.blend(ret.props); this.context.rootNode.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,24 +4749,30 @@ 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 (map) {
const viewNode = map.get(args.id);
if (viewNode) { if (viewNode) {
this.fullScreen.removeChild(viewNode.view); this.fullScreen.removeChild(viewNode.view);
} }
if (this.context.headNodes.size === 0) { if (map.size === 0) {
document.body.removeChild(this.fullScreen); document.body.removeChild(this.fullScreen);
} }
} }
}
else { else {
this.dismissAll(); this.dismissAll();
} }
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) {
for (let node of map.values()) {
map.delete(node.viewId);
this.fullScreen.removeChild(node.view); 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,23 +42,31 @@ 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 (map) {
const viewNode = map.get(args.id)
if (viewNode) { if (viewNode) {
this.fullScreen.removeChild(viewNode.view) this.fullScreen.removeChild(viewNode.view)
} }
if (this.context.headNodes.size === 0) {
if (map.size === 0) {
document.body.removeChild(this.fullScreen) document.body.removeChild(this.fullScreen)
} }
}
} else { } else {
this.dismissAll() this.dismissAll()
} }
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) {
for (let node of map.values()) {
map.delete(node.viewId)
this.fullScreen.removeChild(node.view) 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,11 +7,13 @@ 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()) {
const viewNode = map.get(ret.id)
if (viewNode) { if (viewNode) {
viewNode.blend(ret.props) viewNode.blend(ret.props)
} }
} }
}
} else { } else {
this.context.rootNode.viewId = ret.id this.context.rootNode.viewId = ret.id
this.context.rootNode.blend(ret.props) this.context.rootNode.blend(ret.props)