12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, Component, instantiate, v3, v2, size, Tween, tween, UITransform, sys, UIRenderer, RenderAlternative, ShowNode, ItemCell, LoopList, _crd;
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- /**
- * 获取节点的边缘
- * @param cell
- * @param needArr 顺序是上 下 左 右
- */
- function getNodeBorder(cell, needArr) {
- var borderData = {};
- var wpos = cell.node.worldPosition.clone(); //显示区域上边缘
- if (needArr[0]) {
- borderData.topSide = wpos.y + cell.uiTrans.height * (1 - cell.uiTrans.anchorY);
- } //显示区域下边缘
- if (needArr[1]) {
- borderData.bottomSide = wpos.y - cell.uiTrans.height * cell.uiTrans.anchorY;
- } //显示区域左边缘
- if (needArr[2]) {
- borderData.leftSide = wpos.x - cell.uiTrans.width * cell.uiTrans.anchorX;
- } //显示区域右边缘
- if (needArr[3]) {
- borderData.rightSide = wpos.x + cell.uiTrans.width * (1 - cell.uiTrans.anchorX);
- }
- borderData.size = size(cell.uiTrans.width, cell.uiTrans.height);
- return borderData;
- }
- function _reportPossibleCrUseOfRenderAlternative(extras) {
- _reporterNs.report("RenderAlternative", "./RenderAlternative", _context.meta, extras);
- }
- _export({
- ShowNode: void 0,
- ItemCell: void 0,
- default: void 0
- });
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- Node = _cc.Node;
- Component = _cc.Component;
- instantiate = _cc.instantiate;
- v3 = _cc.v3;
- v2 = _cc.v2;
- size = _cc.size;
- Tween = _cc.Tween;
- tween = _cc.tween;
- UITransform = _cc.UITransform;
- sys = _cc.sys;
- UIRenderer = _cc.UIRenderer;
- }, function (_unresolved_2) {
- RenderAlternative = _unresolved_2.default;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "eb0f0XLY1pHG4T0p8KqFdV/", "LoopList", undefined);
- __checkObsolete__(['Node', 'Component', 'Vec2', 'Size', 'Prefab', 'instantiate', 'v3', 'ScrollView', 'v2', 'size', 'Tween', 'tween', 'UITransform', 'Vec3', 'sys', 'UIRenderer']);
- /**边缘 */
- _export("ShowNode", ShowNode = class ShowNode extends Component {
- constructor() {
- super(...arguments);
- this.hasInit = false;
- /**渲染分层开启的挂载节点 */
- this.renderLayer = void 0;
- /**上级的cell */
- this.cell = void 0;
- /**数据 */
- this.data = void 0;
- }
- /**初始化 */
- init(cell, data, renderLayer) {
- this.cell = cell;
- this.data = data;
- if (this.renderLayer != renderLayer) {
- this.renderLayer = renderLayer;
- renderLayer && this.initRenders();
- }
- this.initShow();
- }
- /**初始化操作 */
- initShow() {}
- /**被回收,应该做一些释放的操作 */
- onRecircle() {}
- /**
- * 在特定时间内进行大小变化
- * @param targetSize
- * @param time
- */
- resize(targetSize, time) {
- if (time === void 0) {
- time = 0.3;
- }
- this.cell.resize(targetSize, time);
- }
- /**
- * 处理分层代理渲染
- */
- initRenders() {
- if (!this.hasInit && this.renderLayer) {
- var propMap = new WeakMap();
- var keys = Object.keys(this);
- for (var i = 0, len = keys.length; i < len; ++i) {
- var value = this[keys[i]];
- var alternative = null;
- if (value instanceof Node) {
- alternative = value.getComponent(_crd && RenderAlternative === void 0 ? (_reportPossibleCrUseOfRenderAlternative({
- error: Error()
- }), RenderAlternative) : RenderAlternative);
- if (alternative) {
- alternative.init(this.renderLayer);
- }
- } else if (value instanceof UIRenderer) {
- alternative = value.getComponent(_crd && RenderAlternative === void 0 ? (_reportPossibleCrUseOfRenderAlternative({
- error: Error()
- }), RenderAlternative) : RenderAlternative);
- if (alternative) {
- this[keys[i]] = alternative.init(this.renderLayer);
- }
- }
- alternative && propMap.set(alternative, true);
- }
- this.dealChilrenAlternative(this.node, propMap, 0, 0);
- this.hasInit = true;
- }
- }
- /**
- * 处理子节点代理
- * @param node
- * @param propMap 记录脚本已经处理过的属性代理
- * @param parentSindex 父节点的所在的顺序
- * @param depth 深度
- */
- dealChilrenAlternative(node, propMap, parentSindex, depth) {
- for (var i = 0, len = node.children.length; i < len; i++) {
- var _children$getComponen;
- var children = node.children[i];
- var alternative = (_children$getComponen = children.getComponent(UIRenderer)) == null ? void 0 : _children$getComponen.getComponent(_crd && RenderAlternative === void 0 ? (_reportPossibleCrUseOfRenderAlternative({
- error: Error()
- }), RenderAlternative) : RenderAlternative);
- var sIndex = parentSindex + i * Math.pow(0.1, depth);
- if (alternative) {
- if (!propMap.has(alternative) || !propMap.get(alternative)) {
- alternative.init(this.renderLayer);
- }
- alternative.sIndex = sIndex;
- }
- this.dealChilrenAlternative(children, propMap, sIndex, depth + 1);
- }
- }
- });
- _export("ItemCell", ItemCell = class ItemCell {
- /**
- * 构造函数
- * @param node
- * @param looplist
- */
- constructor(node, looplist) {
- /**持有cell的list */
- this.looplist = null;
- /**大小处理 */
- this.uiTrans = null;
- /**位置节点 */
- this.node = null;
- /**显示节点 */
- this.showNode = null;
- /**数据下标 */
- this.dataIndex = null;
- /**cell下标 */
- this.cellIndex = null;
- /**尺寸 */
- this.size = null;
- /**数据 */
- this.data = null;
- this.node = node;
- this.looplist = looplist;
- }
- /**
- * 初始化
- * @param node 节点
- * @param data 数据
- * @param size 大小
- * @param dataIndex 数据下标
- * @param cellIndex 节点下标
- * @param looplist 挂载的列表
- */
- init(data, size, dataIndex, cellIndex) {
- Tween.stopAllByTarget(this.node);
- this.cellIndex = cellIndex;
- this.dataIndex = dataIndex;
- !this.uiTrans && (this.uiTrans = this.node.getComponent(UITransform));
- this.uiTrans.width = size.width;
- this.uiTrans.height = size.height;
- this.data = data;
- this.size = size;
- }
- /**
- * 重置大小
- * @param newSize
- * @param time
- */
- resize(newSize, time) {
- var nodeSides = getNodeBorder(this, [true, true, true, true]);
- var changeSize = size(newSize.width - this.size.width, newSize.height - this.size.height);
- this.size = newSize;
- this.looplist.dealChangeSize(this, nodeSides, changeSize, time).then(() => {
- this.uiTrans.width = newSize.width;
- this.uiTrans.height = newSize.height;
- this.looplist.updateNodes();
- });
- }
- /**
- *
- * 更新节点显示
- * @param isShow 是否显示
- * @param prefab 需要显示的节点的预制件(也可以是节点,或者预制件url,生成方式自由改动)
- * @param cacheNode 对象池中的显示节点
- * @param renderLayer 分层节点
- */
- updateShow(isShow, prefab, cacheNode, renderLayer) {
- if (isShow) {
- //当前没有显示节点
- if (!this.showNode) {
- //如果是临时对象池还有节点则重用
- if (cacheNode) {
- this.showNode = cacheNode;
- } else {
- //否则使用传入的预制件进行生成
- this.showNode = instantiate(prefab).getComponent(ShowNode);
- }
- this.showNode.node.setParent(this.node);
- this.showNode.node.position = v3();
- this.updateShowNode(renderLayer);
- }
- }
- }
- /**
- * 更新showNode节点显示
- * @param renderLayer
- */
- updateShowNode(renderLayer) {
- //当前有显示节点
- if (this.showNode) {
- this.showNode.init(this, this.data, renderLayer);
- }
- }
- /**是否有显示节点 */
- get hasNoNode() {
- return !this.showNode;
- }
- /**回收显示节点 */
- recircle() {
- if (this.showNode) {
- var node = this.showNode;
- this.showNode.cell = null;
- this.showNode.onRecircle();
- this.showNode.node.removeFromParent();
- this.showNode = null;
- return node;
- }
- }
- destroy() {
- this.node.destroy();
- this.node = null;
- this.uiTrans = null;
- this.looplist = null;
- }
- /**
- * 失去显示节点
- * @returns
- */
- lostShowNode() {
- if (this.showNode) {
- var node = this.showNode;
- this.showNode.cell = null;
- this.showNode.node.removeFromParent();
- this.showNode = null;
- return node;
- }
- }
- /**
- * 获取显示节点
- * @param showNode
- */
- getShowNode(showNode) {
- this.showNode = showNode;
- showNode.node.setParent(this.node);
- this.showNode.cell = this;
- }
- });
- /**
- * 目前列表注意事项
- * 1.开启cellMaxNum后不能一行多列或者一列多行,只能单行或者单列
- */
- _export("default", LoopList = class LoopList {
- constructor() {
- /**分层节点(只有在showNode中挂载了RenderAlternative才能起作用) */
- this.renderLayer = null;
- /**滚动组件 */
- this.scrollView = null;
- /**cell节点最大数量 */
- this.cellMaxNum = null;
- /**当前起点 */
- this.curStartIndex = null;
- /**容器的ui控件 */
- this.contentUiTrans = null;
- /**数据 */
- this.datas = [];
- /**item节点们 */
- this.itemCells = [];
- /**预制件 */
- this.prefab = null;
- /**显示节点的池子 */
- this.showNodePool = [];
- /**边缘数据 */
- this.viewSides = {};
- /**上一帧滚动容器的坐标 */
- this.lastPos = null;
- /**刷新显示的间隔次数 */
- this.updateInv = 0;
- /**循环切换的最后一次时间 */
- this.lastChange = 0;
- /**通用尺寸 */
- this.size = null;
- /**通用锚点 */
- this.anchor = null;
- }
- static ins(listName) {
- if (!this.insMap.has(listName)) {
- this.insMap.set(listName, new LoopList());
- }
- return this.insMap.get(listName);
- }
- /**
- * 更新边界
- */
- updateBorder() {
- this.contentUiTrans = this.scrollView.content.getComponent(UITransform);
- var view = this.scrollView.view;
- view.anchorX = this.contentUiTrans.anchorX;
- view.anchorY = this.contentUiTrans.anchorY; //修改锚点之后下一帧世界坐标才会更新,没办法只能等一帧了
- return new Promise((resolve, reject) => {
- requestAnimationFrame(() => {
- var wpos = view.node.worldPosition.clone(); //显示区域左边缘
- var leftSide = wpos.x - view.width * view.anchorX; //显示区域右边缘
- var rightSide = wpos.x + view.width * (1 - view.anchorX); //显示区域下边缘
- var bottomSide = wpos.y - view.height * view.anchorY; //显示区域上边缘
- var topSide = wpos.y + view.height * (1 - view.anchorY);
- this.viewSides = {
- leftSide,
- rightSide,
- bottomSide,
- topSide,
- size: size(view.width, view.height)
- };
- this.contentUiTrans.node.setPosition(v3(0, 0));
- resolve();
- });
- });
- }
- /**
- * 初始化滚动列表*
- * @param scrollView
- * @param renderLayer 渲染分层的父节点,如果传入则可以配合showNode上的renderAlternative来进行渲染分层
- * @param cellMaxNum cell节点的最大数量,设置成null则不启用,启用的话,要设置成(可视窗刚好能显示的最大数量*2)+2,假设最多能看到10个节点,那么设置成22
- */
- init(scrollView, renderLayer, cellMaxNum) {
- var _this = this;
- return _asyncToGenerator(function* () {
- cellMaxNum && (_this.cellMaxNum = cellMaxNum);
- renderLayer && (_this.renderLayer = renderLayer);
- _this.scrollView = scrollView;
- yield _this.updateBorder();
- _this.scrollView.node.on("scrolling", _this.scrollingListener, _this);
- })();
- }
- /**滚动监听 */
- scrollingListener() {
- this.updateInv--;
- if (this.updateInv <= 0) {
- this.updateInv = 2;
- var showCells = this.updateNodes();
- if (!this.cellMaxNum) {
- return;
- }
- if (!this.lastPos) {
- this.lastPos = this.scrollView.content.position.clone();
- } else {
- var offset = this.scrollView.content.position.clone().subtract(this.lastPos);
- this.lastPos = this.scrollView.content.position.clone();
- var now = sys.now();
- if (!this.lastChange || now - this.lastChange > 1) {
- this.lastChange = now;
- this.dealLoopList(offset, showCells);
- }
- }
- }
- }
- /**
- * 初始化
- * @param data 数据组
- * @param prefab 预制件
- * @param size 通用尺寸
- * @param anchor cell的锚点
- */
- initData(data, prefab, size, anchor) {
- if (anchor === void 0) {
- anchor = v2(0.5, 0.5);
- }
- this.datas = data;
- this.size = size;
- this.anchor = anchor;
- this.prefab = prefab;
- var len = this.cellMaxNum ? this.cellMaxNum : data.length;
- for (var i = 0; i < len; ++i) {
- var _data = this.datas[this.curStartIndex + i];
- var cellSize = _data.size ? _data.size : size;
- var itemCell = this.itemCells[i];
- if (!itemCell) {
- var node = new Node('LoopListCell');
- var uiTrans = node.addComponent(UITransform);
- itemCell = this.itemCells[i] = new ItemCell(node, this);
- uiTrans.setAnchorPoint(anchor);
- node.setParent(this.scrollView.content);
- }
- itemCell.init(_data, cellSize, this.curStartIndex + i, i);
- }
- for (var _i = data.length, _len = this.itemCells.length; _i < _len; ++_i) {
- this.recircleShowNode(this.itemCells[_i].recircle());
- this.itemCells[_i].destroy();
- this.itemCells[_i] = null;
- }
- requestAnimationFrame(() => {
- this.updateNodes();
- });
- }
- /**
- * 压入新的数据
- * @param datas
- */
- pushDatas(datas) {
- var length = this.datas.length;
- for (var i = 0, len = datas.length; i < len; ++i) {
- var data = datas[i];
- this.datas.push(data);
- var index = length + i;
- this.addNodeFromIndex(index);
- }
- }
- /**
- * 插入新的数据
- * @param data
- * @param insertIndex
- */
- insertData(data, insertIndex) {
- if (this.datas.length >= insertIndex) {
- this.datas.splice(insertIndex, 0, data);
- this.addNodeFromIndex(insertIndex);
- } else {
- this.pushDatas([data]);
- }
- }
- /**
- * 移除对应数据
- * @param removeIndex
- */
- removeData(removeIndex) {
- if (this.datas.length >= removeIndex) {
- this.datas.splice(removeIndex, 1);
- if (this.cellMaxNum) {
- var cellIndex = removeIndex - this.curStartIndex; //在使用范围内
- if (cellIndex >= 0 && cellIndex < this.cellMaxNum) {
- var itemCell = this.itemCells[cellIndex];
- var nodeSides = getNodeBorder(itemCell, [true, true, true, true]);
- var changeSize = size(-itemCell.size.width, -itemCell.size.height);
- itemCell.size = size(0, 0);
- this.dealChangeSize(itemCell, nodeSides, changeSize).then(() => {
- //更新数据
- for (var i = cellIndex; i < this.cellMaxNum; i++) {
- var curDataIndex = this.curStartIndex + i;
- var curData = this.datas[curDataIndex];
- var curCellSize = curData.size ? curData.size : this.size;
- this.itemCells[i].init(curData, curCellSize, curDataIndex, i);
- this.itemCells[i].updateShowNode(this.renderLayer);
- }
- });
- }
- } else {
- var _itemCell = this.itemCells.splice(removeIndex, 1)[0];
- var _nodeSides = getNodeBorder(_itemCell, [true, true, true, true]);
- var _changeSize = size(-_itemCell.size.width, -_itemCell.size.height);
- _itemCell.size = size(0, 0);
- this.dealChangeSize(_itemCell, _nodeSides, _changeSize).then(() => {
- this.recircleShowNode(_itemCell.recircle());
- _itemCell.node.destroy();
- });
- }
- }
- }
- /**
- * 从某个数据开始更新
- * @param dataIndex
- */
- addNodeFromIndex(dataIndex) {
- var _this2 = this;
- return _asyncToGenerator(function* () {
- var data = _this2.datas[dataIndex];
- var cellSize = data.size ? data.size : _this2.size; //是否开启cell循环
- if (_this2.cellMaxNum) {
- var cellIndex = dataIndex - _this2.curStartIndex; //在使用范围内
- if (cellIndex >= 0 && cellIndex < _this2.cellMaxNum) {
- //更新数据
- for (var i = cellIndex; i < _this2.cellMaxNum; i++) {
- var curDataIndex = _this2.curStartIndex + i;
- var curData = _this2.datas[curDataIndex];
- var curCellSize = curData.size ? curData.size : _this2.size;
- _this2.itemCells[i].init(curData, curCellSize, curDataIndex, i);
- _this2.itemCells[i].updateShowNode(_this2.renderLayer);
- } //获取当前的位置
- var nodeSides = null;
- var itemCell = _this2.itemCells[cellIndex];
- if (itemCell) {
- nodeSides = getNodeBorder(itemCell, [true, true, true, true]);
- itemCell.uiTrans.width = 0;
- itemCell.uiTrans.height = 0;
- _this2.dealChangeSize(itemCell, nodeSides, cellSize).then(() => {
- itemCell.uiTrans.width = cellSize.width;
- itemCell.uiTrans.height = cellSize.height;
- });
- }
- }
- } else {
- //获取当前的位置
- var _nodeSides2 = null;
- if (_this2.itemCells[dataIndex]) {
- _nodeSides2 = getNodeBorder(_this2.itemCells[dataIndex], [true, true, true, true]);
- }
- var node = new Node('LoopListCell');
- var uiTrans = node.addComponent(UITransform);
- uiTrans.setAnchorPoint(_this2.anchor);
- node.setParent(_this2.scrollView.content);
- node.setSiblingIndex(dataIndex);
- var _itemCell2 = new ItemCell(node, _this2);
- _this2.itemCells.splice(dataIndex, 0, _itemCell2);
- _itemCell2.init(data, cellSize, dataIndex, dataIndex);
- if (!_nodeSides2) {
- yield new Promise((resolve, reject) => {
- requestAnimationFrame(() => {
- _nodeSides2 = getNodeBorder(_itemCell2, [true, true, true, true]);
- resolve();
- });
- });
- }
- if (_nodeSides2) {
- _itemCell2.uiTrans.width = 0;
- _itemCell2.uiTrans.height = 0;
- _this2.dealChangeSize(_itemCell2, _nodeSides2, cellSize).then(() => {
- _itemCell2.uiTrans.width = cellSize.width;
- _itemCell2.uiTrans.height = cellSize.height;
- });
- }
- _this2.dealItemShow(_itemCell2);
- }
- })();
- }
- /**
- * 处理列表的循环利用
- * @param offset
- * @param dataIndexs
- */
- dealLoopList(offset, showCells) {
- var startCell = showCells[0];
- var endCell = showCells[showCells.length - 1];
- if (this.scrollView.vertical) {
- /**内容上移 */
- if (offset.y > 0) {
- //已经到达最后倒数第二个节点并且还有数据
- if (this.scrollView.content.position.y >= -this.itemCells[this.itemCells.length - 2].node.position.y - this.viewSides.size.height && endCell.dataIndex < this.datas.length - 2) {
- //显示开始数据下标(这里-1是想要顶部留一个itemcell做缓冲)
- var showStart = startCell.dataIndex - 1; //剩余可展示的数据量
- var leave = this.datas.length - showStart; //计算应该从那个位置开始重新赋值,因为如果直接移动到最上方,数据量不够覆盖所有的cell
- var cellStartIndex = Math.max(0, this.itemCells.length - leave); //计算第一个cell的数据下标
- this.curStartIndex = showStart - cellStartIndex;
- var cellTop = getNodeBorder(this.itemCells[startCell.cellIndex], [true]).topSide;
- var contentHeight = 0;
- var targetY = 0;
- var jumpFirst = true;
- var showIndex = 0;
- for (var i = 0, len = this.itemCells.length; i < len; ++i) {
- if (i >= cellStartIndex) {
- //将当前已经显示的showNode节点直接重新设置到移动后的节点上
- if (showIndex < showCells.length && !jumpFirst) {
- if (showIndex == 0) {
- targetY = contentHeight;
- }
- var showNode = showCells[showIndex].lostShowNode();
- showIndex++;
- this.itemCells[i].getShowNode(showNode);
- }
- jumpFirst = false;
- }
- var dataIndex = this.curStartIndex + i;
- var data = this.datas[dataIndex];
- var cellSize = data.size ? data.size : this.size;
- contentHeight += cellSize.height;
- this.itemCells[i].init(data, cellSize, dataIndex, i);
- } //将content的位置移动到最上方并对齐移动前的状态
- var posY = targetY + (cellTop - this.viewSides.topSide);
- this.scrollView.content.setPosition(v3(this.scrollView.content.position.x, posY));
- this.scrollView.scrollToOffset(v2(0, posY + endCell.size.height), 1);
- this.lastPos = null;
- }
- } //内容下移
- else if (offset.y < 0) {
- //已经到达第二个节点并且还有数据
- if (this.scrollView.content.position.y < -this.itemCells[2].node.position.y && startCell.dataIndex > 2) {
- //展示的最后一个数据下表,+1是为了在底部预留一部分空间
- var showEndIndex = endCell.dataIndex + 1; //计算应该从那个位置开始重新赋值,因为如果直接移动到最下方,数据量不够覆盖所有的cell
- var cellEndIndex = Math.min(this.itemCells.length - 2, showEndIndex - 1); //计算第一个cell的数据下标
- this.curStartIndex = Math.max(showEndIndex - (this.itemCells.length - 1), 0); //将content的位置移动到最下方并对齐移动前的状态
- var _cellTop = getNodeBorder(this.itemCells[Math.max(startCell.cellIndex - 1, 0)], [true]).topSide;
- var _contentHeight = 0;
- var _showIndex = showCells.length - 1;
- for (var _i2 = this.itemCells.length - 1; _i2 >= 0; --_i2) {
- if (_i2 <= cellEndIndex) {
- //将当前已经显示的showNode节点直接重新设置到移动后的节点上
- if (_showIndex >= 0) {
- var _showNode = showCells[_showIndex].lostShowNode();
- _showIndex--;
- this.itemCells[_i2].getShowNode(_showNode);
- } else {
- _showIndex--;
- }
- }
- var _dataIndex = this.curStartIndex + _i2;
- var _data2 = this.datas[_dataIndex];
- var _cellSize = _data2.size ? _data2.size : this.size;
- if (_showIndex < -1) {
- _contentHeight += _cellSize.height;
- }
- this.itemCells[_i2].init(_data2, _cellSize, _dataIndex, _i2);
- } //将content的位置移动到最下方并对齐移动前的状态
- var _posY = _contentHeight + (_cellTop - this.viewSides.topSide);
- this.scrollView.content.setPosition(v3(this.scrollView.content.position.x, _posY));
- this.scrollView.scrollToOffset(v2(0, _posY - startCell.size.height), 1);
- this.lastPos = null;
- }
- }
- } else if (this.scrollView.horizontal) {
- if (offset.x < 0) {
- //已经到达最后倒数第二个节点并且还有数据
- if (this.scrollView.content.position.x <= -(this.itemCells[this.itemCells.length - 2].node.position.x - this.viewSides.size.width) && endCell.dataIndex < this.datas.length - 2) {
- //显示开始数据下标(这里-1是想要左侧留一个itemcell做缓冲)
- var _showStart = startCell.dataIndex - 1; //剩余可展示的数据量
- var _leave = this.datas.length - _showStart; //计算应该从那个位置开始重新赋值,因为如果直接移动到最左侧,数据量不够覆盖所有的cell
- var _cellStartIndex = Math.max(0, this.itemCells.length - _leave); //计算第一个cell的数据下标
- this.curStartIndex = _showStart - _cellStartIndex;
- var cellLeft = getNodeBorder(this.itemCells[startCell.cellIndex], [false, false, true]).leftSide;
- var contentWidth = 0;
- var targetX = 0;
- var _jumpFirst = true;
- var _showIndex2 = 0;
- for (var _i3 = 0, _len2 = this.itemCells.length; _i3 < _len2; ++_i3) {
- if (_i3 >= _cellStartIndex) {
- //将当前已经显示的showNode节点直接重新设置到移动后的节点上
- if (_showIndex2 < showCells.length && !_jumpFirst) {
- if (_showIndex2 == 0) {
- targetX = contentWidth;
- }
- var _showNode2 = showCells[_showIndex2].lostShowNode();
- _showIndex2++;
- this.itemCells[_i3].getShowNode(_showNode2);
- }
- _jumpFirst = false;
- }
- var _dataIndex2 = this.curStartIndex + _i3;
- var _data3 = this.datas[_dataIndex2];
- var _cellSize2 = _data3.size ? _data3.size : this.size;
- contentWidth += _cellSize2.width;
- this.itemCells[_i3].init(_data3, _cellSize2, _dataIndex2, _i3);
- } //将content的位置移动到最左侧并对齐移动前的状态
- var posX = cellLeft - this.viewSides.leftSide - targetX;
- this.scrollView.content.setPosition(v3(posX, this.scrollView.content.position.y));
- this.scrollView.scrollToOffset(v2(-(posX - endCell.size.width), 0), 1);
- this.lastPos = null;
- }
- } else if (offset.x > 0) {
- //已经到达第二个节点并且还有数据
- if (this.scrollView.content.position.x > -this.itemCells[2].node.position.x && startCell.dataIndex > 2) {
- //展示的最后一个数据下表,+1是为了在右侧预留一部分空间
- var _showEndIndex = endCell.dataIndex + 1; //计算应该从那个位置开始重新赋值,因为如果直接移动到最右侧,数据量不够覆盖所有的cell
- var _cellEndIndex = Math.min(this.itemCells.length - 2, _showEndIndex - 1); //计算第一个cell的数据下标
- this.curStartIndex = Math.max(_showEndIndex - (this.itemCells.length - 1), 0); //将content的位置移动到最右侧并对齐移动前的状态
- var _cellLeft = getNodeBorder(this.itemCells[Math.max(startCell.cellIndex - 1, 0)], [false, false, true]).leftSide;
- var _contentWidth = 0;
- var _showIndex3 = showCells.length - 1;
- for (var _i4 = this.itemCells.length - 1; _i4 >= 0; --_i4) {
- if (_i4 <= _cellEndIndex) {
- //将当前已经显示的showNode节点直接重新设置到移动后的节点上
- if (_showIndex3 >= 0) {
- var _showNode3 = showCells[_showIndex3].lostShowNode();
- _showIndex3--;
- this.itemCells[_i4].getShowNode(_showNode3);
- } else {
- _showIndex3--;
- }
- }
- var _dataIndex3 = this.curStartIndex + _i4;
- var _data4 = this.datas[_dataIndex3];
- var _cellSize3 = _data4.size ? _data4.size : this.size;
- if (_showIndex3 < -1) {
- _contentWidth += _cellSize3.width;
- }
- this.itemCells[_i4].init(_data4, _cellSize3, _dataIndex3, _i4);
- } //将content的位置移动到最右侧并对齐移动前的状态
- var _posX = _cellLeft - this.viewSides.leftSide - _contentWidth;
- this.scrollView.content.setPosition(v3(_posX, this.scrollView.content.position.y));
- this.scrollView.scrollToOffset(v2(-(_posX + startCell.size.width), 0), 1);
- this.lastPos = null;
- }
- }
- }
- }
- /**更新节点的显示 */
- updateNodes() {
- var showCells = [];
- for (var i = 0, len = this.itemCells.length; i < len; ++i) {
- var itemCell = this.itemCells[i];
- var isShow = this.dealItemShow(itemCell);
- if (isShow) {
- showCells.push(itemCell);
- }
- }
- return showCells;
- }
- /**
- * 处理cell的显示隐藏
- * @param itemCell
- */
- dealItemShow(itemCell) {
- if (itemCell) {
- var isShow = this.checkInView(itemCell);
- if (isShow) {
- itemCell.hasNoNode && itemCell.updateShow(isShow, this.prefab, this.showNodePool.length > 0 ? this.showNodePool.pop() : null, this.renderLayer);
- } else {
- !itemCell.hasNoNode && this.recircleShowNode(itemCell.recircle());
- }
- return isShow;
- }
- }
- /**
- * 检查是否在屏幕内
- * @param node
- * @returns
- */
- checkInView(itemCell) {
- var nodeSides = getNodeBorder(itemCell, [true, true, true, true]); //节点右侧边缘在屏幕左侧外面或者节点左边缘在屏幕右侧外面 则不在显示区域
- var horizontalOutside = nodeSides.rightSide < this.viewSides.leftSide || nodeSides.leftSide > this.viewSides.rightSide;
- var verticalOutside = false;
- if (!horizontalOutside) {
- //节点上边缘在屏幕下方外面或者节点下边缘在屏幕上方外面 则不在显示区域
- verticalOutside = nodeSides.topSide < this.viewSides.bottomSide || nodeSides.bottomSide > this.viewSides.topSide;
- }
- return !horizontalOutside && !verticalOutside;
- }
- /**
- * 处理变化的大小
- * @param cell
- * @param nodeSides
- * @param changeSize
- */
- dealChangeSize(cell, nodeSides, changeSize, time) {
- var _this3 = this;
- return _asyncToGenerator(function* () {
- if (time === void 0) {
- time = 0.3;
- }
- var topToBottomFulfill = _this3.contentUiTrans.anchorY == 1 && nodeSides.bottomSide >= _this3.viewSides.topSide;
- var bottomToTopFulfill = _this3.contentUiTrans.anchorY == 0 && nodeSides.topSide <= _this3.viewSides.bottomSide;
- if (topToBottomFulfill || bottomToTopFulfill) {
- if (topToBottomFulfill) {
- _this3.scrollView.content.position.add(v3(0, changeSize.height));
- } else {
- _this3.scrollView.content.position.subtract(v3(0, changeSize.height));
- }
- }
- var leftToRightFulfill = _this3.contentUiTrans.anchorX == 0 && nodeSides.rightSide <= _this3.viewSides.leftSide;
- var RightToLeftFulfill = _this3.contentUiTrans.anchorX == 1 && nodeSides.leftSide >= _this3.viewSides.rightSide;
- if (leftToRightFulfill || RightToLeftFulfill) {
- if (RightToLeftFulfill) {
- _this3.scrollView.content.position.add(v3(changeSize.width, 0));
- } else {
- _this3.scrollView.content.position.subtract(v3(changeSize.width, 0));
- }
- }
- if (!(topToBottomFulfill || bottomToTopFulfill || leftToRightFulfill || RightToLeftFulfill)) {
- Tween.stopAllByTarget(cell.node);
- yield new Promise((resolve, reject) => {
- tween(cell.uiTrans).to(time, {
- width: cell.size.width,
- height: cell.size.height
- }).call(() => {
- resolve();
- }).start();
- });
- }
- _this3.updateNodes();
- return true;
- })();
- }
- /**
- * 回收显示节点
- * @param node
- */
- recircleShowNode(node) {
- node && this.showNodePool.push(node);
- }
- /**
- * 释放当前列表
- */
- freeList() {
- this.scrollView.node.off("scrolling", this.scrollingListener);
- for (var i = 0, len = this.itemCells.length; i < len; ++i) {
- this.recircleShowNode(this.itemCells[i].recircle());
- this.itemCells[i].destroy();
- }
- this.itemCells = [];
- for (var index = 0, _len3 = this.showNodePool.length; index < _len3; ++index) {
- this.showNodePool[index].destroy();
- }
- this.showNodePool = [];
- this.renderLayer = null;
- this.scrollView = null;
- this.prefab = null;
- }
- });
- LoopList.insMap = new Map();
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=08ba4751e7c5800eec3c9b3663921ed7b92e974b.js.map
|