Commit e74ed763 authored by 李维's avatar 李维

优化单元Item加载卡顿的问题

parent 5a57b63f
{
"ver": "1.1.0",
"uuid": "0f8f392f-32f6-44d4-a812-2c422c86f4df",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "70909523-db85-4efd-b77d-bbc2cfb2ca88",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.0",
"uuid": "b5e998fd-17de-4c57-8da6-9d61b68ad0e9",
"subMetas": {}
}
\ No newline at end of file
......@@ -14819,7 +14819,7 @@
{
"__type__": "cc.Node",
"_name": "content",
"_objFlags": 512,
"_objFlags": 0,
"_parent": {
"__id__": 326
},
......@@ -14857,7 +14857,7 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
-960,
0,
0,
0,
......
......@@ -182,6 +182,7 @@ export default class PageViewerClass extends cc.Component {
})
.call(() => {
outPage.active = false;
outPage.emit("unmounted")
resovle(true)
})
.start();
......@@ -206,6 +207,7 @@ export default class PageViewerClass extends cc.Component {
})
.call(() => {
outPage.active = false;
outPage.emit("unmounted")
resovle(true)
})
.start();
......@@ -213,9 +215,13 @@ export default class PageViewerClass extends cc.Component {
} else {
if(outPage) {
outPage.active = false;
outPage.emit("unmounted")
} else {
// 未传移除页面 则全部移除
this.justShowView("")
for(let key in PageMap) {
this[PageMap[key]].active = false;
this[PageMap[key]].emit("unmounted");
}
}
inPage.active = true;
inPage.x = 0;
......@@ -227,17 +233,5 @@ export default class PageViewerClass extends cc.Component {
})
}
}
justShowView(viewName) {
this.loginPage.active = viewName == "loginPage"
this.homePage.active = viewName == "homePage"
this.libraryPage.active = viewName == "libraryPage"
this.libraryReadPage.active = viewName == "libraryReadPage"
this.libraryAudioPage.active = viewName == "libraryAudioPage"
this.libraryVideoPage.active = viewName == "libraryVideoPage"
this.libraryReadDetailPage.active = viewName == "libraryReadDetailPage"
this.unitPage.active = viewName == "unitPage"
this.missionPage.active = viewName == "missionPage"
}
// update (dt) {}
}
......@@ -50,9 +50,12 @@ export default class UnitPageClass extends cc.Component {
this.node.on("beforeMounted", this.beforeMounted.bind(this));
// 注册PageViwer发来的mounted事件 [页面已经切换完毕]
this.node.on("mounted", this.mounted.bind(this));
// 注册PageViwer发来的unmounted事件 [页面已经切换完毕]
this.node.on("unmounted", this.unmounted.bind(this));
}
async beforeMounted() {
this.isDestory = false;
const svNode = this.unitScrollView;
const sv = svNode.getComponent(cc.ScrollView);
const content = sv.content;
......@@ -64,6 +67,12 @@ export default class UnitPageClass extends cc.Component {
await this.initView();
}
// 页面切换走
isDestory = false;
async unmounted() {
this.isDestory = true;
}
async initView() {
this.loading.active = true;
this.initTitle();
......@@ -168,9 +177,10 @@ export default class UnitPageClass extends cc.Component {
}
configData = []
configData = [];
allListItemNodes = [];
async initUnitListView() {
this.allListItemNodes = [];
const svNode = this.unitScrollView;
svNode.opacity = 0;
const n1Date = new Date()
......@@ -210,20 +220,18 @@ export default class UnitPageClass extends cc.Component {
const nowDate = new Date();
const sv = svNode.getComponent(cc.ScrollView);
const itemArr = this.getUnitItemDataArr(rows, sv);
this.allListItemNodes = itemArr;
// this.initScrollViewItem(sv, itemArr, 1);
this.getUnitItemDataArr(rows, sv);
const time = new Date() - nowDate
console.log("创建节点时间: ", time)
const content = sv.content;
const canvas = cc.find("Canvas");
if (content.width > canvas.width) {
content.x = -canvas.width / 2;
} else {
content.x = -content.width / 2;
}
// const content = sv.content;
// const canvas = cc.find("Canvas");
// if (content.width > canvas.width) {
// content.x = -canvas.width / 2;
// } else {
// content.x = -content.width / 2;
// }
svNode.opacity = 255;
this.refreshConfig()
}
......@@ -238,7 +246,7 @@ export default class UnitPageClass extends cc.Component {
}
listItem;
getUnitItemDataArr(dataArr, sv) {
async getUnitItemDataArr(dataArr, sv) {
const content = sv.content;
content.removeAllChildren();
......@@ -259,20 +267,21 @@ export default class UnitPageClass extends cc.Component {
const disX = 530;
let lastX = 0;
for (let j = 0; j < subArr.length; j++) {
// 此方法为异步方法,防止页面切换走以后仍然执行,在这里判断一下是否页面已经切换走
if(this.isDestory) {
break
}
const subNode = cc.instantiate(subItem)
subNode.x = baseX + j * disX;
subNode.y = baseY;
itemNode.addChild(subNode);
lastX = subNode.x;
const subData = subArr[j];
getSprNodeByUrl(subData.cover, (spr) => {
const sprNode = spr.node;
const picLayer = cc.find("mask/pic_frame", subNode);
picLayer.addChild(sprNode);
setSprNodeMaxLen(sprNode, picLayer.width, picLayer.height, true);
})
......@@ -336,50 +345,18 @@ export default class UnitPageClass extends cc.Component {
}, 1);
// }
itemArr.push(itemNode);
itemNode.parent = content
this.allListItemNodes.push(itemNode);
itemNode.parent = content;
// 默认显示前3个节点
if (i < 3) {
itemArr[i].opacity = 255;
}
await asyncDelay(0.1)
}
return itemArr;
}
initScrollViewItem(sv, itemArr, row = 1) {
sv.scrollToTop();
const content = sv.content;
content.width = sv.node.width;
content.height = sv.node.height;
content.removeAllChildren();
const tempH = content.height / row;
const disY = tempH * 0.95;
const baseY = (row - 1) * 0.5 * disY;
let rowCount = 0;
const disX = 40;
let colCount = 0;
let lastX = 0;
for (let i = 0; i < itemArr.length; i++) {
const item = itemArr[i];
// 默认显示前3个节点
if (i < 3) {
itemArr[i].opacity = 255;
}
item.x = lastX + disX;
item.y = baseY - rowCount * disY;
lastX = item.x + item.width * item.scale;
content.addChild(itemArr[i]);
itemArr[i].parent = content
const tempW = Math.abs(item.x + disX + item.width / 2 * item.scale);
content.width = lastX + disX;
rowCount++;
if (rowCount >= row) {
rowCount = 0;
colCount++;
}
}
}
onClickPreview() {
this.LessonBrief.active = true
this.LessonBrief.getComponent("LessonBrief").setData(this.configData.introduces)
......
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