Commit f47787a2 authored by 李维's avatar 李维

去掉unmounted钩子,增加beforeDestory钩子

parent 2850ef80
......@@ -240,14 +240,12 @@ export default class HomePageClass extends PageComponentBaseClass {
}
async mounted() {
console.log("mounted")
await this.getUserInfo();
await this.getCourseList();
this.initTopUserPanel();
}
async unmounted(data: any) {
console.log("unmounted")
async beforeDestroy() {
this.SvContent.removeAllChildren();
}
// update (dt) {}
......
......@@ -65,7 +65,7 @@ export default class UnitPageClass extends PageComponentBaseClass {
// 页面隐藏
isDestroy = false;
async unmounted() {
async beforeDestroy() {
const content = this.svContent;
const sv = this.unitScrollView.getComponent(cc.ScrollView);
this.unitScrollView.off("scrolling");
......
......@@ -23,14 +23,14 @@ export default class PageComponentBaseClass extends cc.Component {
node.on("beforeMount", (data)=>this.beforeMount(data));
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
node.on("mounted", (data)=>this.mounted(data));
// 注册PageViwer发来的unmounted事件 [页面已经切换完毕]
node.on("unmounted", (data)=>this.unmounted(data));
}
// 页面即将被显示
beforeMount(data) {}
mounted(data) {}
unmounted(data) {}
// 页面即将被销毁
beforeDestroy() {}
// 设置页面数据
setPageRouterData(currentValue, newValue) {
......
......@@ -211,7 +211,6 @@ export default class PageViewerClass extends cc.Component {
})
.call(() => {
outPage.active = false;
outPage.emit("unmounted");
this.destroyPage(outPage);
resovle(true);
})
......@@ -237,7 +236,6 @@ export default class PageViewerClass extends cc.Component {
})
.call(() => {
outPage.active = false;
outPage.emit("unmounted");
this.destroyPage(outPage);
resovle(true);
})
......@@ -246,7 +244,6 @@ export default class PageViewerClass extends cc.Component {
} else {
if (outPage) {
outPage.active = false;
outPage.emit("unmounted");
this.destroyPage(outPage);
} else {
// 未传移除页面 则全部移除
......@@ -269,6 +266,9 @@ export default class PageViewerClass extends cc.Component {
}
destroyPage(node) {
const script = node.getComponent(node.name)
script && script.beforeDestroy && script.beforeDestroy();
node.removeFromParent();
node.destroy();
this.releaseAssets();
......@@ -303,7 +303,7 @@ export default class PageViewerClass extends cc.Component {
this.runGC();
this.courseBackViewName = viewName;
this[PageMap[viewName]].active = false;
this[PageMap[viewName]].emit("unmounted");
this.destroyPage(this[PageMap[viewName]])
}
courseClose() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment