122ae41024fa99aa4949a176919256851ded60b7.js 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619
  1. System.register(["__unresolved_0", "cc", "cc/env", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, Component, Enum, tween, _decorator, EventHandler, ScrollView, Prefab, Layout, Size, NodePool, isValid, instantiate, Vec3, Widget, UITransform, CCFloat, CCBoolean, CCInteger, DEV, ListItem, _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;
  4. 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 }); }
  5. 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; }
  6. 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.'); }
  7. function _reportPossibleCrUseOfListItem(extras) {
  8. _reporterNs.report("ListItem", "./ListItem", _context.meta, extras);
  9. }
  10. return {
  11. setters: [function (_unresolved_) {
  12. _reporterNs = _unresolved_;
  13. }, function (_cc) {
  14. _cclegacy = _cc.cclegacy;
  15. __checkObsolete__ = _cc.__checkObsolete__;
  16. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  17. Node = _cc.Node;
  18. Component = _cc.Component;
  19. Enum = _cc.Enum;
  20. tween = _cc.tween;
  21. _decorator = _cc._decorator;
  22. EventHandler = _cc.EventHandler;
  23. ScrollView = _cc.ScrollView;
  24. Prefab = _cc.Prefab;
  25. Layout = _cc.Layout;
  26. Size = _cc.Size;
  27. NodePool = _cc.NodePool;
  28. isValid = _cc.isValid;
  29. instantiate = _cc.instantiate;
  30. Vec3 = _cc.Vec3;
  31. Widget = _cc.Widget;
  32. UITransform = _cc.UITransform;
  33. CCFloat = _cc.CCFloat;
  34. CCBoolean = _cc.CCBoolean;
  35. CCInteger = _cc.CCInteger;
  36. }, function (_ccEnv) {
  37. DEV = _ccEnv.DEV;
  38. }, function (_unresolved_2) {
  39. ListItem = _unresolved_2.default;
  40. }],
  41. execute: function () {
  42. _crd = true;
  43. _cclegacy._RF.push({}, "30e50g9bStDgYX3Y3vvH6ye", "List", undefined);
  44. /******************************************
  45. * @author kL <klk0@qq.com>
  46. * @date 2020/12/9
  47. * @doc 列表组件.
  48. * @end
  49. ******************************************/
  50. ({
  51. ccclass,
  52. property,
  53. disallowMultiple,
  54. menu,
  55. executionOrder,
  56. requireComponent
  57. } = _decorator);
  58. __checkObsolete__(['Node', 'Component', 'Enum', 'tween', '_decorator', 'EventHandler', 'Tween', 'ScrollView', 'Prefab', 'Layout', 'Vec2', 'Size', 'NodePool', 'isValid', 'instantiate', 'Vec3', 'Widget', 'UITransform', 'CCFloat', 'CCBoolean', 'CCInteger']);
  59. TemplateType = /*#__PURE__*/function (TemplateType) {
  60. TemplateType[TemplateType["NODE"] = 1] = "NODE";
  61. TemplateType[TemplateType["PREFAB"] = 2] = "PREFAB";
  62. return TemplateType;
  63. }(TemplateType || {});
  64. SlideType = /*#__PURE__*/function (SlideType) {
  65. SlideType[SlideType["NORMAL"] = 1] = "NORMAL";
  66. SlideType[SlideType["ADHERING"] = 2] = "ADHERING";
  67. SlideType[SlideType["PAGE"] = 3] = "PAGE";
  68. return SlideType;
  69. }(SlideType || {});
  70. SelectedType = /*#__PURE__*/function (SelectedType) {
  71. SelectedType[SelectedType["NONE"] = 0] = "NONE";
  72. SelectedType[SelectedType["SINGLE"] = 1] = "SINGLE";
  73. SelectedType[SelectedType["MULT"] = 2] = "MULT";
  74. return SelectedType;
  75. }(SelectedType || {});
  76. _export("default", List = (_dec = disallowMultiple(), _dec2 = menu('List'), _dec3 = requireComponent(ScrollView), _dec4 = executionOrder(-5000), _dec5 = property({
  77. type: Enum(TemplateType),
  78. tooltip: DEV && '模板类型'
  79. }), _dec6 = property({
  80. type: Node,
  81. tooltip: DEV && '模板Item',
  82. visible() {
  83. return this.templateType == TemplateType.NODE;
  84. }
  85. }), _dec7 = property({
  86. type: Prefab,
  87. tooltip: DEV && '模板Item',
  88. visible() {
  89. return this.templateType == TemplateType.PREFAB;
  90. }
  91. }), _dec8 = property({}), _dec9 = property({
  92. type: Enum(SlideType),
  93. tooltip: DEV && '滑动模式'
  94. }), _dec10 = property({
  95. type: CCFloat,
  96. range: [0, 1, .1],
  97. tooltip: DEV && '翻页作用距离',
  98. slide: true,
  99. visible() {
  100. return this._slideMode == SlideType.PAGE;
  101. }
  102. }), _dec11 = property({
  103. type: EventHandler,
  104. tooltip: DEV && '页面改变事件',
  105. visible() {
  106. return this._slideMode == SlideType.PAGE;
  107. }
  108. }), _dec12 = property({}), _dec13 = property({
  109. type: CCBoolean,
  110. tooltip: DEV && '是否为虚拟列表(动态列表)'
  111. }), _dec14 = property({
  112. tooltip: DEV && '是否为循环列表',
  113. visible() {
  114. let val =
  115. /*this.virtual &&*/
  116. this.slideMode == SlideType.NORMAL;
  117. if (!val) this.cyclic = false;
  118. return val;
  119. }
  120. }), _dec15 = property({
  121. tooltip: DEV && 'Item数量不足以填满Content时,是否居中显示Item(不支持Grid布局)',
  122. visible() {
  123. return this.virtual;
  124. }
  125. }), _dec16 = property({
  126. tooltip: DEV && 'Item数量不足以填满Content时,是否可滑动',
  127. visible() {
  128. let val = this.virtual && !this.lackCenter;
  129. if (!val) this.lackSlide = false;
  130. return val;
  131. }
  132. }), _dec17 = property({
  133. type: CCInteger
  134. }), _dec18 = property({
  135. type: CCInteger,
  136. range: [0, 6, 1],
  137. tooltip: DEV && '刷新频率(值越大刷新频率越低、性能越高)',
  138. slide: true
  139. }), _dec19 = property({
  140. type: CCInteger,
  141. range: [0, 12, 1],
  142. tooltip: DEV && '逐帧渲染时,每帧渲染的Item数量(<=0时关闭分帧渲染)',
  143. slide: true
  144. }), _dec20 = property({
  145. type: EventHandler,
  146. tooltip: DEV && '渲染事件(渲染器)'
  147. }), _dec21 = property({
  148. type: Enum(SelectedType),
  149. tooltip: DEV && '选择模式'
  150. }), _dec22 = property({
  151. type: EventHandler,
  152. tooltip: DEV && '触发选择事件',
  153. visible() {
  154. return this.selectedMode > SelectedType.NONE;
  155. }
  156. }), _dec23 = property({
  157. tooltip: DEV && '是否重复响应单选事件',
  158. visible() {
  159. return this.selectedMode == SelectedType.SINGLE;
  160. }
  161. }), _dec24 = property({
  162. serializable: false
  163. }), ccclass(_class = _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = (_class2 = class List extends Component {
  164. constructor(...args) {
  165. super(...args);
  166. //模板类型
  167. _initializerDefineProperty(this, "templateType", _descriptor, this);
  168. //模板Item(Node)
  169. _initializerDefineProperty(this, "tmpNode", _descriptor2, this);
  170. //模板Item(Prefab)
  171. _initializerDefineProperty(this, "tmpPrefab", _descriptor3, this);
  172. //滑动模式
  173. _initializerDefineProperty(this, "_slideMode", _descriptor4, this);
  174. //翻页作用距离
  175. _initializerDefineProperty(this, "pageDistance", _descriptor5, this);
  176. //页面改变事件
  177. _initializerDefineProperty(this, "pageChangeEvent", _descriptor6, this);
  178. //是否为虚拟列表(动态列表)
  179. _initializerDefineProperty(this, "_virtual", _descriptor7, this);
  180. //是否为循环列表
  181. _initializerDefineProperty(this, "cyclic", _descriptor8, this);
  182. //缺省居中
  183. _initializerDefineProperty(this, "lackCenter", _descriptor9, this);
  184. //缺省可滑动
  185. _initializerDefineProperty(this, "lackSlide", _descriptor10, this);
  186. //刷新频率
  187. _initializerDefineProperty(this, "_updateRate", _descriptor11, this);
  188. //分帧渲染(每帧渲染的Item数量(<=0时关闭分帧渲染))
  189. _initializerDefineProperty(this, "frameByFrameRenderNum", _descriptor12, this);
  190. //渲染事件(渲染器)
  191. _initializerDefineProperty(this, "renderEvent", _descriptor13, this);
  192. //选择模式
  193. _initializerDefineProperty(this, "selectedMode", _descriptor14, this);
  194. //触发选择事件
  195. _initializerDefineProperty(this, "selectedEvent", _descriptor15, this);
  196. _initializerDefineProperty(this, "repeatEventSingle", _descriptor16, this);
  197. //当前选择id
  198. this._selectedId = -1;
  199. this._lastSelectedId = void 0;
  200. this.multSelected = void 0;
  201. this._forceUpdate = false;
  202. this._align = void 0;
  203. this._horizontalDir = void 0;
  204. this._verticalDir = void 0;
  205. this._startAxis = void 0;
  206. this._alignCalcType = void 0;
  207. this.content = void 0;
  208. this._contentUt = void 0;
  209. this.firstListId = void 0;
  210. this.displayItemNum = void 0;
  211. this._updateDone = true;
  212. this._updateCounter = void 0;
  213. this._actualNumItems = void 0;
  214. this._cyclicNum = void 0;
  215. this._cyclicPos1 = void 0;
  216. this._cyclicPos2 = void 0;
  217. //列表数量
  218. _initializerDefineProperty(this, "_numItems", _descriptor17, this);
  219. this._inited = false;
  220. this._scrollView = void 0;
  221. this._layout = void 0;
  222. this._resizeMode = void 0;
  223. this._topGap = void 0;
  224. this._rightGap = void 0;
  225. this._bottomGap = void 0;
  226. this._leftGap = void 0;
  227. this._columnGap = void 0;
  228. this._lineGap = void 0;
  229. this._colLineNum = void 0;
  230. this._lastDisplayData = void 0;
  231. this.displayData = void 0;
  232. this._pool = void 0;
  233. this._itemTmp = void 0;
  234. this._itemTmpUt = void 0;
  235. this._needUpdateWidget = false;
  236. this._itemSize = void 0;
  237. this._sizeType = void 0;
  238. this._customSize = void 0;
  239. this.frameCount = void 0;
  240. this._aniDelRuning = false;
  241. this._aniDelCB = void 0;
  242. this._aniDelItem = void 0;
  243. this._aniDelBeforePos = void 0;
  244. this._aniDelBeforeScale = void 0;
  245. this.viewTop = void 0;
  246. this.viewRight = void 0;
  247. this.viewBottom = void 0;
  248. this.viewLeft = void 0;
  249. this._doneAfterUpdate = false;
  250. this.elasticTop = void 0;
  251. this.elasticRight = void 0;
  252. this.elasticBottom = void 0;
  253. this.elasticLeft = void 0;
  254. this.scrollToListId = void 0;
  255. this.adhering = false;
  256. this._adheringBarrier = false;
  257. this.nearestListId = void 0;
  258. this.curPageNum = 0;
  259. this._beganPos = void 0;
  260. this._scrollPos = void 0;
  261. this._curScrollIsTouch = void 0;
  262. //当前滑动是否为手动
  263. this._scrollToListId = void 0;
  264. this._scrollToEndTime = void 0;
  265. this._scrollToSo = void 0;
  266. this._lack = void 0;
  267. this._allItemSize = void 0;
  268. this._allItemSizeNoEdge = void 0;
  269. this._scrollItem = void 0;
  270. //当前控制 ScrollView 滚动的 Item
  271. this._thisNodeUt = void 0;
  272. }
  273. set slideMode(val) {
  274. this._slideMode = val;
  275. }
  276. get slideMode() {
  277. return this._slideMode;
  278. }
  279. set virtual(val) {
  280. if (val != null) this._virtual = val;
  281. if (!DEV && this._numItems != 0) {
  282. this._onScrolling();
  283. }
  284. }
  285. get virtual() {
  286. return this._virtual;
  287. }
  288. set updateRate(val) {
  289. if (val >= 0 && val <= 6) {
  290. this._updateRate = val;
  291. }
  292. }
  293. get updateRate() {
  294. return this._updateRate;
  295. }
  296. set selectedId(val) {
  297. let t = this;
  298. let item;
  299. switch (t.selectedMode) {
  300. case SelectedType.SINGLE:
  301. {
  302. if (!t.repeatEventSingle && val == t._selectedId) return;
  303. item = t.getItemByListId(val); // if (!item && val >= 0)
  304. // return;
  305. let listItem;
  306. if (t._selectedId >= 0) t._lastSelectedId = t._selectedId;else //如果<0则取消选择,把_lastSelectedId也置空吧,如果以后有特殊需求再改吧。
  307. t._lastSelectedId = null;
  308. t._selectedId = val;
  309. if (item) {
  310. listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  311. error: Error()
  312. }), ListItem) : ListItem);
  313. listItem.selected = true;
  314. }
  315. if (t._lastSelectedId >= 0 && t._lastSelectedId != t._selectedId) {
  316. let lastItem = t.getItemByListId(t._lastSelectedId);
  317. if (lastItem) {
  318. lastItem.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  319. error: Error()
  320. }), ListItem) : ListItem).selected = false;
  321. }
  322. }
  323. if (t.selectedEvent) {
  324. EventHandler.emitEvents([t.selectedEvent], item, val % this._actualNumItems, t._lastSelectedId == null ? null : t._lastSelectedId % this._actualNumItems);
  325. }
  326. break;
  327. }
  328. case SelectedType.MULT:
  329. {
  330. item = t.getItemByListId(val);
  331. if (!item) return;
  332. let listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  333. error: Error()
  334. }), ListItem) : ListItem);
  335. if (t._selectedId >= 0) t._lastSelectedId = t._selectedId;
  336. t._selectedId = val;
  337. let bool = !listItem.selected;
  338. listItem.selected = bool;
  339. let sub = t.multSelected.indexOf(val);
  340. if (bool && sub < 0) {
  341. t.multSelected.push(val);
  342. } else if (!bool && sub >= 0) {
  343. t.multSelected.splice(sub, 1);
  344. }
  345. if (t.selectedEvent) {
  346. EventHandler.emitEvents([t.selectedEvent], item, val % this._actualNumItems, t._lastSelectedId == null ? null : t._lastSelectedId % this._actualNumItems, bool);
  347. }
  348. break;
  349. }
  350. }
  351. }
  352. get selectedId() {
  353. return this._selectedId;
  354. }
  355. set numItems(val) {
  356. let t = this;
  357. if (!t.checkInited(false)) return;
  358. if (val == null || val < 0) {
  359. console.error('numItems set the wrong::', val);
  360. return;
  361. }
  362. t._actualNumItems = t._numItems = val;
  363. t._forceUpdate = true;
  364. if (t._virtual) {
  365. t._resizeContent();
  366. if (t.cyclic) {
  367. t._numItems = t._cyclicNum * t._numItems;
  368. }
  369. t._onScrolling();
  370. if (!t.frameByFrameRenderNum && t.slideMode == SlideType.PAGE) t.curPageNum = t.nearestListId;
  371. } else {
  372. if (t.cyclic) {
  373. t._resizeContent();
  374. t._numItems = t._cyclicNum * t._numItems;
  375. }
  376. let layout = t.content.getComponent(Layout);
  377. if (layout) {
  378. layout.enabled = true;
  379. }
  380. t._delRedundantItem();
  381. t.firstListId = 0;
  382. if (t.frameByFrameRenderNum > 0) {
  383. //先渲染几个出来
  384. let len = t.frameByFrameRenderNum > t._numItems ? t._numItems : t.frameByFrameRenderNum;
  385. for (let n = 0; n < len; n++) {
  386. t._createOrUpdateItem2(n);
  387. }
  388. if (t.frameByFrameRenderNum < t._numItems) {
  389. t._updateCounter = t.frameByFrameRenderNum;
  390. t._updateDone = false;
  391. }
  392. } else {
  393. for (let n = 0; n < t._numItems; n++) {
  394. t._createOrUpdateItem2(n);
  395. }
  396. t.displayItemNum = t._numItems;
  397. }
  398. }
  399. }
  400. get numItems() {
  401. return this._actualNumItems;
  402. }
  403. get scrollView() {
  404. return this._scrollView;
  405. }
  406. //----------------------------------------------------------------------------
  407. onLoad() {
  408. this._init();
  409. }
  410. onDestroy() {
  411. let t = this;
  412. if (isValid(t._itemTmp)) t._itemTmp.destroy();
  413. if (isValid(t.tmpNode)) t.tmpNode.destroy();
  414. t._pool && t._pool.clear();
  415. }
  416. onEnable() {
  417. // if (!EDITOR)
  418. this._registerEvent();
  419. this._init(); // 处理重新显示后,有可能上一次的动画移除还未播放完毕,导致动画卡住的问题
  420. if (this._aniDelRuning) {
  421. this._aniDelRuning = false;
  422. if (this._aniDelItem) {
  423. if (this._aniDelBeforePos) {
  424. this._aniDelItem.position = this._aniDelBeforePos;
  425. delete this._aniDelBeforePos;
  426. }
  427. if (this._aniDelBeforeScale) {
  428. this._aniDelItem.scale = this._aniDelBeforeScale;
  429. delete this._aniDelBeforeScale;
  430. }
  431. delete this._aniDelItem;
  432. }
  433. if (this._aniDelCB) {
  434. this._aniDelCB();
  435. delete this._aniDelCB;
  436. }
  437. }
  438. }
  439. onDisable() {
  440. // if (!EDITOR)
  441. this._unregisterEvent();
  442. } //注册事件
  443. _registerEvent() {
  444. let t = this;
  445. t.node.on(Node.EventType.TOUCH_START, t._onTouchStart, t);
  446. t.node.on('touch-up', t._onTouchUp, t);
  447. t.node.on(Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t);
  448. t.node.on('scroll-began', t._onScrollBegan, t);
  449. t.node.on('scroll-ended', t._onScrollEnded, t);
  450. t.node.on('scrolling', t._onScrolling, t);
  451. t.node.on(Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
  452. } //卸载事件
  453. _unregisterEvent() {
  454. let t = this;
  455. t.node.off(Node.EventType.TOUCH_START, t._onTouchStart, t);
  456. t.node.off('touch-up', t._onTouchUp, t);
  457. t.node.off(Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t);
  458. t.node.off('scroll-began', t._onScrollBegan, t);
  459. t.node.off('scroll-ended', t._onScrollEnded, t);
  460. t.node.off('scrolling', t._onScrolling, t);
  461. t.node.off(Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
  462. } //初始化各种..
  463. _init() {
  464. let t = this;
  465. if (t._inited) return;
  466. t._thisNodeUt = t.node.getComponent(UITransform);
  467. t._scrollView = t.node.getComponent(ScrollView);
  468. t.content = t._scrollView.content;
  469. t._contentUt = t.content.getComponent(UITransform);
  470. if (!t.content) {
  471. console.error(t.node.name + "'s ScrollView unset content!");
  472. return;
  473. }
  474. t._layout = t.content.getComponent(Layout);
  475. t._align = t._layout.type; //排列模式
  476. t._resizeMode = t._layout.resizeMode; //自适应模式
  477. t._startAxis = t._layout.startAxis;
  478. t._topGap = t._layout.paddingTop; //顶边距
  479. t._rightGap = t._layout.paddingRight; //右边距
  480. t._bottomGap = t._layout.paddingBottom; //底边距
  481. t._leftGap = t._layout.paddingLeft; //左边距
  482. t._columnGap = t._layout.spacingX; //列距
  483. t._lineGap = t._layout.spacingY; //行距
  484. t._colLineNum; //列数或行数(非GRID模式则=1,表示单列或单行);
  485. t._verticalDir = t._layout.verticalDirection; //垂直排列子节点的方向
  486. t._horizontalDir = t._layout.horizontalDirection; //水平排列子节点的方向
  487. t.setTemplateItem(instantiate(t.templateType == TemplateType.PREFAB ? t.tmpPrefab : t.tmpNode)); // 特定的滑动模式处理
  488. if (t._slideMode == SlideType.ADHERING || t._slideMode == SlideType.PAGE) {
  489. t._scrollView.inertia = false;
  490. t._scrollView._onMouseWheel = function () {
  491. return;
  492. };
  493. }
  494. if (!t.virtual) // lackCenter 仅支持 Virtual 模式
  495. t.lackCenter = false;
  496. t._lastDisplayData = []; //最后一次刷新的数据
  497. t.displayData = []; //当前数据
  498. t._pool = new NodePool(); //这是个池子..
  499. t._forceUpdate = false; //是否强制更新
  500. t._updateCounter = 0; //当前分帧渲染帧数
  501. t._updateDone = true; //分帧渲染是否完成
  502. t.curPageNum = 0; //当前页数
  503. if (t.cyclic || 0) {
  504. t._scrollView._processAutoScrolling = this._processAutoScrolling.bind(t);
  505. t._scrollView._startBounceBackIfNeeded = function () {
  506. return false;
  507. };
  508. }
  509. switch (t._align) {
  510. case Layout.Type.HORIZONTAL:
  511. {
  512. switch (t._horizontalDir) {
  513. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  514. t._alignCalcType = 1;
  515. break;
  516. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  517. t._alignCalcType = 2;
  518. break;
  519. }
  520. break;
  521. }
  522. case Layout.Type.VERTICAL:
  523. {
  524. switch (t._verticalDir) {
  525. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  526. t._alignCalcType = 3;
  527. break;
  528. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  529. t._alignCalcType = 4;
  530. break;
  531. }
  532. break;
  533. }
  534. case Layout.Type.GRID:
  535. {
  536. switch (t._startAxis) {
  537. case Layout.AxisDirection.HORIZONTAL:
  538. switch (t._verticalDir) {
  539. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  540. t._alignCalcType = 3;
  541. break;
  542. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  543. t._alignCalcType = 4;
  544. break;
  545. }
  546. break;
  547. case Layout.AxisDirection.VERTICAL:
  548. switch (t._horizontalDir) {
  549. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  550. t._alignCalcType = 1;
  551. break;
  552. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  553. t._alignCalcType = 2;
  554. break;
  555. }
  556. break;
  557. }
  558. break;
  559. }
  560. } // 清空 content
  561. // t.content.children.forEach((child: Node) => {
  562. // child.removeFromParent();
  563. // if (child != t.tmpNode && child.isValid)
  564. // child.destroy();
  565. // });
  566. t.content.removeAllChildren();
  567. t._inited = true;
  568. }
  569. /**
  570. * 为了实现循环列表,必须覆写cc.ScrollView的某些函数
  571. * @param {Number} dt
  572. */
  573. _processAutoScrolling(dt) {
  574. // ------------- scroll-view 里定义的一些常量 -------------
  575. const OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05;
  576. const EPSILON = 1e-4;
  577. const ZERO = new Vec3();
  578. const quintEaseOut = time => {
  579. time -= 1;
  580. return time * time * time * time * time + 1;
  581. }; // ------------- scroll-view 里定义的一些常量 -------------
  582. let sv = this._scrollView;
  583. const isAutoScrollBrake = sv['_isNecessaryAutoScrollBrake']();
  584. const brakingFactor = isAutoScrollBrake ? OUT_OF_BOUNDARY_BREAKING_FACTOR : 1;
  585. sv['_autoScrollAccumulatedTime'] += dt * (1 / brakingFactor);
  586. let percentage = Math.min(1, sv['_autoScrollAccumulatedTime'] / sv['_autoScrollTotalTime']);
  587. if (sv['_autoScrollAttenuate']) {
  588. percentage = quintEaseOut(percentage);
  589. }
  590. const clonedAutoScrollTargetDelta = sv['_autoScrollTargetDelta'].clone();
  591. clonedAutoScrollTargetDelta.multiplyScalar(percentage);
  592. const clonedAutoScrollStartPosition = sv['_autoScrollStartPosition'].clone();
  593. clonedAutoScrollStartPosition.add(clonedAutoScrollTargetDelta);
  594. let reachedEnd = Math.abs(percentage - 1) <= EPSILON;
  595. const fireEvent = Math.abs(percentage - 1) <= sv['getScrollEndedEventTiming']();
  596. if (fireEvent && !sv['_isScrollEndedWithThresholdEventFired']) {
  597. sv['_dispatchEvent'](ScrollView.EventType.SCROLL_ENG_WITH_THRESHOLD);
  598. sv['_isScrollEndedWithThresholdEventFired'] = true;
  599. }
  600. if (sv['elastic']) {
  601. const brakeOffsetPosition = clonedAutoScrollStartPosition.clone();
  602. brakeOffsetPosition.subtract(sv['_autoScrollBrakingStartPosition']);
  603. if (isAutoScrollBrake) {
  604. brakeOffsetPosition.multiplyScalar(brakingFactor);
  605. }
  606. clonedAutoScrollStartPosition.set(sv['_autoScrollBrakingStartPosition']);
  607. clonedAutoScrollStartPosition.add(brakeOffsetPosition);
  608. } else {
  609. const moveDelta = clonedAutoScrollStartPosition.clone();
  610. moveDelta.subtract(sv['_getContentPosition']());
  611. const outOfBoundary = sv['_getHowMuchOutOfBoundary'](moveDelta);
  612. if (!outOfBoundary.equals(ZERO, EPSILON)) {
  613. clonedAutoScrollStartPosition.add(outOfBoundary);
  614. reachedEnd = true;
  615. }
  616. }
  617. if (reachedEnd) {
  618. sv['_autoScrolling'] = false;
  619. }
  620. const deltaMove = new Vec3(clonedAutoScrollStartPosition);
  621. deltaMove.subtract(sv['_getContentPosition']());
  622. sv['_clampDelta'](deltaMove);
  623. sv['_moveContent'](deltaMove, reachedEnd);
  624. sv['_dispatchEvent'](ScrollView.EventType.SCROLLING);
  625. if (!sv['_autoScrolling']) {
  626. sv['_isBouncing'] = false;
  627. sv['_scrolling'] = false;
  628. sv['_dispatchEvent'](ScrollView.EventType.SCROLL_ENDED);
  629. }
  630. } //设置模板Item
  631. setTemplateItem(item) {
  632. if (!item) return;
  633. let t = this;
  634. t._itemTmp = item;
  635. t._itemTmpUt = item.getComponent(UITransform);
  636. if (t._resizeMode == Layout.ResizeMode.CHILDREN) t._itemSize = t._layout.cellSize;else {
  637. let itemUt = item.getComponent(UITransform);
  638. t._itemSize = new Size(itemUt.width, itemUt.height);
  639. } //获取ListItem,如果没有就取消选择模式
  640. let com = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  641. error: Error()
  642. }), ListItem) : ListItem);
  643. let remove = false;
  644. if (!com) remove = true; // if (com) {
  645. // if (!com._btnCom && !item.getComponent(cc.Button)) {
  646. // remove = true;
  647. // }
  648. // }
  649. if (remove) {
  650. t.selectedMode = SelectedType.NONE;
  651. }
  652. com = item.getComponent(Widget);
  653. if (com && com.enabled) {
  654. t._needUpdateWidget = true;
  655. }
  656. if (t.selectedMode == SelectedType.MULT) t.multSelected = [];
  657. switch (t._align) {
  658. case Layout.Type.HORIZONTAL:
  659. t._colLineNum = 1;
  660. t._sizeType = false;
  661. break;
  662. case Layout.Type.VERTICAL:
  663. t._colLineNum = 1;
  664. t._sizeType = true;
  665. break;
  666. case Layout.Type.GRID:
  667. switch (t._startAxis) {
  668. case Layout.AxisDirection.HORIZONTAL:
  669. //计算列数
  670. let trimW = t._contentUt.width - t._leftGap - t._rightGap;
  671. t._colLineNum = Math.floor((trimW + t._columnGap) / (t._itemSize.width + t._columnGap));
  672. t._sizeType = true;
  673. break;
  674. case Layout.AxisDirection.VERTICAL:
  675. //计算行数
  676. let trimH = t._contentUt.height - t._topGap - t._bottomGap;
  677. t._colLineNum = Math.floor((trimH + t._lineGap) / (t._itemSize.height + t._lineGap));
  678. t._sizeType = false;
  679. break;
  680. }
  681. break;
  682. }
  683. }
  684. /**
  685. * 检查是否初始化
  686. * @param {Boolean} printLog 是否打印错误信息
  687. * @returns
  688. */
  689. checkInited(printLog = true) {
  690. if (!this._inited) {
  691. if (printLog) console.error('List initialization not completed!');
  692. return false;
  693. }
  694. return true;
  695. } //禁用 Layout 组件,自行计算 Content Size
  696. _resizeContent() {
  697. let t = this;
  698. let result;
  699. switch (t._align) {
  700. case Layout.Type.HORIZONTAL:
  701. {
  702. if (t._customSize) {
  703. let fixed = t._getFixedSize(null);
  704. result = t._leftGap + fixed.val + t._itemSize.width * (t._numItems - fixed.count) + t._columnGap * (t._numItems - 1) + t._rightGap;
  705. } else {
  706. result = t._leftGap + t._itemSize.width * t._numItems + t._columnGap * (t._numItems - 1) + t._rightGap;
  707. }
  708. break;
  709. }
  710. case Layout.Type.VERTICAL:
  711. {
  712. if (t._customSize) {
  713. let fixed = t._getFixedSize(null);
  714. result = t._topGap + fixed.val + t._itemSize.height * (t._numItems - fixed.count) + t._lineGap * (t._numItems - 1) + t._bottomGap;
  715. } else {
  716. result = t._topGap + t._itemSize.height * t._numItems + t._lineGap * (t._numItems - 1) + t._bottomGap;
  717. }
  718. break;
  719. }
  720. case Layout.Type.GRID:
  721. {
  722. //网格模式不支持居中
  723. if (t.lackCenter) t.lackCenter = false;
  724. switch (t._startAxis) {
  725. case Layout.AxisDirection.HORIZONTAL:
  726. let lineNum = Math.ceil(t._numItems / t._colLineNum);
  727. result = t._topGap + t._itemSize.height * lineNum + t._lineGap * (lineNum - 1) + t._bottomGap;
  728. break;
  729. case Layout.AxisDirection.VERTICAL:
  730. let colNum = Math.ceil(t._numItems / t._colLineNum);
  731. result = t._leftGap + t._itemSize.width * colNum + t._columnGap * (colNum - 1) + t._rightGap;
  732. break;
  733. }
  734. break;
  735. }
  736. }
  737. let layout = t.content.getComponent(Layout);
  738. if (layout) layout.enabled = false;
  739. t._allItemSize = result;
  740. t._allItemSizeNoEdge = t._allItemSize - (t._sizeType ? t._topGap + t._bottomGap : t._leftGap + t._rightGap);
  741. if (t.cyclic) {
  742. let totalSize = t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width;
  743. t._cyclicPos1 = 0;
  744. totalSize -= t._cyclicPos1;
  745. t._cyclicNum = Math.ceil(totalSize / t._allItemSizeNoEdge) + 1;
  746. let spacing = t._sizeType ? t._lineGap : t._columnGap;
  747. t._cyclicPos2 = t._cyclicPos1 + t._allItemSizeNoEdge + spacing;
  748. t._cyclicAllItemSize = t._allItemSize + t._allItemSizeNoEdge * (t._cyclicNum - 1) + spacing * (t._cyclicNum - 1);
  749. t._cycilcAllItemSizeNoEdge = t._allItemSizeNoEdge * t._cyclicNum;
  750. t._cycilcAllItemSizeNoEdge += spacing * (t._cyclicNum - 1); // cc.log('_cyclicNum ->', t._cyclicNum, t._allItemSizeNoEdge, t._allItemSize, t._cyclicPos1, t._cyclicPos2);
  751. }
  752. t._lack = !t.cyclic && t._allItemSize < (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
  753. let slideOffset = (!t._lack || !t.lackCenter) && t.lackSlide ? 0 : .1;
  754. let targetWH = t._lack ? (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) - slideOffset : t.cyclic ? t._cyclicAllItemSize : t._allItemSize;
  755. if (targetWH < 0) targetWH = 0;
  756. if (t._sizeType) {
  757. t._contentUt.height = targetWH;
  758. } else {
  759. t._contentUt.width = targetWH;
  760. } // cc.log('_resizeContent() numItems =', t._numItems, ',content =', t.content);
  761. } //滚动进行时...
  762. _onScrolling(ev = null) {
  763. if (this.frameCount == null) this.frameCount = this._updateRate;
  764. if (!this._forceUpdate && ev && ev.type != 'scroll-ended' && this.frameCount > 0) {
  765. this.frameCount--;
  766. return;
  767. } else this.frameCount = this._updateRate;
  768. if (this._aniDelRuning) return; //循环列表处理
  769. if (this.cyclic) {
  770. let scrollPos = this.content.getPosition();
  771. scrollPos = this._sizeType ? scrollPos.y : scrollPos.x;
  772. let addVal = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap);
  773. let add = this._sizeType ? new Vec3(0, addVal, 0) : new Vec3(addVal, 0, 0);
  774. let contentPos = this.content.getPosition();
  775. switch (this._alignCalcType) {
  776. case 1:
  777. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  778. if (scrollPos > -this._cyclicPos1) {
  779. contentPos.set(-this._cyclicPos2, contentPos.y, contentPos.z);
  780. this.content.setPosition(contentPos);
  781. if (this._scrollView.isAutoScrolling()) {
  782. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  783. } // if (this._beganPos) {
  784. // this._beganPos += add;
  785. // }
  786. } else if (scrollPos < -this._cyclicPos2) {
  787. contentPos.set(-this._cyclicPos1, contentPos.y, contentPos.z);
  788. this.content.setPosition(contentPos);
  789. if (this._scrollView.isAutoScrolling()) {
  790. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  791. } // if (this._beganPos) {
  792. // this._beganPos -= add;
  793. // }
  794. }
  795. break;
  796. case 2:
  797. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  798. if (scrollPos < this._cyclicPos1) {
  799. contentPos.set(this._cyclicPos2, contentPos.y, contentPos.z);
  800. this.content.setPosition(contentPos);
  801. if (this._scrollView.isAutoScrolling()) {
  802. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  803. }
  804. } else if (scrollPos > this._cyclicPos2) {
  805. contentPos.set(this._cyclicPos1, contentPos.y, contentPos.z);
  806. this.content.setPosition(contentPos);
  807. if (this._scrollView.isAutoScrolling()) {
  808. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  809. }
  810. }
  811. break;
  812. case 3:
  813. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  814. if (scrollPos < this._cyclicPos1) {
  815. contentPos.set(contentPos.x, this._cyclicPos2, contentPos.z);
  816. this.content.setPosition(contentPos);
  817. if (this._scrollView.isAutoScrolling()) {
  818. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  819. }
  820. } else if (scrollPos > this._cyclicPos2) {
  821. contentPos.set(contentPos.x, this._cyclicPos1, contentPos.z);
  822. this.content.setPosition(contentPos);
  823. if (this._scrollView.isAutoScrolling()) {
  824. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  825. }
  826. }
  827. break;
  828. case 4:
  829. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  830. if (scrollPos > -this._cyclicPos1) {
  831. contentPos.set(contentPos.x, -this._cyclicPos2, contentPos.z);
  832. this.content.setPosition(contentPos);
  833. if (this._scrollView.isAutoScrolling()) {
  834. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  835. }
  836. } else if (scrollPos < -this._cyclicPos2) {
  837. contentPos.set(contentPos.x, -this._cyclicPos1, contentPos.z);
  838. this.content.setPosition(contentPos);
  839. if (this._scrollView.isAutoScrolling()) {
  840. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  841. }
  842. }
  843. break;
  844. }
  845. }
  846. this._calcViewPos();
  847. let vTop, vRight, vBottom, vLeft;
  848. if (this._sizeType) {
  849. vTop = this.viewTop;
  850. vBottom = this.viewBottom;
  851. } else {
  852. vRight = this.viewRight;
  853. vLeft = this.viewLeft;
  854. }
  855. if (this._virtual) {
  856. this.displayData = [];
  857. let itemPos;
  858. let curId = 0;
  859. let endId = this._numItems - 1;
  860. if (this._customSize) {
  861. let breakFor = false; //如果该item的位置在可视区域内,就推入displayData
  862. for (; curId <= endId && !breakFor; curId++) {
  863. itemPos = this._calcItemPos(curId);
  864. switch (this._align) {
  865. case Layout.Type.HORIZONTAL:
  866. if (itemPos.right >= vLeft && itemPos.left <= vRight) {
  867. this.displayData.push(itemPos);
  868. } else if (curId != 0 && this.displayData.length > 0) {
  869. breakFor = true;
  870. }
  871. break;
  872. case Layout.Type.VERTICAL:
  873. if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
  874. this.displayData.push(itemPos);
  875. } else if (curId != 0 && this.displayData.length > 0) {
  876. breakFor = true;
  877. }
  878. break;
  879. case Layout.Type.GRID:
  880. switch (this._startAxis) {
  881. case Layout.AxisDirection.HORIZONTAL:
  882. if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
  883. this.displayData.push(itemPos);
  884. } else if (curId != 0 && this.displayData.length > 0) {
  885. breakFor = true;
  886. }
  887. break;
  888. case Layout.AxisDirection.VERTICAL:
  889. if (itemPos.right >= vLeft && itemPos.left <= vRight) {
  890. this.displayData.push(itemPos);
  891. } else if (curId != 0 && this.displayData.length > 0) {
  892. breakFor = true;
  893. }
  894. break;
  895. }
  896. break;
  897. }
  898. }
  899. } else {
  900. let ww = this._itemSize.width + this._columnGap;
  901. let hh = this._itemSize.height + this._lineGap;
  902. switch (this._alignCalcType) {
  903. case 1:
  904. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  905. curId = (vLeft - this._leftGap) / ww;
  906. endId = (vRight - this._leftGap) / ww;
  907. break;
  908. case 2:
  909. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  910. curId = (-vRight - this._rightGap) / ww;
  911. endId = (-vLeft - this._rightGap) / ww;
  912. break;
  913. case 3:
  914. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  915. curId = (-vTop - this._topGap) / hh;
  916. endId = (-vBottom - this._topGap) / hh;
  917. break;
  918. case 4:
  919. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  920. curId = (vBottom - this._bottomGap) / hh;
  921. endId = (vTop - this._bottomGap) / hh;
  922. break;
  923. }
  924. curId = Math.floor(curId) * this._colLineNum;
  925. endId = Math.ceil(endId) * this._colLineNum;
  926. endId--;
  927. if (curId < 0) curId = 0;
  928. if (endId >= this._numItems) endId = this._numItems - 1;
  929. for (; curId <= endId; curId++) {
  930. this.displayData.push(this._calcItemPos(curId));
  931. }
  932. }
  933. this._delRedundantItem();
  934. if (this.displayData.length <= 0 || !this._numItems) {
  935. //if none, delete all.
  936. this._lastDisplayData = [];
  937. return;
  938. }
  939. this.firstListId = this.displayData[0].id;
  940. this.displayItemNum = this.displayData.length;
  941. let len = this._lastDisplayData.length;
  942. let haveDataChange = this.displayItemNum != len;
  943. if (haveDataChange) {
  944. // 如果是逐帧渲染,需要排序
  945. if (this.frameByFrameRenderNum > 0) {
  946. this._lastDisplayData.sort((a, b) => {
  947. return a - b;
  948. });
  949. } // 因List的显示数据是有序的,所以只需要判断数组长度是否相等,以及头、尾两个元素是否相等即可。
  950. haveDataChange = this.firstListId != this._lastDisplayData[0] || this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[len - 1];
  951. }
  952. if (this._forceUpdate || haveDataChange) {
  953. //如果是强制更新
  954. if (this.frameByFrameRenderNum > 0) {
  955. // if (this._updateDone) {
  956. // this._lastDisplayData = [];
  957. //逐帧渲染
  958. if (this._numItems > 0) {
  959. if (!this._updateDone) {
  960. this._doneAfterUpdate = true;
  961. } else {
  962. this._updateCounter = 0;
  963. }
  964. this._updateDone = false;
  965. } else {
  966. this._updateCounter = 0;
  967. this._updateDone = true;
  968. } // }
  969. } else {
  970. //直接渲染
  971. this._lastDisplayData = []; // cc.log('List Display Data II::', this.displayData);
  972. for (let c = 0; c < this.displayItemNum; c++) {
  973. this._createOrUpdateItem(this.displayData[c]);
  974. }
  975. this._forceUpdate = false;
  976. }
  977. }
  978. this._calcNearestItem();
  979. }
  980. } //计算可视范围
  981. _calcViewPos() {
  982. let scrollPos = this.content.getPosition();
  983. switch (this._alignCalcType) {
  984. case 1:
  985. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  986. this.elasticLeft = scrollPos.x > 0 ? scrollPos.x : 0;
  987. this.viewLeft = (scrollPos.x < 0 ? -scrollPos.x : 0) - this.elasticLeft;
  988. this.viewRight = this.viewLeft + this._thisNodeUt.width;
  989. this.elasticRight = this.viewRight > this._contentUt.width ? Math.abs(this.viewRight - this._contentUt.width) : 0;
  990. this.viewRight += this.elasticRight; // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
  991. break;
  992. case 2:
  993. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  994. this.elasticRight = scrollPos.x < 0 ? -scrollPos.x : 0;
  995. this.viewRight = (scrollPos.x > 0 ? -scrollPos.x : 0) + this.elasticRight;
  996. this.viewLeft = this.viewRight - this._thisNodeUt.width;
  997. this.elasticLeft = this.viewLeft < -this._contentUt.width ? Math.abs(this.viewLeft + this._contentUt.width) : 0;
  998. this.viewLeft -= this.elasticLeft; // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
  999. break;
  1000. case 3:
  1001. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1002. this.elasticTop = scrollPos.y < 0 ? Math.abs(scrollPos.y) : 0;
  1003. this.viewTop = (scrollPos.y > 0 ? -scrollPos.y : 0) + this.elasticTop;
  1004. this.viewBottom = this.viewTop - this._thisNodeUt.height;
  1005. this.elasticBottom = this.viewBottom < -this._contentUt.height ? Math.abs(this.viewBottom + this._contentUt.height) : 0;
  1006. this.viewBottom += this.elasticBottom; // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
  1007. break;
  1008. case 4:
  1009. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1010. this.elasticBottom = scrollPos.y > 0 ? Math.abs(scrollPos.y) : 0;
  1011. this.viewBottom = (scrollPos.y < 0 ? -scrollPos.y : 0) - this.elasticBottom;
  1012. this.viewTop = this.viewBottom + this._thisNodeUt.height;
  1013. this.elasticTop = this.viewTop > this._contentUt.height ? Math.abs(this.viewTop - this._contentUt.height) : 0;
  1014. this.viewTop -= this.elasticTop; // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
  1015. break;
  1016. }
  1017. } //计算位置 根据id
  1018. _calcItemPos(id) {
  1019. let width, height, top, bottom, left, right, itemX, itemY;
  1020. switch (this._align) {
  1021. case Layout.Type.HORIZONTAL:
  1022. switch (this._horizontalDir) {
  1023. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  1024. {
  1025. if (this._customSize) {
  1026. let fixed = this._getFixedSize(id);
  1027. left = this._leftGap + (this._itemSize.width + this._columnGap) * (id - fixed.count) + (fixed.val + this._columnGap * fixed.count);
  1028. let cs = this._customSize[id];
  1029. width = cs > 0 ? cs : this._itemSize.width;
  1030. } else {
  1031. left = this._leftGap + (this._itemSize.width + this._columnGap) * id;
  1032. width = this._itemSize.width;
  1033. }
  1034. if (this.lackCenter) {
  1035. left -= this._leftGap;
  1036. let offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
  1037. left += offset;
  1038. }
  1039. right = left + width;
  1040. return {
  1041. id: id,
  1042. left: left,
  1043. right: right,
  1044. x: left + this._itemTmpUt.anchorX * width,
  1045. y: this._itemTmp.y
  1046. };
  1047. }
  1048. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  1049. {
  1050. if (this._customSize) {
  1051. let fixed = this._getFixedSize(id);
  1052. right = -this._rightGap - (this._itemSize.width + this._columnGap) * (id - fixed.count) - (fixed.val + this._columnGap * fixed.count);
  1053. let cs = this._customSize[id];
  1054. width = cs > 0 ? cs : this._itemSize.width;
  1055. } else {
  1056. right = -this._rightGap - (this._itemSize.width + this._columnGap) * id;
  1057. width = this._itemSize.width;
  1058. }
  1059. if (this.lackCenter) {
  1060. right += this._rightGap;
  1061. let offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
  1062. right -= offset;
  1063. }
  1064. left = right - width;
  1065. return {
  1066. id: id,
  1067. right: right,
  1068. left: left,
  1069. x: left + this._itemTmpUt.anchorX * width,
  1070. y: this._itemTmp.y
  1071. };
  1072. }
  1073. }
  1074. break;
  1075. case Layout.Type.VERTICAL:
  1076. {
  1077. switch (this._verticalDir) {
  1078. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  1079. {
  1080. if (this._customSize) {
  1081. let fixed = this._getFixedSize(id);
  1082. top = -this._topGap - (this._itemSize.height + this._lineGap) * (id - fixed.count) - (fixed.val + this._lineGap * fixed.count);
  1083. let cs = this._customSize[id];
  1084. height = cs > 0 ? cs : this._itemSize.height;
  1085. } else {
  1086. top = -this._topGap - (this._itemSize.height + this._lineGap) * id;
  1087. height = this._itemSize.height;
  1088. }
  1089. if (this.lackCenter) {
  1090. top += this._topGap;
  1091. let offset = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
  1092. top -= offset;
  1093. }
  1094. bottom = top - height;
  1095. return {
  1096. id: id,
  1097. top: top,
  1098. bottom: bottom,
  1099. x: this._itemTmp.x,
  1100. y: bottom + this._itemTmpUt.anchorY * height
  1101. };
  1102. }
  1103. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  1104. {
  1105. if (this._customSize) {
  1106. let fixed = this._getFixedSize(id);
  1107. bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * (id - fixed.count) + (fixed.val + this._lineGap * fixed.count);
  1108. let cs = this._customSize[id];
  1109. height = cs > 0 ? cs : this._itemSize.height;
  1110. } else {
  1111. bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * id;
  1112. height = this._itemSize.height;
  1113. }
  1114. if (this.lackCenter) {
  1115. bottom -= this._bottomGap;
  1116. let offset = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
  1117. bottom += offset;
  1118. }
  1119. top = bottom + height;
  1120. return {
  1121. id: id,
  1122. top: top,
  1123. bottom: bottom,
  1124. x: this._itemTmp.x,
  1125. y: bottom + this._itemTmpUt.anchorY * height
  1126. };
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. case Layout.Type.GRID:
  1132. {
  1133. let colLine = Math.floor(id / this._colLineNum);
  1134. switch (this._startAxis) {
  1135. case Layout.AxisDirection.HORIZONTAL:
  1136. {
  1137. switch (this._verticalDir) {
  1138. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  1139. {
  1140. top = -this._topGap - (this._itemSize.height + this._lineGap) * colLine;
  1141. bottom = top - this._itemSize.height;
  1142. itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
  1143. break;
  1144. }
  1145. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  1146. {
  1147. bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * colLine;
  1148. top = bottom + this._itemSize.height;
  1149. itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
  1150. break;
  1151. }
  1152. }
  1153. itemX = this._leftGap + id % this._colLineNum * (this._itemSize.width + this._columnGap);
  1154. switch (this._horizontalDir) {
  1155. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  1156. {
  1157. itemX += this._itemTmpUt.anchorX * this._itemSize.width;
  1158. itemX -= this._contentUt.anchorX * this._contentUt.width;
  1159. break;
  1160. }
  1161. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  1162. {
  1163. itemX += (1 - this._itemTmpUt.anchorX) * this._itemSize.width;
  1164. itemX -= (1 - this._contentUt.anchorX) * this._contentUt.width;
  1165. itemX *= -1;
  1166. break;
  1167. }
  1168. }
  1169. return {
  1170. id: id,
  1171. top: top,
  1172. bottom: bottom,
  1173. x: itemX,
  1174. y: itemY
  1175. };
  1176. }
  1177. case Layout.AxisDirection.VERTICAL:
  1178. {
  1179. switch (this._horizontalDir) {
  1180. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  1181. {
  1182. left = this._leftGap + (this._itemSize.width + this._columnGap) * colLine;
  1183. right = left + this._itemSize.width;
  1184. itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
  1185. itemX -= this._contentUt.anchorX * this._contentUt.width;
  1186. break;
  1187. }
  1188. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  1189. {
  1190. right = -this._rightGap - (this._itemSize.width + this._columnGap) * colLine;
  1191. left = right - this._itemSize.width;
  1192. itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
  1193. itemX += (1 - this._contentUt.anchorX) * this._contentUt.width;
  1194. break;
  1195. }
  1196. }
  1197. itemY = -this._topGap - id % this._colLineNum * (this._itemSize.height + this._lineGap);
  1198. switch (this._verticalDir) {
  1199. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  1200. {
  1201. itemY -= (1 - this._itemTmpUt.anchorY) * this._itemSize.height;
  1202. itemY += (1 - this._contentUt.anchorY) * this._contentUt.height;
  1203. break;
  1204. }
  1205. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  1206. {
  1207. itemY -= this._itemTmpUt.anchorY * this._itemSize.height;
  1208. itemY += this._contentUt.anchorY * this._contentUt.height;
  1209. itemY *= -1;
  1210. break;
  1211. }
  1212. }
  1213. return {
  1214. id: id,
  1215. left: left,
  1216. right: right,
  1217. x: itemX,
  1218. y: itemY
  1219. };
  1220. }
  1221. }
  1222. break;
  1223. }
  1224. }
  1225. } //计算已存在的Item的位置
  1226. _calcExistItemPos(id) {
  1227. let item = this.getItemByListId(id);
  1228. if (!item) return null;
  1229. let ut = item.getComponent(UITransform);
  1230. let pos = item.getPosition();
  1231. let data = {
  1232. id: id,
  1233. x: pos.x,
  1234. y: pos.y
  1235. };
  1236. if (this._sizeType) {
  1237. data.top = pos.y + ut.height * (1 - ut.anchorY);
  1238. data.bottom = pos.y - ut.height * ut.anchorY;
  1239. } else {
  1240. data.left = pos.x - ut.width * ut.anchorX;
  1241. data.right = pos.x + ut.width * (1 - ut.anchorX);
  1242. }
  1243. return data;
  1244. } //获取Item位置
  1245. getItemPos(id) {
  1246. if (this._virtual) return this._calcItemPos(id);else {
  1247. if (this.frameByFrameRenderNum) return this._calcItemPos(id);else return this._calcExistItemPos(id);
  1248. }
  1249. } //获取固定尺寸
  1250. _getFixedSize(listId) {
  1251. if (!this._customSize) return null;
  1252. if (listId == null) listId = this._numItems;
  1253. let fixed = 0;
  1254. let count = 0;
  1255. for (let id in this._customSize) {
  1256. if (parseInt(id) < listId) {
  1257. fixed += this._customSize[id];
  1258. count++;
  1259. }
  1260. }
  1261. return {
  1262. val: fixed,
  1263. count: count
  1264. };
  1265. } //滚动结束时..
  1266. _onScrollBegan() {
  1267. this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
  1268. } //滚动结束时..
  1269. _onScrollEnded() {
  1270. let t = this;
  1271. t._curScrollIsTouch = false;
  1272. if (t.scrollToListId != null) {
  1273. let item = t.getItemByListId(t.scrollToListId);
  1274. t.scrollToListId = null;
  1275. if (item) {
  1276. tween(item).to(.1, {
  1277. scale: 1.06
  1278. }).to(.1, {
  1279. scale: 1
  1280. }).start();
  1281. }
  1282. }
  1283. t._onScrolling();
  1284. if (t._slideMode == SlideType.ADHERING && !t.adhering) {
  1285. //cc.log(t.adhering, t._scrollView.isAutoScrolling(), t._scrollView.isScrolling());
  1286. t.adhere();
  1287. } else if (t._slideMode == SlideType.PAGE) {
  1288. if (t._beganPos != null && t._curScrollIsTouch) {
  1289. this._pageAdhere();
  1290. } else {
  1291. t.adhere();
  1292. }
  1293. }
  1294. } // 触摸时
  1295. _onTouchStart(ev, captureListeners) {
  1296. if (this._scrollView['_hasNestedViewGroup'](ev, captureListeners)) return;
  1297. this._curScrollIsTouch = true;
  1298. let isMe = ev.eventPhase === 2 && ev.target === this.node;
  1299. if (!isMe) {
  1300. let itemNode = ev.target;
  1301. while (itemNode._listId == null && itemNode.parent) itemNode = itemNode.parent;
  1302. this._scrollItem = itemNode._listId != null ? itemNode : ev.target;
  1303. }
  1304. } //触摸抬起时..
  1305. _onTouchUp() {
  1306. let t = this;
  1307. t._scrollPos = null;
  1308. if (t._slideMode == SlideType.ADHERING) {
  1309. if (this.adhering) this._adheringBarrier = true;
  1310. t.adhere();
  1311. } else if (t._slideMode == SlideType.PAGE) {
  1312. if (t._beganPos != null) {
  1313. this._pageAdhere();
  1314. } else {
  1315. t.adhere();
  1316. }
  1317. }
  1318. this._scrollItem = null;
  1319. }
  1320. _onTouchCancelled(ev, captureListeners) {
  1321. let t = this;
  1322. if (t._scrollView['_hasNestedViewGroup'](ev, captureListeners) || ev.simulate) return;
  1323. t._scrollPos = null;
  1324. if (t._slideMode == SlideType.ADHERING) {
  1325. if (t.adhering) t._adheringBarrier = true;
  1326. t.adhere();
  1327. } else if (t._slideMode == SlideType.PAGE) {
  1328. if (t._beganPos != null) {
  1329. t._pageAdhere();
  1330. } else {
  1331. t.adhere();
  1332. }
  1333. }
  1334. this._scrollItem = null;
  1335. } //当尺寸改变
  1336. _onSizeChanged() {
  1337. if (this.checkInited(false)) this._onScrolling();
  1338. } //当Item自适应
  1339. _onItemAdaptive(item) {
  1340. let ut = item.getComponent(UITransform); // if (this.checkInited(false)) {
  1341. if (!this._sizeType && ut.width != this._itemSize.width || this._sizeType && ut.height != this._itemSize.height) {
  1342. if (!this._customSize) this._customSize = {};
  1343. let val = this._sizeType ? ut.height : ut.width;
  1344. if (this._customSize[item._listId] != val) {
  1345. this._customSize[item._listId] = val;
  1346. this._resizeContent(); // this.content.children.forEach((child: Node) => {
  1347. // this._updateItemPos(child);
  1348. // });
  1349. this.updateAll(); // 如果当前正在运行 scrollTo,肯定会不准确,在这里做修正
  1350. if (this._scrollToListId != null) {
  1351. this._scrollPos = null;
  1352. this.unschedule(this._scrollToSo);
  1353. this.scrollTo(this._scrollToListId, Math.max(0, this._scrollToEndTime - new Date().getTime() / 1000));
  1354. }
  1355. }
  1356. } // }
  1357. } //PAGE粘附
  1358. _pageAdhere() {
  1359. let t = this;
  1360. if (!t.cyclic && (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0)) return;
  1361. let curPos = t._sizeType ? t.viewTop : t.viewLeft;
  1362. let dis = (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) * t.pageDistance;
  1363. let canSkip = Math.abs(t._beganPos - curPos) > dis;
  1364. if (canSkip) {
  1365. let timeInSecond = .5;
  1366. switch (t._alignCalcType) {
  1367. case 1: //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1368. case 4:
  1369. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1370. if (t._beganPos > curPos) {
  1371. t.prePage(timeInSecond); // cc.log('_pageAdhere PPPPPPPPPPPPPPP');
  1372. } else {
  1373. t.nextPage(timeInSecond); // cc.log('_pageAdhere NNNNNNNNNNNNNNN');
  1374. }
  1375. break;
  1376. case 2: //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1377. case 3:
  1378. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1379. if (t._beganPos < curPos) {
  1380. t.prePage(timeInSecond);
  1381. } else {
  1382. t.nextPage(timeInSecond);
  1383. }
  1384. break;
  1385. }
  1386. } else if (t.elasticTop <= 0 && t.elasticRight <= 0 && t.elasticBottom <= 0 && t.elasticLeft <= 0) {
  1387. t.adhere();
  1388. }
  1389. t._beganPos = null;
  1390. } //粘附
  1391. adhere() {
  1392. let t = this;
  1393. if (!t.checkInited()) return;
  1394. if (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0) return;
  1395. t.adhering = true;
  1396. t._calcNearestItem();
  1397. let offset = (t._sizeType ? t._topGap : t._leftGap) / (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
  1398. let timeInSecond = .7;
  1399. t.scrollTo(t.nearestListId, timeInSecond, offset);
  1400. } //Update..
  1401. update() {
  1402. if (this.frameByFrameRenderNum <= 0 || this._updateDone) return; // cc.log(this.displayData.length, this._updateCounter, this.displayData[this._updateCounter]);
  1403. if (this._virtual) {
  1404. let len = this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ? this.displayItemNum : this._updateCounter + this.frameByFrameRenderNum;
  1405. for (let n = this._updateCounter; n < len; n++) {
  1406. let data = this.displayData[n];
  1407. if (data) {
  1408. this._createOrUpdateItem(data);
  1409. }
  1410. }
  1411. if (this._updateCounter >= this.displayItemNum - 1) {
  1412. //最后一个
  1413. if (this._doneAfterUpdate) {
  1414. this._updateCounter = 0;
  1415. this._updateDone = false; // if (!this._scrollView.isScrolling())
  1416. this._doneAfterUpdate = false;
  1417. } else {
  1418. this._updateDone = true;
  1419. this._delRedundantItem();
  1420. this._forceUpdate = false;
  1421. this._calcNearestItem();
  1422. if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
  1423. }
  1424. } else {
  1425. this._updateCounter += this.frameByFrameRenderNum;
  1426. }
  1427. } else {
  1428. if (this._updateCounter < this._numItems) {
  1429. let len = this._updateCounter + this.frameByFrameRenderNum > this._numItems ? this._numItems : this._updateCounter + this.frameByFrameRenderNum;
  1430. for (let n = this._updateCounter; n < len; n++) {
  1431. this._createOrUpdateItem2(n);
  1432. }
  1433. this._updateCounter += this.frameByFrameRenderNum;
  1434. } else {
  1435. this._updateDone = true;
  1436. this._calcNearestItem();
  1437. if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
  1438. }
  1439. }
  1440. }
  1441. /**
  1442. * 创建或更新Item(虚拟列表用)
  1443. * @param {Object} data 数据
  1444. */
  1445. _createOrUpdateItem(data) {
  1446. let item = this.getItemByListId(data.id);
  1447. if (!item) {
  1448. //如果不存在
  1449. let canGet = this._pool.size() > 0;
  1450. if (canGet) {
  1451. item = this._pool.get(); // cc.log('从池中取出:: 旧id =', item['_listId'], ',新id =', data.id, item);
  1452. } else {
  1453. item = instantiate(this._itemTmp); // cc.log('新建::', data.id, item);
  1454. }
  1455. if (!canGet || !isValid(item)) {
  1456. item = instantiate(this._itemTmp);
  1457. canGet = false;
  1458. }
  1459. if (item._listId != data.id) {
  1460. item._listId = data.id;
  1461. let ut = item.getComponent(UITransform);
  1462. ut.setContentSize(this._itemSize);
  1463. }
  1464. item.setPosition(new Vec3(data.x, data.y, 0));
  1465. this._resetItemSize(item);
  1466. this.content.addChild(item);
  1467. if (canGet && this._needUpdateWidget) {
  1468. let widget = item.getComponent(Widget);
  1469. if (widget) widget.updateAlignment();
  1470. }
  1471. item.setSiblingIndex(this.content.children.length - 1);
  1472. let listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  1473. error: Error()
  1474. }), ListItem) : ListItem);
  1475. item['listItem'] = listItem;
  1476. if (listItem) {
  1477. listItem.listId = data.id;
  1478. listItem.list = this;
  1479. listItem._registerEvent();
  1480. }
  1481. if (this.renderEvent) {
  1482. EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
  1483. }
  1484. } else if (this._forceUpdate && this.renderEvent) {
  1485. //强制更新
  1486. item.setPosition(new Vec3(data.x, data.y, 0));
  1487. this._resetItemSize(item); // cc.log('ADD::', data.id, item);
  1488. if (this.renderEvent) {
  1489. EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
  1490. }
  1491. }
  1492. this._resetItemSize(item);
  1493. this._updateListItem(item['listItem']);
  1494. if (this._lastDisplayData.indexOf(data.id) < 0) {
  1495. this._lastDisplayData.push(data.id);
  1496. }
  1497. } //创建或更新Item(非虚拟列表用)
  1498. _createOrUpdateItem2(listId) {
  1499. let item = this.content.children[listId];
  1500. let listItem;
  1501. if (!item) {
  1502. //如果不存在
  1503. item = instantiate(this._itemTmp);
  1504. item._listId = listId;
  1505. this.content.addChild(item);
  1506. listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  1507. error: Error()
  1508. }), ListItem) : ListItem);
  1509. item['listItem'] = listItem;
  1510. if (listItem) {
  1511. listItem.listId = listId;
  1512. listItem.list = this;
  1513. listItem._registerEvent();
  1514. }
  1515. if (this.renderEvent) {
  1516. EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
  1517. }
  1518. } else if (this._forceUpdate && this.renderEvent) {
  1519. //强制更新
  1520. item._listId = listId;
  1521. if (listItem) listItem.listId = listId;
  1522. if (this.renderEvent) {
  1523. EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
  1524. }
  1525. }
  1526. this._updateListItem(listItem);
  1527. if (this._lastDisplayData.indexOf(listId) < 0) {
  1528. this._lastDisplayData.push(listId);
  1529. }
  1530. }
  1531. _updateListItem(listItem) {
  1532. if (!listItem) return;
  1533. if (this.selectedMode > SelectedType.NONE) {
  1534. let item = listItem.node;
  1535. switch (this.selectedMode) {
  1536. case SelectedType.SINGLE:
  1537. listItem.selected = this.selectedId == item._listId;
  1538. break;
  1539. case SelectedType.MULT:
  1540. listItem.selected = this.multSelected.indexOf(item._listId) >= 0;
  1541. break;
  1542. }
  1543. }
  1544. } //仅虚拟列表用
  1545. _resetItemSize(item) {
  1546. return;
  1547. let size;
  1548. let ut = item.getComponent(UITransform);
  1549. if (this._customSize && this._customSize[item._listId]) {
  1550. size = this._customSize[item._listId];
  1551. } else {
  1552. if (this._colLineNum > 1) ut.setContentSize(this._itemSize);else size = this._sizeType ? this._itemSize.height : this._itemSize.width;
  1553. }
  1554. if (size) {
  1555. if (this._sizeType) ut.height = size;else ut.width = size;
  1556. }
  1557. }
  1558. /**
  1559. * 更新Item位置
  1560. * @param {Number||Node} listIdOrItem
  1561. */
  1562. _updateItemPos(listIdOrItem) {
  1563. let item = isNaN(listIdOrItem) ? listIdOrItem : this.getItemByListId(listIdOrItem);
  1564. let pos = this.getItemPos(item._listId);
  1565. item.setPosition(pos.x, pos.y);
  1566. }
  1567. /**
  1568. * 设置多选
  1569. * @param {Array} args 可以是单个listId,也可是个listId数组
  1570. * @param {Boolean} bool 值,如果为null的话,则直接用args覆盖
  1571. */
  1572. setMultSelected(args, bool) {
  1573. let t = this;
  1574. if (!t.checkInited()) return;
  1575. if (!Array.isArray(args)) {
  1576. args = [args];
  1577. }
  1578. if (bool == null) {
  1579. t.multSelected = args;
  1580. } else {
  1581. let listId, sub;
  1582. if (bool) {
  1583. for (let n = args.length - 1; n >= 0; n--) {
  1584. listId = args[n];
  1585. sub = t.multSelected.indexOf(listId);
  1586. if (sub < 0) {
  1587. t.multSelected.push(listId);
  1588. }
  1589. }
  1590. } else {
  1591. for (let n = args.length - 1; n >= 0; n--) {
  1592. listId = args[n];
  1593. sub = t.multSelected.indexOf(listId);
  1594. if (sub >= 0) {
  1595. t.multSelected.splice(sub, 1);
  1596. }
  1597. }
  1598. }
  1599. }
  1600. t._forceUpdate = true;
  1601. t._onScrolling();
  1602. }
  1603. /**
  1604. * 获取多选数据
  1605. * @returns
  1606. */
  1607. getMultSelected() {
  1608. return this.multSelected;
  1609. }
  1610. /**
  1611. * 多选是否有选择
  1612. * @param {number} listId 索引
  1613. * @returns
  1614. */
  1615. hasMultSelected(listId) {
  1616. return this.multSelected && this.multSelected.indexOf(listId) >= 0;
  1617. }
  1618. /**
  1619. * 更新指定的Item
  1620. * @param {Array} args 单个listId,或者数组
  1621. * @returns
  1622. */
  1623. updateItem(args) {
  1624. if (!this.checkInited()) return;
  1625. if (!Array.isArray(args)) {
  1626. args = [args];
  1627. }
  1628. for (let n = 0, len = args.length; n < len; n++) {
  1629. let listId = args[n];
  1630. let item = this.getItemByListId(listId);
  1631. if (item) EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
  1632. }
  1633. }
  1634. /**
  1635. * 更新全部
  1636. */
  1637. updateAll() {
  1638. if (!this.checkInited()) return;
  1639. this.numItems = this.numItems;
  1640. }
  1641. /**
  1642. * 根据ListID获取Item
  1643. * @param {Number} listId
  1644. * @returns
  1645. */
  1646. getItemByListId(listId) {
  1647. if (this.content) {
  1648. for (let n = this.content.children.length - 1; n >= 0; n--) {
  1649. let item = this.content.children[n];
  1650. if (item._listId == listId) return item;
  1651. }
  1652. }
  1653. }
  1654. /**
  1655. * 获取在显示区域外的Item
  1656. * @returns
  1657. */
  1658. _getOutsideItem() {
  1659. let item;
  1660. let result = [];
  1661. for (let n = this.content.children.length - 1; n >= 0; n--) {
  1662. item = this.content.children[n];
  1663. if (!this.displayData.find(d => d.id == item._listId)) {
  1664. result.push(item);
  1665. }
  1666. }
  1667. return result;
  1668. } //删除显示区域以外的Item
  1669. _delRedundantItem() {
  1670. if (this._virtual) {
  1671. let arr = this._getOutsideItem();
  1672. for (let n = arr.length - 1; n >= 0; n--) {
  1673. let item = arr[n];
  1674. if (this._scrollItem && item._listId == this._scrollItem._listId) continue;
  1675. item.isCached = true;
  1676. this._pool.put(item);
  1677. for (let m = this._lastDisplayData.length - 1; m >= 0; m--) {
  1678. if (this._lastDisplayData[m] == item._listId) {
  1679. this._lastDisplayData.splice(m, 1);
  1680. break;
  1681. }
  1682. }
  1683. } // cc.log('存入::', str, ' pool.length =', this._pool.length);
  1684. } else {
  1685. while (this.content.children.length > this._numItems) {
  1686. this._delSingleItem(this.content.children[this.content.children.length - 1]);
  1687. }
  1688. }
  1689. } //删除单个Item
  1690. _delSingleItem(item) {
  1691. // cc.log('DEL::', item['_listId'], item);
  1692. item.removeFromParent();
  1693. if (item.destroy) item.destroy();
  1694. item = null;
  1695. }
  1696. /**
  1697. * 动效删除Item(此方法只适用于虚拟列表,即_virtual=true)
  1698. * 一定要在回调函数里重新设置新的numItems进行刷新,毕竟本List是靠数据驱动的。
  1699. */
  1700. aniDelItem(listId, callFunc, aniType) {
  1701. let t = this;
  1702. if (!t.checkInited() || t.cyclic || !t._virtual) return console.error('This function is not allowed to be called!');
  1703. 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!');
  1704. if (t._aniDelRuning) return console.warn('Please wait for the current deletion to finish!');
  1705. let item = t.getItemByListId(listId);
  1706. let listItem;
  1707. if (!item) {
  1708. callFunc(listId);
  1709. return;
  1710. } else {
  1711. listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  1712. error: Error()
  1713. }), ListItem) : ListItem);
  1714. }
  1715. t._aniDelRuning = true;
  1716. t._aniDelCB = callFunc;
  1717. t._aniDelItem = item;
  1718. t._aniDelBeforePos = item.position;
  1719. t._aniDelBeforeScale = item.scale;
  1720. let curLastId = t.displayData[t.displayData.length - 1].id;
  1721. let resetSelectedId = listItem.selected;
  1722. listItem.showAni(aniType, () => {
  1723. //判断有没有下一个,如果有的话,创建粗来
  1724. let newId;
  1725. if (curLastId < t._numItems - 2) {
  1726. newId = curLastId + 1;
  1727. }
  1728. if (newId != null) {
  1729. let newData = t._calcItemPos(newId);
  1730. t.displayData.push(newData);
  1731. if (t._virtual) t._createOrUpdateItem(newData);else t._createOrUpdateItem2(newId);
  1732. } else t._numItems--;
  1733. if (t.selectedMode == SelectedType.SINGLE) {
  1734. if (resetSelectedId) {
  1735. t._selectedId = -1;
  1736. } else if (t._selectedId - 1 >= 0) {
  1737. t._selectedId--;
  1738. }
  1739. } else if (t.selectedMode == SelectedType.MULT && t.multSelected.length) {
  1740. let sub = t.multSelected.indexOf(listId);
  1741. if (sub >= 0) {
  1742. t.multSelected.splice(sub, 1);
  1743. } //多选的数据,在其后的全部减一
  1744. for (let n = t.multSelected.length - 1; n >= 0; n--) {
  1745. let id = t.multSelected[n];
  1746. if (id >= listId) t.multSelected[n]--;
  1747. }
  1748. }
  1749. if (t._customSize) {
  1750. if (t._customSize[listId]) delete t._customSize[listId];
  1751. let newCustomSize = {};
  1752. let size;
  1753. for (let id in t._customSize) {
  1754. size = t._customSize[id];
  1755. let idNumber = parseInt(id);
  1756. newCustomSize[idNumber - (idNumber >= listId ? 1 : 0)] = size;
  1757. }
  1758. t._customSize = newCustomSize;
  1759. } //后面的Item向前怼的动效
  1760. let sec = .2333;
  1761. let twe, haveCB;
  1762. for (let n = newId != null ? newId : curLastId; n >= listId + 1; n--) {
  1763. item = t.getItemByListId(n);
  1764. if (item) {
  1765. let posData = t._calcItemPos(n - 1);
  1766. twe = tween(item).to(sec, {
  1767. position: new Vec3(posData.x, posData.y, 0)
  1768. });
  1769. if (n <= listId + 1) {
  1770. haveCB = true;
  1771. twe.call(() => {
  1772. t._aniDelRuning = false;
  1773. callFunc(listId);
  1774. delete t._aniDelCB;
  1775. });
  1776. }
  1777. twe.start();
  1778. }
  1779. }
  1780. if (!haveCB) {
  1781. t._aniDelRuning = false;
  1782. callFunc(listId);
  1783. t._aniDelCB = null;
  1784. }
  1785. }, true);
  1786. }
  1787. /**
  1788. * 滚动到..
  1789. * @param {Number} listId 索引(如果<0,则滚到首个Item位置,如果>=_numItems,则滚到最末Item位置)
  1790. * @param {Number} timeInSecond 时间
  1791. * @param {Number} offset 索引目标位置偏移,0-1
  1792. * @param {Boolean} overStress 滚动后是否强调该Item(这只是个实验功能)
  1793. */
  1794. scrollTo(listId, timeInSecond = .5, offset = null, overStress = false) {
  1795. let t = this;
  1796. if (!t.checkInited(false)) return; // t._scrollView.stopAutoScroll();
  1797. if (timeInSecond == null) //默认0.5
  1798. timeInSecond = .5;else if (timeInSecond < 0) timeInSecond = 0;
  1799. if (listId < 0) listId = 0;else if (listId >= t._numItems) listId = t._numItems - 1; // 以防设置了numItems之后layout的尺寸还未更新
  1800. if (!t._virtual && t._layout && t._layout.enabled) t._layout.updateLayout();
  1801. let pos = t.getItemPos(listId);
  1802. if (!pos) {
  1803. return DEV && console.error('pos is null', listId);
  1804. }
  1805. let targetX, targetY;
  1806. switch (t._alignCalcType) {
  1807. case 1:
  1808. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1809. targetX = pos.left;
  1810. if (offset != null) targetX -= t._thisNodeUt.width * offset;else targetX -= t._leftGap;
  1811. pos = new Vec3(targetX, 0, 0);
  1812. break;
  1813. case 2:
  1814. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1815. targetX = pos.right - t._thisNodeUt.width;
  1816. if (offset != null) targetX += t._thisNodeUt.width * offset;else targetX += t._rightGap;
  1817. pos = new Vec3(targetX + t._contentUt.width, 0, 0);
  1818. break;
  1819. case 3:
  1820. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1821. targetY = pos.top;
  1822. if (offset != null) targetY += t._thisNodeUt.height * offset;else targetY += t._topGap;
  1823. pos = new Vec3(0, -targetY, 0);
  1824. break;
  1825. case 4:
  1826. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1827. targetY = pos.bottom + t._thisNodeUt.height;
  1828. if (offset != null) targetY -= t._thisNodeUt.height * offset;else targetY -= t._bottomGap;
  1829. pos = new Vec3(0, -targetY + t._contentUt.height, 0);
  1830. break;
  1831. }
  1832. let viewPos = t.content.getPosition();
  1833. viewPos = Math.abs(t._sizeType ? viewPos.y : viewPos.x);
  1834. let comparePos = t._sizeType ? pos.y : pos.x;
  1835. let runScroll = Math.abs((t._scrollPos != null ? t._scrollPos : viewPos) - comparePos) > .5; // cc.log(runScroll, t._scrollPos, viewPos, comparePos)
  1836. // t._scrollView.stopAutoScroll();
  1837. if (runScroll) {
  1838. t._scrollView.scrollToOffset(pos, timeInSecond);
  1839. t._scrollToListId = listId;
  1840. t._scrollToEndTime = new Date().getTime() / 1000 + timeInSecond; // cc.log(listId, t.content.width, t.content.getPosition(), pos);
  1841. t._scrollToSo = t.scheduleOnce(() => {
  1842. if (!t._adheringBarrier) {
  1843. t.adhering = t._adheringBarrier = false;
  1844. }
  1845. t._scrollPos = t._scrollToListId = t._scrollToEndTime = t._scrollToSo = null; //cc.log('2222222222', t._adheringBarrier)
  1846. if (overStress) {
  1847. // t.scrollToListId = listId;
  1848. let item = t.getItemByListId(listId);
  1849. if (item) {
  1850. tween(item).to(.1, {
  1851. scale: 1.05
  1852. }).to(.1, {
  1853. scale: 1
  1854. }).start();
  1855. }
  1856. }
  1857. }, timeInSecond + .1);
  1858. if (timeInSecond <= 0) {
  1859. t._onScrolling();
  1860. }
  1861. }
  1862. }
  1863. /**
  1864. * 计算当前滚动窗最近的Item
  1865. */
  1866. _calcNearestItem() {
  1867. let t = this;
  1868. t.nearestListId = null;
  1869. let data, center;
  1870. if (t._virtual) t._calcViewPos();
  1871. let vTop, vRight, vBottom, vLeft;
  1872. vTop = t.viewTop;
  1873. vRight = t.viewRight;
  1874. vBottom = t.viewBottom;
  1875. vLeft = t.viewLeft;
  1876. let breakFor = false;
  1877. for (let n = 0; n < t.content.children.length && !breakFor; n += t._colLineNum) {
  1878. data = t._virtual ? t.displayData[n] : t._calcExistItemPos(n);
  1879. if (data) {
  1880. center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
  1881. switch (t._alignCalcType) {
  1882. case 1:
  1883. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1884. if (data.right >= vLeft) {
  1885. t.nearestListId = data.id;
  1886. if (vLeft > center) t.nearestListId += t._colLineNum;
  1887. breakFor = true;
  1888. }
  1889. break;
  1890. case 2:
  1891. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1892. if (data.left <= vRight) {
  1893. t.nearestListId = data.id;
  1894. if (vRight < center) t.nearestListId += t._colLineNum;
  1895. breakFor = true;
  1896. }
  1897. break;
  1898. case 3:
  1899. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1900. if (data.bottom <= vTop) {
  1901. t.nearestListId = data.id;
  1902. if (vTop < center) t.nearestListId += t._colLineNum;
  1903. breakFor = true;
  1904. }
  1905. break;
  1906. case 4:
  1907. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1908. if (data.top >= vBottom) {
  1909. t.nearestListId = data.id;
  1910. if (vBottom > center) t.nearestListId += t._colLineNum;
  1911. breakFor = true;
  1912. }
  1913. break;
  1914. }
  1915. }
  1916. } //判断最后一个Item。。。(哎,这些判断真心恶心,判断了前面的还要判断最后一个。。。一开始呢,就只有一个布局(单列布局),那时候代码才三百行,后来就想着完善啊,艹..这坑真深,现在这行数都一千五了= =||)
  1917. data = t._virtual ? t.displayData[t.displayItemNum - 1] : t._calcExistItemPos(t._numItems - 1);
  1918. if (data && data.id == t._numItems - 1) {
  1919. center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
  1920. switch (t._alignCalcType) {
  1921. case 1:
  1922. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1923. if (vRight > center) t.nearestListId = data.id;
  1924. break;
  1925. case 2:
  1926. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1927. if (vLeft < center) t.nearestListId = data.id;
  1928. break;
  1929. case 3:
  1930. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1931. if (vBottom < center) t.nearestListId = data.id;
  1932. break;
  1933. case 4:
  1934. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1935. if (vTop > center) t.nearestListId = data.id;
  1936. break;
  1937. }
  1938. } // cc.log('t.nearestListId =', t.nearestListId);
  1939. } //上一页
  1940. prePage(timeInSecond = .5) {
  1941. // cc.log('👈');
  1942. if (!this.checkInited()) return;
  1943. this.skipPage(this.curPageNum - 1, timeInSecond);
  1944. } //下一页
  1945. nextPage(timeInSecond = .5) {
  1946. // cc.log('👉');
  1947. if (!this.checkInited()) return;
  1948. this.skipPage(this.curPageNum + 1, timeInSecond);
  1949. } //跳转到第几页
  1950. skipPage(pageNum, timeInSecond) {
  1951. let t = this;
  1952. if (!t.checkInited()) return;
  1953. if (t._slideMode != SlideType.PAGE) return console.error('This function is not allowed to be called, Must SlideMode = PAGE!');
  1954. if (pageNum < 0 || pageNum >= t._numItems) return;
  1955. if (t.curPageNum == pageNum) return; // cc.log(pageNum);
  1956. t.curPageNum = pageNum;
  1957. if (t.pageChangeEvent) {
  1958. EventHandler.emitEvents([t.pageChangeEvent], pageNum);
  1959. }
  1960. t.scrollTo(pageNum, timeInSecond);
  1961. } //计算 CustomSize(这个函数还是保留吧,某些罕见的情况的确还是需要手动计算customSize的)
  1962. calcCustomSize(numItems) {
  1963. let t = this;
  1964. if (!t.checkInited()) return;
  1965. if (!t._itemTmp) return console.error('Unset template item!');
  1966. if (!t.renderEvent) return console.error('Unset Render-Event!');
  1967. t._customSize = {};
  1968. let temp = instantiate(t._itemTmp);
  1969. let ut = temp.getComponent(UITransform);
  1970. t.content.addChild(temp);
  1971. for (let n = 0; n < numItems; n++) {
  1972. EventHandler.emitEvents([t.renderEvent], temp, n);
  1973. if (ut.height != t._itemSize.height || ut.width != t._itemSize.width) {
  1974. t._customSize[n] = t._sizeType ? ut.height : ut.width;
  1975. }
  1976. }
  1977. if (!Object.keys(t._customSize).length) t._customSize = null;
  1978. temp.removeFromParent();
  1979. if (temp.destroy) temp.destroy();
  1980. return t._customSize;
  1981. }
  1982. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "templateType", [_dec5], {
  1983. configurable: true,
  1984. enumerable: true,
  1985. writable: true,
  1986. initializer: function () {
  1987. return TemplateType.NODE;
  1988. }
  1989. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tmpNode", [_dec6], {
  1990. configurable: true,
  1991. enumerable: true,
  1992. writable: true,
  1993. initializer: function () {
  1994. return null;
  1995. }
  1996. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "tmpPrefab", [_dec7], {
  1997. configurable: true,
  1998. enumerable: true,
  1999. writable: true,
  2000. initializer: function () {
  2001. return null;
  2002. }
  2003. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_slideMode", [_dec8], {
  2004. configurable: true,
  2005. enumerable: true,
  2006. writable: true,
  2007. initializer: function () {
  2008. return SlideType.NORMAL;
  2009. }
  2010. }), _applyDecoratedDescriptor(_class2.prototype, "slideMode", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "slideMode"), _class2.prototype), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "pageDistance", [_dec10], {
  2011. configurable: true,
  2012. enumerable: true,
  2013. writable: true,
  2014. initializer: function () {
  2015. return .3;
  2016. }
  2017. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "pageChangeEvent", [_dec11], {
  2018. configurable: true,
  2019. enumerable: true,
  2020. writable: true,
  2021. initializer: function () {
  2022. return new EventHandler();
  2023. }
  2024. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "_virtual", [_dec12], {
  2025. configurable: true,
  2026. enumerable: true,
  2027. writable: true,
  2028. initializer: function () {
  2029. return true;
  2030. }
  2031. }), _applyDecoratedDescriptor(_class2.prototype, "virtual", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "virtual"), _class2.prototype), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "cyclic", [_dec14], {
  2032. configurable: true,
  2033. enumerable: true,
  2034. writable: true,
  2035. initializer: function () {
  2036. return false;
  2037. }
  2038. }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "lackCenter", [_dec15], {
  2039. configurable: true,
  2040. enumerable: true,
  2041. writable: true,
  2042. initializer: function () {
  2043. return false;
  2044. }
  2045. }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "lackSlide", [_dec16], {
  2046. configurable: true,
  2047. enumerable: true,
  2048. writable: true,
  2049. initializer: function () {
  2050. return false;
  2051. }
  2052. }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "_updateRate", [_dec17], {
  2053. configurable: true,
  2054. enumerable: true,
  2055. writable: true,
  2056. initializer: function () {
  2057. return 0;
  2058. }
  2059. }), _applyDecoratedDescriptor(_class2.prototype, "updateRate", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "updateRate"), _class2.prototype), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "frameByFrameRenderNum", [_dec19], {
  2060. configurable: true,
  2061. enumerable: true,
  2062. writable: true,
  2063. initializer: function () {
  2064. return 0;
  2065. }
  2066. }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "renderEvent", [_dec20], {
  2067. configurable: true,
  2068. enumerable: true,
  2069. writable: true,
  2070. initializer: function () {
  2071. return new EventHandler();
  2072. }
  2073. }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "selectedMode", [_dec21], {
  2074. configurable: true,
  2075. enumerable: true,
  2076. writable: true,
  2077. initializer: function () {
  2078. return SelectedType.NONE;
  2079. }
  2080. }), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "selectedEvent", [_dec22], {
  2081. configurable: true,
  2082. enumerable: true,
  2083. writable: true,
  2084. initializer: function () {
  2085. return new EventHandler();
  2086. }
  2087. }), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "repeatEventSingle", [_dec23], {
  2088. configurable: true,
  2089. enumerable: true,
  2090. writable: true,
  2091. initializer: function () {
  2092. return false;
  2093. }
  2094. }), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "_numItems", [_dec24], {
  2095. configurable: true,
  2096. enumerable: true,
  2097. writable: true,
  2098. initializer: function () {
  2099. return 0;
  2100. }
  2101. })), _class2)) || _class) || _class) || _class) || _class) || _class));
  2102. _cclegacy._RF.pop();
  2103. _crd = false;
  2104. }
  2105. };
  2106. });
  2107. //# sourceMappingURL=122ae41024fa99aa4949a176919256851ded60b7.js.map