123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673 |
- System.register(["__unresolved_0", "cc", "cc/env", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
- "use strict";
- var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, Component, Enum, tween, _decorator, EventHandler, ScrollView, Prefab, Layout, Size, isValid, Vec3, Widget, UITransform, CCFloat, CCBoolean, CCInteger, DEV, ListItem, PoolManager, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _descriptor15, _descriptor16, _descriptor17, _crd, ccclass, property, disallowMultiple, menu, executionOrder, requireComponent, TemplateType, SlideType, SelectedType, List;
- function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
- function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
- function _reportPossibleCrUseOfListItem(extras) {
- _reporterNs.report("ListItem", "./ListItem", _context.meta, extras);
- }
- function _reportPossibleCrUseOfPoolManager(extras) {
- _reporterNs.report("PoolManager", "../core/manager/PoolManager", _context.meta, extras);
- }
- return {
- setters: [function (_unresolved_) {
- _reporterNs = _unresolved_;
- }, function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- Node = _cc.Node;
- Component = _cc.Component;
- Enum = _cc.Enum;
- tween = _cc.tween;
- _decorator = _cc._decorator;
- EventHandler = _cc.EventHandler;
- ScrollView = _cc.ScrollView;
- Prefab = _cc.Prefab;
- Layout = _cc.Layout;
- Size = _cc.Size;
- isValid = _cc.isValid;
- Vec3 = _cc.Vec3;
- Widget = _cc.Widget;
- UITransform = _cc.UITransform;
- CCFloat = _cc.CCFloat;
- CCBoolean = _cc.CCBoolean;
- CCInteger = _cc.CCInteger;
- }, function (_ccEnv) {
- DEV = _ccEnv.DEV;
- }, function (_unresolved_2) {
- ListItem = _unresolved_2.default;
- }, function (_unresolved_3) {
- PoolManager = _unresolved_3.PoolManager;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "adcd1ArJf5IPoMo1kZUgpJg", "List", undefined);
- /*列表组件*/
- ({
- ccclass,
- property,
- disallowMultiple,
- menu,
- executionOrder,
- requireComponent
- } = _decorator);
- __checkObsolete__(['Node', 'Component', 'Enum', 'tween', '_decorator', 'EventHandler', 'Tween', 'ScrollView', 'Prefab', 'Layout', 'Vec2', 'Size', 'isValid', 'Vec3', 'Widget', 'UITransform', 'CCFloat', 'CCBoolean', 'CCInteger']);
- TemplateType = /*#__PURE__*/function (TemplateType) {
- TemplateType[TemplateType["NODE"] = 1] = "NODE";
- TemplateType[TemplateType["PREFAB"] = 2] = "PREFAB";
- return TemplateType;
- }(TemplateType || {});
- SlideType = /*#__PURE__*/function (SlideType) {
- SlideType[SlideType["NORMAL"] = 1] = "NORMAL";
- SlideType[SlideType["ADHERING"] = 2] = "ADHERING";
- SlideType[SlideType["PAGE"] = 3] = "PAGE";
- return SlideType;
- }(SlideType || {});
- SelectedType = /*#__PURE__*/function (SelectedType) {
- SelectedType[SelectedType["NONE"] = 0] = "NONE";
- SelectedType[SelectedType["SINGLE"] = 1] = "SINGLE";
- SelectedType[SelectedType["MULT"] = 2] = "MULT";
- return SelectedType;
- }(SelectedType || {});
- _export("default", List = (_dec = disallowMultiple(), _dec2 = menu('List'), _dec3 = requireComponent(ScrollView), _dec4 = executionOrder(-5000), _dec5 = property({
- type: Enum(TemplateType),
- tooltip: DEV && '模板类型'
- }), _dec6 = property({
- type: Node,
- tooltip: DEV && '模板Item',
- visible() {
- return this.templateType == TemplateType.NODE;
- }
- }), _dec7 = property({
- type: Prefab,
- tooltip: DEV && '模板Item',
- visible() {
- return this.templateType == TemplateType.PREFAB;
- }
- }), _dec8 = property({}), _dec9 = property({
- type: Enum(SlideType),
- tooltip: DEV && '滑动模式'
- }), _dec10 = property({
- type: CCFloat,
- range: [0, 1, .1],
- tooltip: DEV && '翻页作用距离',
- slide: true,
- visible() {
- return this._slideMode == SlideType.PAGE;
- }
- }), _dec11 = property({
- type: EventHandler,
- tooltip: DEV && '页面改变事件',
- visible() {
- return this._slideMode == SlideType.PAGE;
- }
- }), _dec12 = property({}), _dec13 = property({
- type: CCBoolean,
- tooltip: DEV && '是否为虚拟列表(动态列表)'
- }), _dec14 = property({
- tooltip: DEV && '是否为循环列表',
- visible() {
- var val =
- /*this.virtual &&*/
- this.slideMode == SlideType.NORMAL;
- if (!val) this.cyclic = false;
- return val;
- }
- }), _dec15 = property({
- tooltip: DEV && 'Item数量不足以填满Content时,是否居中显示Item(不支持Grid布局)',
- visible() {
- return this.virtual;
- }
- }), _dec16 = property({
- tooltip: DEV && 'Item数量不足以填满Content时,是否可滑动',
- visible() {
- var val = this.virtual && !this.lackCenter;
- if (!val) this.lackSlide = false;
- return val;
- }
- }), _dec17 = property({
- type: CCInteger
- }), _dec18 = property({
- type: CCInteger,
- range: [0, 6, 1],
- tooltip: DEV && '刷新频率(值越大刷新频率越低、性能越高)',
- slide: true
- }), _dec19 = property({
- type: CCInteger,
- range: [0, 12, 1],
- tooltip: DEV && '逐帧渲染时,每帧渲染的Item数量(<=0时关闭分帧渲染)',
- slide: true
- }), _dec20 = property({
- type: EventHandler,
- tooltip: DEV && '渲染事件(渲染器)'
- }), _dec21 = property({
- type: Enum(SelectedType),
- tooltip: DEV && '选择模式'
- }), _dec22 = property({
- type: EventHandler,
- tooltip: DEV && '触发选择事件',
- visible() {
- return this.selectedMode > SelectedType.NONE;
- }
- }), _dec23 = property({
- tooltip: DEV && '是否重复响应单选事件',
- visible() {
- return this.selectedMode == SelectedType.SINGLE;
- }
- }), _dec24 = property({
- serializable: false
- }), ccclass(_class = _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = (_class2 = class List extends Component {
- constructor() {
- super(...arguments);
- //模板类型
- _initializerDefineProperty(this, "templateType", _descriptor, this);
- //模板Item(Node)
- _initializerDefineProperty(this, "tmpNode", _descriptor2, this);
- //模板Item(Prefab)
- _initializerDefineProperty(this, "tmpPrefab", _descriptor3, this);
- //滑动模式
- _initializerDefineProperty(this, "_slideMode", _descriptor4, this);
- //翻页作用距离
- _initializerDefineProperty(this, "pageDistance", _descriptor5, this);
- //页面改变事件
- _initializerDefineProperty(this, "pageChangeEvent", _descriptor6, this);
- //是否为虚拟列表(动态列表)
- _initializerDefineProperty(this, "_virtual", _descriptor7, this);
- //是否为循环列表
- _initializerDefineProperty(this, "cyclic", _descriptor8, this);
- //缺省居中
- _initializerDefineProperty(this, "lackCenter", _descriptor9, this);
- //缺省可滑动
- _initializerDefineProperty(this, "lackSlide", _descriptor10, this);
- //刷新频率
- _initializerDefineProperty(this, "_updateRate", _descriptor11, this);
- //分帧渲染(每帧渲染的Item数量(<=0时关闭分帧渲染))
- _initializerDefineProperty(this, "frameByFrameRenderNum", _descriptor12, this);
- //渲染事件(渲染器)
- _initializerDefineProperty(this, "renderEvent", _descriptor13, this);
- //选择模式
- _initializerDefineProperty(this, "selectedMode", _descriptor14, this);
- //触发选择事件
- _initializerDefineProperty(this, "selectedEvent", _descriptor15, this);
- _initializerDefineProperty(this, "repeatEventSingle", _descriptor16, this);
- //当前选择id
- this._selectedId = -1;
- this._lastSelectedId = void 0;
- this.multSelected = void 0;
- this._forceUpdate = false;
- this._align = void 0;
- this._horizontalDir = void 0;
- this._verticalDir = void 0;
- this._startAxis = void 0;
- this._alignCalcType = void 0;
- this.content = void 0;
- this._contentUt = void 0;
- this.firstListId = void 0;
- this.displayItemNum = void 0;
- this._updateDone = true;
- this._updateCounter = void 0;
- this._actualNumItems = void 0;
- this._cyclicNum = void 0;
- this._cyclicPos1 = void 0;
- this._cyclicPos2 = void 0;
- //列表数量
- _initializerDefineProperty(this, "_numItems", _descriptor17, this);
- this._inited = false;
- this._scrollView = void 0;
- this._layout = void 0;
- this._resizeMode = void 0;
- this._topGap = void 0;
- this._rightGap = void 0;
- this._bottomGap = void 0;
- this._leftGap = void 0;
- this._columnGap = void 0;
- this._lineGap = void 0;
- this._colLineNum = void 0;
- this._lastDisplayData = void 0;
- this.displayData = void 0;
- this._itemTmp = void 0;
- this._itemTmpUt = void 0;
- this._needUpdateWidget = false;
- this._itemSize = void 0;
- this._sizeType = void 0;
- this._oScale = void 0;
- this._customSize = void 0;
- this.frameCount = void 0;
- this._aniDelRuning = false;
- this._aniDelCB = void 0;
- this._aniDelItem = void 0;
- this._aniDelBeforePos = void 0;
- this._aniDelBeforeScale = void 0;
- this.viewTop = void 0;
- this.viewRight = void 0;
- this.viewBottom = void 0;
- this.viewLeft = void 0;
- this._doneAfterUpdate = false;
- this.elasticTop = void 0;
- this.elasticRight = void 0;
- this.elasticBottom = void 0;
- this.elasticLeft = void 0;
- this.scrollToListId = void 0;
- this.adhering = false;
- this._adheringBarrier = false;
- this.nearestListId = void 0;
- this.curPageNum = 0;
- this._beganPos = void 0;
- this._scrollPos = void 0;
- this._curScrollIsTouch = void 0;
- //当前滑动是否为手动
- this._scrollToListId = void 0;
- this._scrollToEndTime = void 0;
- this._scrollToSo = void 0;
- this._lack = void 0;
- this._allItemSize = void 0;
- this._allItemSizeNoEdge = void 0;
- this._scrollItem = void 0;
- //当前控制 ScrollView 滚动的 Item
- this._thisNodeUt = void 0;
- }
- set slideMode(val) {
- this._slideMode = val;
- }
- get slideMode() {
- return this._slideMode;
- }
- set virtual(val) {
- if (val != null) this._virtual = val;
- if (!DEV && this._numItems != 0) {
- this._onScrolling();
- }
- }
- get virtual() {
- return this._virtual;
- }
- set updateRate(val) {
- if (val >= 0 && val <= 6) {
- this._updateRate = val;
- }
- }
- get updateRate() {
- return this._updateRate;
- }
- set selectedId(val) {
- var t = this;
- var item;
- switch (t.selectedMode) {
- case SelectedType.SINGLE:
- {
- if (!t.repeatEventSingle && val == t._selectedId) return;
- item = t.getItemByListId(val); // if (!item && val >= 0)
- // return;
- var listItem;
- if (t._selectedId >= 0) t._lastSelectedId = t._selectedId;else //如果<0则取消选择,把_lastSelectedId也置空吧,如果以后有特殊需求再改吧。
- t._lastSelectedId = null;
- t._selectedId = val;
- if (item) {
- listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem);
- listItem.selected = true;
- }
- if (t._lastSelectedId >= 0 && t._lastSelectedId != t._selectedId) {
- var lastItem = t.getItemByListId(t._lastSelectedId);
- if (lastItem) {
- lastItem.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem).selected = false;
- }
- }
- if (t.selectedEvent) {
- EventHandler.emitEvents([t.selectedEvent], item, val % this._actualNumItems, t._lastSelectedId == null ? null : t._lastSelectedId % this._actualNumItems);
- }
- break;
- }
- case SelectedType.MULT:
- {
- item = t.getItemByListId(val);
- if (!item) return;
- var _listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem);
- if (t._selectedId >= 0) t._lastSelectedId = t._selectedId;
- t._selectedId = val;
- var bool = !_listItem.selected;
- _listItem.selected = bool;
- var sub = t.multSelected.indexOf(val);
- if (bool && sub < 0) {
- t.multSelected.push(val);
- } else if (!bool && sub >= 0) {
- t.multSelected.splice(sub, 1);
- }
- if (t.selectedEvent) {
- EventHandler.emitEvents([t.selectedEvent], item, val % this._actualNumItems, t._lastSelectedId == null ? null : t._lastSelectedId % this._actualNumItems, bool);
- }
- break;
- }
- }
- }
- get selectedId() {
- return this._selectedId;
- }
- set numItems(val) {
- var t = this; //t.recycle();
- if (!t.checkInited(false)) return;
- if (val == null || val < 0) {
- console.error('numItems set the wrong::', val);
- return;
- }
- t._actualNumItems = t._numItems = val;
- t._forceUpdate = true;
- if (t._virtual) {
- t._resizeContent();
- if (t.cyclic) {
- t._numItems = t._cyclicNum * t._numItems;
- }
- t._onScrolling();
- if (!t.frameByFrameRenderNum && t.slideMode == SlideType.PAGE) t.curPageNum = t.nearestListId;
- } else {
- if (t.cyclic) {
- t._resizeContent();
- t._numItems = t._cyclicNum * t._numItems;
- }
- var layout = t.content.getComponent(Layout);
- if (layout) {
- layout.enabled = true;
- }
- t._delRedundantItem();
- t.firstListId = 0;
- if (t.frameByFrameRenderNum > 0) {
- //先渲染几个出来
- var len = t.frameByFrameRenderNum > t._numItems ? t._numItems : t.frameByFrameRenderNum;
- for (var n = 0; n < len; n++) {
- t._createOrUpdateItem2(n);
- }
- if (t.frameByFrameRenderNum < t._numItems) {
- t._updateCounter = t.frameByFrameRenderNum;
- t._updateDone = false;
- }
- } else {
- for (var _n = 0; _n < t._numItems; _n++) {
- t._createOrUpdateItem2(_n);
- }
- t.displayItemNum = t._numItems;
- }
- }
- }
- get numItems() {
- return this._actualNumItems;
- }
- get scrollView() {
- return this._scrollView;
- }
- onLoad() {
- this._init();
- }
- recycle() {
- this.content.children.forEach(e => {
- if (e != this.tmpNode && isValid(e)) {
- e.scale = this._oScale;
- (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).putNode(e);
- }
- });
- }
- onDestroy() {
- var t = this;
- if (isValid(t._itemTmp)) t._itemTmp.destroy();
- if (isValid(t.tmpNode)) t.tmpNode.destroy();
- }
- onDisable() {
- // if (!EDITOR)
- this._unregisterEvent();
- this.recycle();
- }
- onEnable() {
- // if (!EDITOR)
- this._registerEvent();
- this._init(); // 处理重新显示后,有可能上一次的动画移除还未播放完毕,导致动画卡住的问题
- if (this._aniDelRuning) {
- this._aniDelRuning = false;
- if (this._aniDelItem) {
- if (this._aniDelBeforePos) {
- this._aniDelItem.position = this._aniDelBeforePos;
- delete this._aniDelBeforePos;
- }
- if (this._aniDelBeforeScale) {
- this._aniDelItem.scale = this._aniDelBeforeScale;
- delete this._aniDelBeforeScale;
- }
- delete this._aniDelItem;
- }
- if (this._aniDelCB) {
- this._aniDelCB();
- delete this._aniDelCB;
- }
- }
- } //注册事件
- _registerEvent() {
- var t = this;
- t.node.on(Node.EventType.TOUCH_START, t._onTouchStart, t);
- t.node.on('touch-up', t._onTouchUp, t);
- t.node.on(Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t);
- t.node.on('scroll-began', t._onScrollBegan, t);
- t.node.on('scroll-ended', t._onScrollEnded, t);
- t.node.on('scrolling', t._onScrolling, t);
- t.node.on(Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
- } //卸载事件
- _unregisterEvent() {
- var t = this;
- t.node.off(Node.EventType.TOUCH_START, t._onTouchStart, t);
- t.node.off('touch-up', t._onTouchUp, t);
- t.node.off(Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t);
- t.node.off('scroll-began', t._onScrollBegan, t);
- t.node.off('scroll-ended', t._onScrollEnded, t);
- t.node.off('scrolling', t._onScrolling, t);
- t.node.off(Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
- } //初始化各种..
- _init() {
- var t = this;
- if (t._inited) return;
- t._thisNodeUt = t.node.getComponent(UITransform);
- t._scrollView = t.node.getComponent(ScrollView);
- t.content = t._scrollView.content;
- t._contentUt = t.content.getComponent(UITransform);
- if (!t.content) {
- console.error(t.node.name + "'s ScrollView unset content!");
- return;
- }
- t._layout = t.content.getComponent(Layout);
- t._align = t._layout.type; //排列模式
- t._resizeMode = t._layout.resizeMode; //自适应模式
- t._startAxis = t._layout.startAxis;
- t._topGap = t._layout.paddingTop; //顶边距
- t._rightGap = t._layout.paddingRight; //右边距
- t._bottomGap = t._layout.paddingBottom; //底边距
- t._leftGap = t._layout.paddingLeft; //左边距
- t._columnGap = t._layout.spacingX; //列距
- t._lineGap = t._layout.spacingY; //行距
- t._colLineNum; //列数或行数(非GRID模式则=1,表示单列或单行);
- t._verticalDir = t._layout.verticalDirection; //垂直排列子节点的方向
- t._horizontalDir = t._layout.horizontalDirection; //水平排列子节点的方向
- var pNode = t.templateType == TemplateType.PREFAB ? t.tmpPrefab : t.tmpNode;
- t.setTemplateItem((_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).getNode(pNode)); // 特定的滑动模式处理
- if (t._slideMode == SlideType.ADHERING || t._slideMode == SlideType.PAGE) {
- t._scrollView.inertia = false;
- t._scrollView._onMouseWheel = function () {
- return;
- };
- }
- if (!t.virtual) // lackCenter 仅支持 Virtual 模式
- t.lackCenter = false;
- t._lastDisplayData = []; //最后一次刷新的数据
- t.displayData = []; //当前数据
- t._forceUpdate = false; //是否强制更新
- t._updateCounter = 0; //当前分帧渲染帧数
- t._updateDone = true; //分帧渲染是否完成
- t.curPageNum = 0; //当前页数
- if (t.cyclic || 0) {
- t._scrollView._processAutoScrolling = this._processAutoScrolling.bind(t);
- t._scrollView._startBounceBackIfNeeded = function () {
- return false;
- };
- }
- switch (t._align) {
- case Layout.Type.HORIZONTAL:
- {
- switch (t._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- t._alignCalcType = 1;
- break;
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- t._alignCalcType = 2;
- break;
- }
- break;
- }
- case Layout.Type.VERTICAL:
- {
- switch (t._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- t._alignCalcType = 3;
- break;
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- t._alignCalcType = 4;
- break;
- }
- break;
- }
- case Layout.Type.GRID:
- {
- switch (t._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- switch (t._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- t._alignCalcType = 3;
- break;
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- t._alignCalcType = 4;
- break;
- }
- break;
- case Layout.AxisDirection.VERTICAL:
- switch (t._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- t._alignCalcType = 1;
- break;
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- t._alignCalcType = 2;
- break;
- }
- break;
- }
- break;
- }
- } // 清空 content
- // t.content.children.forEach((child: Node) => {
- // child.removeFromParent();
- // if (child != t.tmpNode && child.isValid)
- // child.destroy();
- // });
- t.content.removeAllChildren();
- t._inited = true;
- }
- /**
- * 为了实现循环列表,必须覆写cc.ScrollView的某些函数
- * @param {Number} dt
- */
- _processAutoScrolling(dt) {
- // ------------- scroll-view 里定义的一些常量 -------------
- var OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05;
- var EPSILON = 1e-4;
- var ZERO = new Vec3();
- var quintEaseOut = time => {
- time -= 1;
- return time * time * time * time * time + 1;
- }; // ------------- scroll-view 里定义的一些常量 -------------
- var sv = this._scrollView;
- var isAutoScrollBrake = sv['_isNecessaryAutoScrollBrake']();
- var brakingFactor = isAutoScrollBrake ? OUT_OF_BOUNDARY_BREAKING_FACTOR : 1;
- sv['_autoScrollAccumulatedTime'] += dt * (1 / brakingFactor);
- var percentage = Math.min(1, sv['_autoScrollAccumulatedTime'] / sv['_autoScrollTotalTime']);
- if (sv['_autoScrollAttenuate']) {
- percentage = quintEaseOut(percentage);
- }
- var clonedAutoScrollTargetDelta = sv['_autoScrollTargetDelta'].clone();
- clonedAutoScrollTargetDelta.multiplyScalar(percentage);
- var clonedAutoScrollStartPosition = sv['_autoScrollStartPosition'].clone();
- clonedAutoScrollStartPosition.add(clonedAutoScrollTargetDelta);
- var reachedEnd = Math.abs(percentage - 1) <= EPSILON;
- var fireEvent = Math.abs(percentage - 1) <= sv['getScrollEndedEventTiming']();
- if (fireEvent && !sv['_isScrollEndedWithThresholdEventFired']) {
- sv['_dispatchEvent'](ScrollView.EventType.SCROLL_ENG_WITH_THRESHOLD);
- sv['_isScrollEndedWithThresholdEventFired'] = true;
- }
- if (sv['elastic']) {
- var brakeOffsetPosition = clonedAutoScrollStartPosition.clone();
- brakeOffsetPosition.subtract(sv['_autoScrollBrakingStartPosition']);
- if (isAutoScrollBrake) {
- brakeOffsetPosition.multiplyScalar(brakingFactor);
- }
- clonedAutoScrollStartPosition.set(sv['_autoScrollBrakingStartPosition']);
- clonedAutoScrollStartPosition.add(brakeOffsetPosition);
- } else {
- var moveDelta = clonedAutoScrollStartPosition.clone();
- moveDelta.subtract(sv['_getContentPosition']());
- var outOfBoundary = sv['_getHowMuchOutOfBoundary'](moveDelta);
- if (!outOfBoundary.equals(ZERO, EPSILON)) {
- clonedAutoScrollStartPosition.add(outOfBoundary);
- reachedEnd = true;
- }
- }
- if (reachedEnd) {
- sv['_autoScrolling'] = false;
- }
- var deltaMove = new Vec3(clonedAutoScrollStartPosition);
- deltaMove.subtract(sv['_getContentPosition']());
- sv['_clampDelta'](deltaMove);
- sv['_moveContent'](deltaMove, reachedEnd);
- sv['_dispatchEvent'](ScrollView.EventType.SCROLLING);
- if (!sv['_autoScrolling']) {
- sv['_isBouncing'] = false;
- sv['_scrolling'] = false;
- sv['_dispatchEvent'](ScrollView.EventType.SCROLL_ENDED);
- }
- } //设置模板Item
- setTemplateItem(item) {
- if (!item) return;
- var t = this;
- t._itemTmp = item;
- t._itemTmpUt = item.getComponent(UITransform);
- t._oScale = item.scale;
- if (t._resizeMode == Layout.ResizeMode.CHILDREN) t._itemSize = t._layout.cellSize;else {
- var itemUt = item.getComponent(UITransform);
- t._itemSize = new Size(itemUt.width, itemUt.height);
- } //获取ListItem,如果没有就取消选择模式
- var com = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem);
- var remove = false;
- if (!com) remove = true; // if (com) {
- // if (!com._btnCom && !item.getComponent(cc.Button)) {
- // remove = true;
- // }
- // }
- if (remove) {
- t.selectedMode = SelectedType.NONE;
- }
- com = item.getComponent(Widget);
- if (com && com.enabled) {
- t._needUpdateWidget = true;
- }
- if (t.selectedMode == SelectedType.MULT) t.multSelected = [];
- switch (t._align) {
- case Layout.Type.HORIZONTAL:
- t._colLineNum = 1;
- t._sizeType = false;
- break;
- case Layout.Type.VERTICAL:
- t._colLineNum = 1;
- t._sizeType = true;
- break;
- case Layout.Type.GRID:
- switch (t._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- //计算列数
- var trimW = t._contentUt.width - t._leftGap - t._rightGap;
- t._colLineNum = Math.floor((trimW + t._columnGap) / (t._itemSize.width + t._columnGap));
- t._sizeType = true;
- break;
- case Layout.AxisDirection.VERTICAL:
- //计算行数
- var trimH = t._contentUt.height - t._topGap - t._bottomGap;
- t._colLineNum = Math.floor((trimH + t._lineGap) / (t._itemSize.height + t._lineGap));
- t._sizeType = false;
- break;
- }
- break;
- }
- }
- /**
- * 检查是否初始化
- * @param {Boolean} printLog 是否打印错误信息
- * @returns
- */
- checkInited(printLog) {
- if (printLog === void 0) {
- printLog = true;
- }
- if (!this._inited) {
- if (printLog) console.error('List initialization not completed!');
- return false;
- }
- return true;
- } //禁用 Layout 组件,自行计算 Content Size
- _resizeContent() {
- var t = this;
- var result;
- switch (t._align) {
- case Layout.Type.HORIZONTAL:
- {
- if (t._customSize) {
- var fixed = t._getFixedSize(null);
- result = t._leftGap + fixed.val + t._itemSize.width * (t._numItems - fixed.count) + t._columnGap * (t._numItems - 1) + t._rightGap;
- } else {
- result = t._leftGap + t._itemSize.width * t._numItems + t._columnGap * (t._numItems - 1) + t._rightGap;
- }
- break;
- }
- case Layout.Type.VERTICAL:
- {
- if (t._customSize) {
- var _fixed = t._getFixedSize(null);
- result = t._topGap + _fixed.val + t._itemSize.height * (t._numItems - _fixed.count) + t._lineGap * (t._numItems - 1) + t._bottomGap;
- } else {
- result = t._topGap + t._itemSize.height * t._numItems + t._lineGap * (t._numItems - 1) + t._bottomGap;
- }
- break;
- }
- case Layout.Type.GRID:
- {
- //网格模式不支持居中
- if (t.lackCenter) t.lackCenter = false;
- switch (t._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- var lineNum = Math.ceil(t._numItems / t._colLineNum);
- result = t._topGap + t._itemSize.height * lineNum + t._lineGap * (lineNum - 1) + t._bottomGap;
- break;
- case Layout.AxisDirection.VERTICAL:
- var colNum = Math.ceil(t._numItems / t._colLineNum);
- result = t._leftGap + t._itemSize.width * colNum + t._columnGap * (colNum - 1) + t._rightGap;
- break;
- }
- break;
- }
- }
- var layout = t.content.getComponent(Layout);
- if (layout) layout.enabled = false;
- t._allItemSize = result;
- t._allItemSizeNoEdge = t._allItemSize - (t._sizeType ? t._topGap + t._bottomGap : t._leftGap + t._rightGap);
- if (t.cyclic) {
- var totalSize = t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width;
- t._cyclicPos1 = 0;
- totalSize -= t._cyclicPos1;
- t._cyclicNum = Math.ceil(totalSize / t._allItemSizeNoEdge) + 1;
- var spacing = t._sizeType ? t._lineGap : t._columnGap;
- t._cyclicPos2 = t._cyclicPos1 + t._allItemSizeNoEdge + spacing;
- t._cyclicAllItemSize = t._allItemSize + t._allItemSizeNoEdge * (t._cyclicNum - 1) + spacing * (t._cyclicNum - 1);
- t._cycilcAllItemSizeNoEdge = t._allItemSizeNoEdge * t._cyclicNum;
- t._cycilcAllItemSizeNoEdge += spacing * (t._cyclicNum - 1); // cc.log('_cyclicNum ->', t._cyclicNum, t._allItemSizeNoEdge, t._allItemSize, t._cyclicPos1, t._cyclicPos2);
- }
- t._lack = !t.cyclic && t._allItemSize < (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
- var slideOffset = (!t._lack || !t.lackCenter) && t.lackSlide ? 0 : .1;
- var targetWH = t._lack ? (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) - slideOffset : t.cyclic ? t._cyclicAllItemSize : t._allItemSize;
- if (targetWH < 0) targetWH = 0;
- if (t._sizeType) {
- t._contentUt.height = targetWH;
- } else {
- t._contentUt.width = targetWH;
- } // cc.log('_resizeContent() numItems =', t._numItems, ',content =', t.content);
- }
- /**
- * 自定义大小
- * @returns
- */
- _getChildSize() {
- var pTra = this.content.getComponent(UITransform);
- var spacingX = this._layout.spacingX;
- var paddingLeft = this._layout.paddingLeft;
- var w = (pTra.contentSize.width - (this._numItems - 1) * spacingX - paddingLeft * 2) / this._numItems;
- return new Size(w, w);
- } //滚动进行时...
- _onScrolling(ev) {
- if (ev === void 0) {
- ev = null;
- }
- if (this.frameCount == null) this.frameCount = this._updateRate;
- if (!this._forceUpdate && ev && ev.type != 'scroll-ended' && this.frameCount > 0) {
- this.frameCount--;
- return;
- } else this.frameCount = this._updateRate;
- if (this._aniDelRuning) return; //循环列表处理
- if (this.cyclic) {
- var scrollPos = this.content.getPosition();
- scrollPos = this._sizeType ? scrollPos.y : scrollPos.x;
- var addVal = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap);
- var add = this._sizeType ? new Vec3(0, addVal, 0) : new Vec3(addVal, 0, 0);
- var contentPos = this.content.getPosition();
- switch (this._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- if (scrollPos > -this._cyclicPos1) {
- contentPos.set(-this._cyclicPos2, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- } // if (this._beganPos) {
- // this._beganPos += add;
- // }
- } else if (scrollPos < -this._cyclicPos2) {
- contentPos.set(-this._cyclicPos1, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- } // if (this._beganPos) {
- // this._beganPos -= add;
- // }
- }
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- if (scrollPos < this._cyclicPos1) {
- contentPos.set(this._cyclicPos2, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- } else if (scrollPos > this._cyclicPos2) {
- contentPos.set(this._cyclicPos1, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- }
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (scrollPos < this._cyclicPos1) {
- contentPos.set(contentPos.x, this._cyclicPos2, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- } else if (scrollPos > this._cyclicPos2) {
- contentPos.set(contentPos.x, this._cyclicPos1, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- }
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (scrollPos > -this._cyclicPos1) {
- contentPos.set(contentPos.x, -this._cyclicPos2, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- } else if (scrollPos < -this._cyclicPos2) {
- contentPos.set(contentPos.x, -this._cyclicPos1, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- }
- break;
- }
- }
- this._calcViewPos();
- var vTop, vRight, vBottom, vLeft;
- if (this._sizeType) {
- vTop = this.viewTop;
- vBottom = this.viewBottom;
- } else {
- vRight = this.viewRight;
- vLeft = this.viewLeft;
- }
- if (this._virtual) {
- this.displayData = [];
- var itemPos;
- var curId = 0;
- var endId = this._numItems - 1;
- if (this._customSize) {
- var breakFor = false; //如果该item的位置在可视区域内,就推入displayData
- for (; curId <= endId && !breakFor; curId++) {
- itemPos = this._calcItemPos(curId);
- switch (this._align) {
- case Layout.Type.HORIZONTAL:
- if (itemPos.right >= vLeft && itemPos.left <= vRight) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- case Layout.Type.VERTICAL:
- if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- case Layout.Type.GRID:
- switch (this._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- case Layout.AxisDirection.VERTICAL:
- if (itemPos.right >= vLeft && itemPos.left <= vRight) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- }
- break;
- }
- }
- } else {
- var ww = this._itemSize.width + this._columnGap;
- var hh = this._itemSize.height + this._lineGap;
- switch (this._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- curId = (vLeft - this._leftGap) / ww;
- endId = (vRight - this._leftGap) / ww;
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- curId = (-vRight - this._rightGap) / ww;
- endId = (-vLeft - this._rightGap) / ww;
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- curId = (-vTop - this._topGap) / hh;
- endId = (-vBottom - this._topGap) / hh;
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- curId = (vBottom - this._bottomGap) / hh;
- endId = (vTop - this._bottomGap) / hh;
- break;
- }
- curId = Math.floor(curId) * this._colLineNum;
- endId = Math.ceil(endId) * this._colLineNum;
- endId--;
- if (curId < 0) curId = 0;
- if (endId >= this._numItems) endId = this._numItems - 1;
- for (; curId <= endId; curId++) {
- this.displayData.push(this._calcItemPos(curId));
- }
- }
- this._delRedundantItem();
- if (this.displayData.length <= 0 || !this._numItems) {
- //if none, delete all.
- this._lastDisplayData = [];
- return;
- }
- this.firstListId = this.displayData[0].id;
- this.displayItemNum = this.displayData.length;
- var len = this._lastDisplayData.length;
- var haveDataChange = this.displayItemNum != len;
- if (haveDataChange) {
- // 如果是逐帧渲染,需要排序
- if (this.frameByFrameRenderNum > 0) {
- this._lastDisplayData.sort((a, b) => {
- return a - b;
- });
- } // 因List的显示数据是有序的,所以只需要判断数组长度是否相等,以及头、尾两个元素是否相等即可。
- haveDataChange = this.firstListId != this._lastDisplayData[0] || this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[len - 1];
- }
- if (this._forceUpdate || haveDataChange) {
- //如果是强制更新
- if (this.frameByFrameRenderNum > 0) {
- // if (this._updateDone) {
- // this._lastDisplayData = [];
- //逐帧渲染
- if (this._numItems > 0) {
- if (!this._updateDone) {
- this._doneAfterUpdate = true;
- } else {
- this._updateCounter = 0;
- }
- this._updateDone = false;
- } else {
- this._updateCounter = 0;
- this._updateDone = true;
- } // }
- } else {
- //直接渲染
- this._lastDisplayData = []; // cc.log('List Display Data II::', this.displayData);
- for (var c = 0; c < this.displayItemNum; c++) {
- this._createOrUpdateItem(this.displayData[c]);
- }
- this._forceUpdate = false;
- }
- }
- this._calcNearestItem();
- }
- } //计算可视范围
- _calcViewPos() {
- var scrollPos = this.content.getPosition();
- switch (this._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- this.elasticLeft = scrollPos.x > 0 ? scrollPos.x : 0;
- this.viewLeft = (scrollPos.x < 0 ? -scrollPos.x : 0) - this.elasticLeft;
- this.viewRight = this.viewLeft + this._thisNodeUt.width;
- this.elasticRight = this.viewRight > this._contentUt.width ? Math.abs(this.viewRight - this._contentUt.width) : 0;
- this.viewRight += this.elasticRight; // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- this.elasticRight = scrollPos.x < 0 ? -scrollPos.x : 0;
- this.viewRight = (scrollPos.x > 0 ? -scrollPos.x : 0) + this.elasticRight;
- this.viewLeft = this.viewRight - this._thisNodeUt.width;
- this.elasticLeft = this.viewLeft < -this._contentUt.width ? Math.abs(this.viewLeft + this._contentUt.width) : 0;
- this.viewLeft -= this.elasticLeft; // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- this.elasticTop = scrollPos.y < 0 ? Math.abs(scrollPos.y) : 0;
- this.viewTop = (scrollPos.y > 0 ? -scrollPos.y : 0) + this.elasticTop;
- this.viewBottom = this.viewTop - this._thisNodeUt.height;
- this.elasticBottom = this.viewBottom < -this._contentUt.height ? Math.abs(this.viewBottom + this._contentUt.height) : 0;
- this.viewBottom += this.elasticBottom; // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- this.elasticBottom = scrollPos.y > 0 ? Math.abs(scrollPos.y) : 0;
- this.viewBottom = (scrollPos.y < 0 ? -scrollPos.y : 0) - this.elasticBottom;
- this.viewTop = this.viewBottom + this._thisNodeUt.height;
- this.elasticTop = this.viewTop > this._contentUt.height ? Math.abs(this.viewTop - this._contentUt.height) : 0;
- this.viewTop -= this.elasticTop; // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
- break;
- }
- } //计算位置 根据id
- _calcItemPos(id) {
- var width, height, top, bottom, left, right, itemX, itemY;
- switch (this._align) {
- case Layout.Type.HORIZONTAL:
- switch (this._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- {
- if (this._customSize) {
- var fixed = this._getFixedSize(id);
- left = this._leftGap + (this._itemSize.width + this._columnGap) * (id - fixed.count) + (fixed.val + this._columnGap * fixed.count);
- var cs = this._customSize[id];
- width = cs > 0 ? cs : this._itemSize.width;
- } else {
- left = this._leftGap + (this._itemSize.width + this._columnGap) * id;
- width = this._itemSize.width;
- }
- if (this.lackCenter) {
- left -= this._leftGap;
- var offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
- left += offset;
- }
- right = left + width;
- return {
- id: id,
- left: left,
- right: right,
- x: left + this._itemTmpUt.anchorX * width,
- y: this._itemTmp.y
- };
- }
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- {
- if (this._customSize) {
- var _fixed2 = this._getFixedSize(id);
- right = -this._rightGap - (this._itemSize.width + this._columnGap) * (id - _fixed2.count) - (_fixed2.val + this._columnGap * _fixed2.count);
- var _cs = this._customSize[id];
- width = _cs > 0 ? _cs : this._itemSize.width;
- } else {
- right = -this._rightGap - (this._itemSize.width + this._columnGap) * id;
- width = this._itemSize.width;
- }
- if (this.lackCenter) {
- right += this._rightGap;
- var _offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
- right -= _offset;
- }
- left = right - width;
- return {
- id: id,
- right: right,
- left: left,
- x: left + this._itemTmpUt.anchorX * width,
- y: this._itemTmp.y
- };
- }
- }
- break;
- case Layout.Type.VERTICAL:
- {
- switch (this._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- {
- if (this._customSize) {
- var _fixed3 = this._getFixedSize(id);
- top = -this._topGap - (this._itemSize.height + this._lineGap) * (id - _fixed3.count) - (_fixed3.val + this._lineGap * _fixed3.count);
- var _cs2 = this._customSize[id];
- height = _cs2 > 0 ? _cs2 : this._itemSize.height;
- } else {
- top = -this._topGap - (this._itemSize.height + this._lineGap) * id;
- height = this._itemSize.height;
- }
- if (this.lackCenter) {
- top += this._topGap;
- var _offset2 = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
- top -= _offset2;
- }
- bottom = top - height;
- return {
- id: id,
- top: top,
- bottom: bottom,
- x: this._itemTmp.x,
- y: bottom + this._itemTmpUt.anchorY * height
- };
- }
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- {
- if (this._customSize) {
- var _fixed4 = this._getFixedSize(id);
- bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * (id - _fixed4.count) + (_fixed4.val + this._lineGap * _fixed4.count);
- var _cs3 = this._customSize[id];
- height = _cs3 > 0 ? _cs3 : this._itemSize.height;
- } else {
- bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * id;
- height = this._itemSize.height;
- }
- if (this.lackCenter) {
- bottom -= this._bottomGap;
- var _offset3 = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
- bottom += _offset3;
- }
- top = bottom + height;
- return {
- id: id,
- top: top,
- bottom: bottom,
- x: this._itemTmp.x,
- y: bottom - this._itemTmpUt.anchorY * height
- };
- break;
- }
- }
- }
- case Layout.Type.GRID:
- {
- var colLine = Math.floor(id / this._colLineNum);
- switch (this._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- {
- switch (this._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- {
- top = -this._topGap - (this._itemSize.height + this._lineGap) * colLine;
- bottom = top - this._itemSize.height;
- itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
- break;
- }
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- {
- bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * colLine;
- top = bottom + this._itemSize.height;
- itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
- break;
- }
- }
- itemX = this._leftGap + id % this._colLineNum * (this._itemSize.width + this._columnGap);
- switch (this._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- {
- itemX += this._itemTmpUt.anchorX * this._itemSize.width;
- itemX -= this._contentUt.anchorX * this._contentUt.width;
- break;
- }
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- {
- itemX += (1 - this._itemTmpUt.anchorX) * this._itemSize.width;
- itemX -= (1 - this._contentUt.anchorX) * this._contentUt.width;
- itemX *= -1;
- break;
- }
- }
- return {
- id: id,
- top: top,
- bottom: bottom,
- x: itemX,
- y: itemY
- };
- }
- case Layout.AxisDirection.VERTICAL:
- {
- switch (this._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- {
- left = this._leftGap + (this._itemSize.width + this._columnGap) * colLine;
- right = left + this._itemSize.width;
- itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
- itemX -= this._contentUt.anchorX * this._contentUt.width;
- break;
- }
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- {
- right = -this._rightGap - (this._itemSize.width + this._columnGap) * colLine;
- left = right - this._itemSize.width;
- itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
- itemX += (1 - this._contentUt.anchorX) * this._contentUt.width;
- break;
- }
- }
- itemY = -this._topGap - id % this._colLineNum * (this._itemSize.height + this._lineGap);
- switch (this._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- {
- itemY -= (1 - this._itemTmpUt.anchorY) * this._itemSize.height;
- itemY += (1 - this._contentUt.anchorY) * this._contentUt.height;
- break;
- }
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- {
- itemY -= this._itemTmpUt.anchorY * this._itemSize.height;
- itemY += this._contentUt.anchorY * this._contentUt.height;
- itemY *= -1;
- break;
- }
- }
- return {
- id: id,
- left: left,
- right: right,
- x: itemX,
- y: itemY
- };
- }
- }
- break;
- }
- }
- } //计算已存在的Item的位置
- _calcExistItemPos(id) {
- var item = this.getItemByListId(id);
- if (!item) return null;
- var ut = item.getComponent(UITransform);
- var pos = item.getPosition();
- var data = {
- id: id,
- x: pos.x,
- y: pos.y
- };
- if (this._sizeType) {
- data.top = pos.y + ut.height * (1 - ut.anchorY);
- data.bottom = pos.y - ut.height * ut.anchorY;
- } else {
- data.left = pos.x - ut.width * ut.anchorX;
- data.right = pos.x + ut.width * (1 - ut.anchorX);
- }
- return data;
- } //获取Item位置
- getItemPos(id) {
- if (this._virtual) return this._calcItemPos(id);else {
- if (this.frameByFrameRenderNum) return this._calcItemPos(id);else return this._calcExistItemPos(id);
- }
- } //获取固定尺寸
- _getFixedSize(listId) {
- if (!this._customSize) return null;
- if (listId == null) listId = this._numItems;
- var fixed = 0;
- var count = 0;
- for (var id in this._customSize) {
- if (parseInt(id) < listId) {
- fixed += this._customSize[id];
- count++;
- }
- }
- return {
- val: fixed,
- count: count
- };
- } //滚动结束时..
- _onScrollBegan() {
- this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
- } //滚动结束时..
- _onScrollEnded() {
- var t = this;
- t._curScrollIsTouch = false;
- if (t.scrollToListId != null) {
- var item = t.getItemByListId(t.scrollToListId);
- t.scrollToListId = null;
- if (item) {
- tween(item).to(.1, {
- scale: 1.06
- }).to(.1, {
- scale: 1
- }).start();
- }
- }
- t._onScrolling();
- if (t._slideMode == SlideType.ADHERING && !t.adhering) {
- //cc.log(t.adhering, t._scrollView.isAutoScrolling(), t._scrollView.isScrolling());
- t.adhere();
- } else if (t._slideMode == SlideType.PAGE) {
- if (t._beganPos != null && t._curScrollIsTouch) {
- this._pageAdhere();
- } else {
- t.adhere();
- }
- }
- } // 触摸时
- _onTouchStart(ev, captureListeners) {
- if (this._scrollView['_hasNestedViewGroup'](ev, captureListeners)) return;
- this._curScrollIsTouch = true;
- var isMe = ev.eventPhase === Event.AT_TARGET && ev.target === this.node;
- if (!isMe) {
- var itemNode = ev.target;
- while (itemNode._listId == null && itemNode.parent) itemNode = itemNode.parent;
- this._scrollItem = itemNode._listId != null ? itemNode : ev.target;
- }
- } //触摸抬起时..
- _onTouchUp() {
- var t = this;
- t._scrollPos = null;
- if (t._slideMode == SlideType.ADHERING) {
- if (this.adhering) this._adheringBarrier = true;
- t.adhere();
- } else if (t._slideMode == SlideType.PAGE) {
- if (t._beganPos != null) {
- this._pageAdhere();
- } else {
- t.adhere();
- }
- }
- this._scrollItem = null;
- }
- _onTouchCancelled(ev, captureListeners) {
- var t = this;
- if (t._scrollView['_hasNestedViewGroup'](ev, captureListeners) || ev.simulate) return;
- t._scrollPos = null;
- if (t._slideMode == SlideType.ADHERING) {
- if (t.adhering) t._adheringBarrier = true;
- t.adhere();
- } else if (t._slideMode == SlideType.PAGE) {
- if (t._beganPos != null) {
- t._pageAdhere();
- } else {
- t.adhere();
- }
- }
- this._scrollItem = null;
- } //当尺寸改变
- _onSizeChanged() {
- if (this.checkInited(false)) this._onScrolling();
- } //当Item自适应
- _onItemAdaptive(item) {
- var ut = item.getComponent(UITransform); // if (this.checkInited(false)) {
- if (!this._sizeType && ut.width != this._itemSize.width || this._sizeType && ut.height != this._itemSize.height) {
- if (!this._customSize) this._customSize = {};
- var val = this._sizeType ? ut.height : ut.width;
- if (this._customSize[item._listId] != val) {
- this._customSize[item._listId] = val;
- this._resizeContent(); // this.content.children.forEach((child: Node) => {
- // this._updateItemPos(child);
- // });
- this.updateAll(); // 如果当前正在运行 scrollTo,肯定会不准确,在这里做修正
- if (this._scrollToListId != null) {
- this._scrollPos = null;
- this.unschedule(this._scrollToSo);
- this.scrollTo(this._scrollToListId, Math.max(0, this._scrollToEndTime - new Date().getTime() / 1000));
- }
- }
- } // }
- } //PAGE粘附
- _pageAdhere() {
- var t = this;
- if (!t.cyclic && (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0)) return;
- var curPos = t._sizeType ? t.viewTop : t.viewLeft;
- var dis = (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) * t.pageDistance;
- var canSkip = Math.abs(t._beganPos - curPos) > dis;
- if (canSkip) {
- var timeInSecond = .5;
- switch (t._alignCalcType) {
- case 1: //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (t._beganPos > curPos) {
- t.prePage(timeInSecond); // cc.log('_pageAdhere PPPPPPPPPPPPPPP');
- } else {
- t.nextPage(timeInSecond); // cc.log('_pageAdhere NNNNNNNNNNNNNNN');
- }
- break;
- case 2: //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (t._beganPos < curPos) {
- t.prePage(timeInSecond);
- } else {
- t.nextPage(timeInSecond);
- }
- break;
- }
- } else if (t.elasticTop <= 0 && t.elasticRight <= 0 && t.elasticBottom <= 0 && t.elasticLeft <= 0) {
- t.adhere();
- }
- t._beganPos = null;
- } //粘附
- adhere() {
- var t = this;
- if (!t.checkInited()) return;
- if (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0) return;
- t.adhering = true;
- t._calcNearestItem();
- var offset = (t._sizeType ? t._topGap : t._leftGap) / (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
- var timeInSecond = .7;
- t.scrollTo(t.nearestListId, timeInSecond, offset);
- } //Update..
- update() {
- if (this.frameByFrameRenderNum <= 0 || this._updateDone) return; // cc.log(this.displayData.length, this._updateCounter, this.displayData[this._updateCounter]);
- if (this._virtual) {
- var len = this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ? this.displayItemNum : this._updateCounter + this.frameByFrameRenderNum;
- for (var n = this._updateCounter; n < len; n++) {
- var data = this.displayData[n];
- if (data) {
- this._createOrUpdateItem(data);
- }
- }
- if (this._updateCounter >= this.displayItemNum - 1) {
- //最后一个
- if (this._doneAfterUpdate) {
- this._updateCounter = 0;
- this._updateDone = false; // if (!this._scrollView.isScrolling())
- this._doneAfterUpdate = false;
- } else {
- this._updateDone = true;
- this._delRedundantItem();
- this._forceUpdate = false;
- this._calcNearestItem();
- if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
- }
- } else {
- this._updateCounter += this.frameByFrameRenderNum;
- }
- } else {
- if (this._updateCounter < this._numItems) {
- var _len = this._updateCounter + this.frameByFrameRenderNum > this._numItems ? this._numItems : this._updateCounter + this.frameByFrameRenderNum;
- for (var _n2 = this._updateCounter; _n2 < _len; _n2++) {
- this._createOrUpdateItem2(_n2);
- }
- this._updateCounter += this.frameByFrameRenderNum;
- } else {
- this._updateDone = true;
- this._calcNearestItem();
- if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
- }
- }
- }
- /**
- * 创建或更新Item(虚拟列表用)
- * @param {Object} data 数据
- */
- _createOrUpdateItem(data) {
- var item = this.getItemByListId(data.id);
- if (!item) {
- //如果不存在
- item = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).getNode(this._itemTmp, this.content);
- if (item._listId != data.id) {
- item._listId = data.id;
- var ut = item.getComponent(UITransform);
- ut.setContentSize(this._itemSize);
- }
- item.setPosition(new Vec3(data.x, data.y, 0));
- this._resetItemSize(item);
- if (this._needUpdateWidget) {
- var widget = item.getComponent(Widget);
- if (widget) widget.updateAlignment();
- }
- item.setSiblingIndex(this.content.children.length - 1);
- var listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem);
- item['listItem'] = listItem;
- if (listItem) {
- listItem.listId = data.id;
- listItem.list = this;
- listItem._registerEvent();
- }
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
- }
- } else if (this._forceUpdate && this.renderEvent) {
- //强制更新
- item.setPosition(new Vec3(data.x, data.y, 0));
- this._resetItemSize(item); // cc.log('ADD::', data.id, item);
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
- }
- }
- this._resetItemSize(item);
- this._updateListItem(item['listItem']);
- if (this._lastDisplayData.indexOf(data.id) < 0) {
- this._lastDisplayData.push(data.id);
- }
- } //创建或更新Item(非虚拟列表用)
- _createOrUpdateItem2(listId) {
- var item = this.content.children[listId];
- var listItem;
- if (!item) {
- //如果不存在
- item = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).getNode(this._itemTmp, this.content);
- item._listId = listId;
- listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem);
- item['listItem'] = listItem;
- if (listItem) {
- listItem.listId = listId;
- listItem.list = this;
- listItem._registerEvent();
- }
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
- }
- } else if (this._forceUpdate && this.renderEvent) {
- //强制更新
- item._listId = listId;
- if (listItem) listItem.listId = listId;
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
- }
- }
- this._updateListItem(listItem);
- if (this._lastDisplayData.indexOf(listId) < 0) {
- this._lastDisplayData.push(listId);
- }
- }
- _updateListItem(listItem) {
- if (!listItem) return;
- if (this.selectedMode > SelectedType.NONE) {
- var item = listItem.node;
- switch (this.selectedMode) {
- case SelectedType.SINGLE:
- listItem.selected = this.selectedId == item._listId;
- break;
- case SelectedType.MULT:
- listItem.selected = this.multSelected.indexOf(item._listId) >= 0;
- break;
- }
- }
- } //仅虚拟列表用
- _resetItemSize(item) {
- return;
- var size;
- var ut = item.getComponent(UITransform);
- if (this._customSize && this._customSize[item._listId]) {
- size = this._customSize[item._listId];
- } else {
- if (this._colLineNum > 1) ut.setContentSize(this._itemSize);else size = this._sizeType ? this._itemSize.height : this._itemSize.width;
- }
- if (size) {
- if (this._sizeType) ut.height = size;else ut.width = size;
- }
- }
- /**
- * 更新Item位置
- * @param {Number||Node} listIdOrItem
- */
- _updateItemPos(listIdOrItem) {
- var item = isNaN(listIdOrItem) ? listIdOrItem : this.getItemByListId(listIdOrItem);
- var pos = this.getItemPos(item._listId);
- item.setPosition(pos.x, pos.y);
- }
- /**
- * 设置多选
- * @param {Array} args 可以是单个listId,也可是个listId数组
- * @param {Boolean} bool 值,如果为null的话,则直接用args覆盖
- */
- setMultSelected(args, bool) {
- var t = this;
- if (!t.checkInited()) return;
- if (!Array.isArray(args)) {
- args = [args];
- }
- if (bool == null) {
- t.multSelected = args;
- } else {
- var listId, sub;
- if (bool) {
- for (var n = args.length - 1; n >= 0; n--) {
- listId = args[n];
- sub = t.multSelected.indexOf(listId);
- if (sub < 0) {
- t.multSelected.push(listId);
- }
- }
- } else {
- for (var _n3 = args.length - 1; _n3 >= 0; _n3--) {
- listId = args[_n3];
- sub = t.multSelected.indexOf(listId);
- if (sub >= 0) {
- t.multSelected.splice(sub, 1);
- }
- }
- }
- }
- t._forceUpdate = true;
- t._onScrolling();
- }
- /**
- * 获取多选数据
- * @returns
- */
- getMultSelected() {
- return this.multSelected;
- }
- /**
- * 多选是否有选择
- * @param {number} listId 索引
- * @returns
- */
- hasMultSelected(listId) {
- return this.multSelected && this.multSelected.indexOf(listId) >= 0;
- }
- /**
- * 更新指定的Item
- * @param {Array} args 单个listId,或者数组
- * @returns
- */
- updateItem(args) {
- if (!this.checkInited()) return;
- if (!Array.isArray(args)) {
- args = [args];
- }
- for (var n = 0, len = args.length; n < len; n++) {
- var listId = args[n];
- var item = this.getItemByListId(listId);
- if (item) EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
- }
- }
- /**
- * 更新全部
- */
- updateAll() {
- if (!this.checkInited()) return;
- this.numItems = this.numItems;
- }
- /**
- * 根据ListID获取Item
- * @param {Number} listId
- * @returns
- */
- getItemByListId(listId) {
- if (this.content) {
- for (var n = this.content.children.length - 1; n >= 0; n--) {
- var item = this.content.children[n];
- if (item._listId == listId) return item;
- }
- }
- }
- /**
- * 获取在显示区域外的Item
- * @returns
- */
- _getOutsideItem() {
- var item;
- var result = [];
- for (var n = this.content.children.length - 1; n >= 0; n--) {
- item = this.content.children[n];
- if (!this.displayData.find(d => d.id == item._listId)) {
- result.push(item);
- }
- }
- return result;
- } //删除显示区域以外的Item
- _delRedundantItem() {
- if (this._virtual) {
- var arr = this._getOutsideItem();
- for (var n = arr.length - 1; n >= 0; n--) {
- var item = arr[n];
- if (this._scrollItem && item._listId == this._scrollItem._listId) continue;
- item.isCached = true;
- (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).putNode(item);
- for (var m = this._lastDisplayData.length - 1; m >= 0; m--) {
- if (this._lastDisplayData[m] == item._listId) {
- this._lastDisplayData.splice(m, 1);
- break;
- }
- }
- } // cc.log('存入::', str, ' pool.length =', this._pool.length);
- } else {
- while (this.content.children.length > this._numItems) {
- this._delSingleItem(this.content.children[this.content.children.length - 1]);
- }
- }
- } //删除单个Item
- _delSingleItem(item) {
- // cc.log('DEL::', item['_listId'], item);
- item.removeFromParent();
- if (item.destroy) item.destroy();
- item = null;
- }
- /**
- * 动效删除Item(此方法只适用于虚拟列表,即_virtual=true)
- * 一定要在回调函数里重新设置新的numItems进行刷新,毕竟本List是靠数据驱动的。
- */
- aniDelItem(listId, callFunc, aniType) {
- var t = this;
- if (!t.checkInited() || t.cyclic || !t._virtual) return console.error('This function is not allowed to be called!');
- if (!callFunc) return console.error('CallFunc are not allowed to be NULL, You need to delete the corresponding index in the data array in the CallFunc!');
- if (t._aniDelRuning) return console.warn('Please wait for the current deletion to finish!');
- var item = t.getItemByListId(listId);
- var listItem;
- if (!item) {
- callFunc(listId);
- return;
- } else {
- listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
- error: Error()
- }), ListItem) : ListItem);
- }
- t._aniDelRuning = true;
- t._aniDelCB = callFunc;
- t._aniDelItem = item;
- t._aniDelBeforePos = item.position;
- t._aniDelBeforeScale = item.scale;
- var curLastId = t.displayData[t.displayData.length - 1].id;
- var resetSelectedId = listItem.selected;
- listItem.showAni(aniType, () => {
- //判断有没有下一个,如果有的话,创建粗来
- var newId;
- if (curLastId < t._numItems - 2) {
- newId = curLastId + 1;
- }
- if (newId != null) {
- var newData = t._calcItemPos(newId);
- t.displayData.push(newData);
- if (t._virtual) t._createOrUpdateItem(newData);else t._createOrUpdateItem2(newId);
- } else t._numItems--;
- if (t.selectedMode == SelectedType.SINGLE) {
- if (resetSelectedId) {
- t._selectedId = -1;
- } else if (t._selectedId - 1 >= 0) {
- t._selectedId--;
- }
- } else if (t.selectedMode == SelectedType.MULT && t.multSelected.length) {
- var sub = t.multSelected.indexOf(listId);
- if (sub >= 0) {
- t.multSelected.splice(sub, 1);
- } //多选的数据,在其后的全部减一
- for (var n = t.multSelected.length - 1; n >= 0; n--) {
- var id = t.multSelected[n];
- if (id >= listId) t.multSelected[n]--;
- }
- }
- if (t._customSize) {
- if (t._customSize[listId]) delete t._customSize[listId];
- var newCustomSize = {};
- var size;
- for (var _id in t._customSize) {
- size = t._customSize[_id];
- var idNumber = parseInt(_id);
- newCustomSize[idNumber - (idNumber >= listId ? 1 : 0)] = size;
- }
- t._customSize = newCustomSize;
- } //后面的Item向前怼的动效
- var sec = .2333;
- var twe, haveCB;
- for (var _n4 = newId != null ? newId : curLastId; _n4 >= listId + 1; _n4--) {
- item = t.getItemByListId(_n4);
- if (item) {
- var posData = t._calcItemPos(_n4 - 1);
- twe = tween(item).to(sec, {
- position: new Vec3(posData.x, posData.y, 0)
- });
- if (_n4 <= listId + 1) {
- haveCB = true;
- twe.call(() => {
- t._aniDelRuning = false;
- callFunc(listId);
- delete t._aniDelCB;
- });
- }
- twe.start();
- }
- }
- if (!haveCB) {
- t._aniDelRuning = false;
- callFunc(listId);
- t._aniDelCB = null;
- }
- }, true);
- }
- /**
- * 滚动到..
- * @param {Number} listId 索引(如果<0,则滚到首个Item位置,如果>=_numItems,则滚到最末Item位置)
- * @param {Number} timeInSecond 时间
- * @param {Number} offset 索引目标位置偏移,0-1
- * @param {Boolean} overStress 滚动后是否强调该Item(这只是个实验功能)
- */
- scrollTo(listId, timeInSecond, offset, overStress) {
- if (timeInSecond === void 0) {
- timeInSecond = .5;
- }
- if (offset === void 0) {
- offset = null;
- }
- if (overStress === void 0) {
- overStress = false;
- }
- var t = this;
- if (!t.checkInited(false)) return; // t._scrollView.stopAutoScroll();
- if (timeInSecond == null) //默认0.5
- timeInSecond = .5;else if (timeInSecond < 0) timeInSecond = 0;
- if (listId < 0) listId = 0;else if (listId >= t._numItems) listId = t._numItems - 1; // 以防设置了numItems之后layout的尺寸还未更新
- if (!t._virtual && t._layout && t._layout.enabled) t._layout.updateLayout();
- var pos = t.getItemPos(listId);
- if (!pos) {
- return DEV && console.error('pos is null', listId);
- }
- var targetX, targetY;
- switch (t._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- targetX = pos.left;
- if (offset != null) targetX -= t._thisNodeUt.width * offset;else targetX -= t._leftGap;
- pos = new Vec3(targetX, 0, 0);
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- targetX = pos.right - t._thisNodeUt.width;
- if (offset != null) targetX += t._thisNodeUt.width * offset;else targetX += t._rightGap;
- pos = new Vec3(targetX + t._contentUt.width, 0, 0);
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- targetY = pos.top;
- if (offset != null) targetY += t._thisNodeUt.height * offset;else targetY += t._topGap;
- pos = new Vec3(0, -targetY, 0);
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- targetY = pos.bottom + t._thisNodeUt.height;
- if (offset != null) targetY -= t._thisNodeUt.height * offset;else targetY -= t._bottomGap;
- pos = new Vec3(0, -targetY + t._contentUt.height, 0);
- break;
- }
- var viewPos = t.content.getPosition();
- viewPos = Math.abs(t._sizeType ? viewPos.y : viewPos.x);
- var comparePos = t._sizeType ? pos.y : pos.x;
- var runScroll = Math.abs((t._scrollPos != null ? t._scrollPos : viewPos) - comparePos) > .5; // cc.log(runScroll, t._scrollPos, viewPos, comparePos)
- // t._scrollView.stopAutoScroll();
- if (runScroll) {
- t._scrollView.scrollToOffset(pos, timeInSecond);
- t._scrollToListId = listId;
- t._scrollToEndTime = new Date().getTime() / 1000 + timeInSecond; // cc.log(listId, t.content.width, t.content.getPosition(), pos);
- t._scrollToSo = t.scheduleOnce(() => {
- if (!t._adheringBarrier) {
- t.adhering = t._adheringBarrier = false;
- }
- t._scrollPos = t._scrollToListId = t._scrollToEndTime = t._scrollToSo = null; //cc.log('2222222222', t._adheringBarrier)
- if (overStress) {
- // t.scrollToListId = listId;
- var item = t.getItemByListId(listId);
- if (item) {
- tween(item).to(.1, {
- scale: 1.05
- }).to(.1, {
- scale: 1
- }).start();
- }
- }
- }, timeInSecond + .1);
- if (timeInSecond <= 0) {
- t._onScrolling();
- }
- }
- }
- /**
- * 计算当前滚动窗最近的Item
- */
- _calcNearestItem() {
- var t = this;
- t.nearestListId = null;
- var data, center;
- if (t._virtual) t._calcViewPos();
- var vTop, vRight, vBottom, vLeft;
- vTop = t.viewTop;
- vRight = t.viewRight;
- vBottom = t.viewBottom;
- vLeft = t.viewLeft;
- var breakFor = false;
- for (var n = 0; n < t.content.children.length && !breakFor; n += t._colLineNum) {
- data = t._virtual ? t.displayData[n] : t._calcExistItemPos(n);
- if (data) {
- center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
- switch (t._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- if (data.right >= vLeft) {
- t.nearestListId = data.id;
- if (vLeft > center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- if (data.left <= vRight) {
- t.nearestListId = data.id;
- if (vRight < center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (data.bottom <= vTop) {
- t.nearestListId = data.id;
- if (vTop < center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (data.top >= vBottom) {
- t.nearestListId = data.id;
- if (vBottom > center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- }
- }
- } //判断最后一个Item。。。(哎,这些判断真心恶心,判断了前面的还要判断最后一个。。。一开始呢,就只有一个布局(单列布局),那时候代码才三百行,后来就想着完善啊,艹..这坑真深,现在这行数都一千五了= =||)
- data = t._virtual ? t.displayData[t.displayItemNum - 1] : t._calcExistItemPos(t._numItems - 1);
- if (data && data.id == t._numItems - 1) {
- center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
- switch (t._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- if (vRight > center) t.nearestListId = data.id;
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- if (vLeft < center) t.nearestListId = data.id;
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (vBottom < center) t.nearestListId = data.id;
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (vTop > center) t.nearestListId = data.id;
- break;
- }
- } // cc.log('t.nearestListId =', t.nearestListId);
- } //上一页
- prePage(timeInSecond) {
- if (timeInSecond === void 0) {
- timeInSecond = .5;
- }
- // cc.log('👈');
- if (!this.checkInited()) return;
- this.skipPage(this.curPageNum - 1, timeInSecond);
- } //下一页
- nextPage(timeInSecond) {
- if (timeInSecond === void 0) {
- timeInSecond = .5;
- }
- // cc.log('👉');
- if (!this.checkInited()) return;
- this.skipPage(this.curPageNum + 1, timeInSecond);
- } //跳转到第几页
- skipPage(pageNum, timeInSecond) {
- var t = this;
- if (!t.checkInited()) return;
- if (t._slideMode != SlideType.PAGE) return console.error('This function is not allowed to be called, Must SlideMode = PAGE!');
- if (pageNum < 0 || pageNum >= t._numItems) return;
- if (t.curPageNum == pageNum) return; // cc.log(pageNum);
- t.curPageNum = pageNum;
- if (t.pageChangeEvent) {
- EventHandler.emitEvents([t.pageChangeEvent], pageNum);
- }
- t.scrollTo(pageNum, timeInSecond);
- } //计算 CustomSize(这个函数还是保留吧,某些罕见的情况的确还是需要手动计算customSize的)
- calcCustomSize(numItems) {
- var t = this;
- if (!t.checkInited()) return;
- if (!t._itemTmp) return console.error('Unset template item!');
- if (!t.renderEvent) return console.error('Unset Render-Event!');
- t._customSize = {};
- var temp = (_crd && PoolManager === void 0 ? (_reportPossibleCrUseOfPoolManager({
- error: Error()
- }), PoolManager) : PoolManager).getNode(t._itemTmp, t.content);
- var ut = temp.getComponent(UITransform);
- for (var n = 0; n < numItems; n++) {
- EventHandler.emitEvents([t.renderEvent], temp, n);
- if (ut.height != t._itemSize.height || ut.width != t._itemSize.width) {
- t._customSize[n] = t._sizeType ? ut.height : ut.width;
- }
- }
- if (!Object.keys(t._customSize).length) t._customSize = null;
- temp.removeFromParent();
- if (temp.destroy) temp.destroy();
- return t._customSize;
- }
- }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "templateType", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return TemplateType.NODE;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tmpNode", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "tmpPrefab", [_dec7], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_slideMode", [_dec8], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return SlideType.NORMAL;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "slideMode", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "slideMode"), _class2.prototype), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "pageDistance", [_dec10], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return .3;
- }
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "pageChangeEvent", [_dec11], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new EventHandler();
- }
- }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "_virtual", [_dec12], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return true;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "virtual", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "virtual"), _class2.prototype), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "cyclic", [_dec14], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "lackCenter", [_dec15], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "lackSlide", [_dec16], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "_updateRate", [_dec17], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "updateRate", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "updateRate"), _class2.prototype), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "frameByFrameRenderNum", [_dec19], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "renderEvent", [_dec20], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new EventHandler();
- }
- }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "selectedMode", [_dec21], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return SelectedType.NONE;
- }
- }), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "selectedEvent", [_dec22], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new EventHandler();
- }
- }), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "repeatEventSingle", [_dec23], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "_numItems", [_dec24], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- })), _class2)) || _class) || _class) || _class) || _class) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=56ae9e35797d5e8240d73f72d113dd7717d70dd2.js.map
|