d9ffd842e0d1c5a0c6b29396f172e2772497d53b.js 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655
  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. var 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. var 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() {
  165. super(...arguments);
  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. var t = this;
  298. var 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. var 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. var 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. var _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. var bool = !_listItem.selected;
  338. _listItem.selected = bool;
  339. var 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. var 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. var 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. var len = t.frameByFrameRenderNum > t._numItems ? t._numItems : t.frameByFrameRenderNum;
  385. for (var 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 (var _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. var 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. var 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. var 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. var 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. var OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05;
  576. var EPSILON = 1e-4;
  577. var ZERO = new Vec3();
  578. var quintEaseOut = time => {
  579. time -= 1;
  580. return time * time * time * time * time + 1;
  581. }; // ------------- scroll-view 里定义的一些常量 -------------
  582. var sv = this._scrollView;
  583. var isAutoScrollBrake = sv['_isNecessaryAutoScrollBrake']();
  584. var brakingFactor = isAutoScrollBrake ? OUT_OF_BOUNDARY_BREAKING_FACTOR : 1;
  585. sv['_autoScrollAccumulatedTime'] += dt * (1 / brakingFactor);
  586. var percentage = Math.min(1, sv['_autoScrollAccumulatedTime'] / sv['_autoScrollTotalTime']);
  587. if (sv['_autoScrollAttenuate']) {
  588. percentage = quintEaseOut(percentage);
  589. }
  590. var clonedAutoScrollTargetDelta = sv['_autoScrollTargetDelta'].clone();
  591. clonedAutoScrollTargetDelta.multiplyScalar(percentage);
  592. var clonedAutoScrollStartPosition = sv['_autoScrollStartPosition'].clone();
  593. clonedAutoScrollStartPosition.add(clonedAutoScrollTargetDelta);
  594. var reachedEnd = Math.abs(percentage - 1) <= EPSILON;
  595. var 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. var 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. var moveDelta = clonedAutoScrollStartPosition.clone();
  610. moveDelta.subtract(sv['_getContentPosition']());
  611. var 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. var 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. var 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. var itemUt = item.getComponent(UITransform);
  638. t._itemSize = new Size(itemUt.width, itemUt.height);
  639. } //获取ListItem,如果没有就取消选择模式
  640. var com = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  641. error: Error()
  642. }), ListItem) : ListItem);
  643. var 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. var 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. var 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) {
  690. if (printLog === void 0) {
  691. printLog = true;
  692. }
  693. if (!this._inited) {
  694. if (printLog) console.error('List initialization not completed!');
  695. return false;
  696. }
  697. return true;
  698. } //禁用 Layout 组件,自行计算 Content Size
  699. _resizeContent() {
  700. var t = this;
  701. var result;
  702. switch (t._align) {
  703. case Layout.Type.HORIZONTAL:
  704. {
  705. if (t._customSize) {
  706. var fixed = t._getFixedSize(null);
  707. result = t._leftGap + fixed.val + t._itemSize.width * (t._numItems - fixed.count) + t._columnGap * (t._numItems - 1) + t._rightGap;
  708. } else {
  709. result = t._leftGap + t._itemSize.width * t._numItems + t._columnGap * (t._numItems - 1) + t._rightGap;
  710. }
  711. break;
  712. }
  713. case Layout.Type.VERTICAL:
  714. {
  715. if (t._customSize) {
  716. var _fixed = t._getFixedSize(null);
  717. result = t._topGap + _fixed.val + t._itemSize.height * (t._numItems - _fixed.count) + t._lineGap * (t._numItems - 1) + t._bottomGap;
  718. } else {
  719. result = t._topGap + t._itemSize.height * t._numItems + t._lineGap * (t._numItems - 1) + t._bottomGap;
  720. }
  721. break;
  722. }
  723. case Layout.Type.GRID:
  724. {
  725. //网格模式不支持居中
  726. if (t.lackCenter) t.lackCenter = false;
  727. switch (t._startAxis) {
  728. case Layout.AxisDirection.HORIZONTAL:
  729. var lineNum = Math.ceil(t._numItems / t._colLineNum);
  730. result = t._topGap + t._itemSize.height * lineNum + t._lineGap * (lineNum - 1) + t._bottomGap;
  731. break;
  732. case Layout.AxisDirection.VERTICAL:
  733. var colNum = Math.ceil(t._numItems / t._colLineNum);
  734. result = t._leftGap + t._itemSize.width * colNum + t._columnGap * (colNum - 1) + t._rightGap;
  735. break;
  736. }
  737. break;
  738. }
  739. }
  740. var layout = t.content.getComponent(Layout);
  741. if (layout) layout.enabled = false;
  742. t._allItemSize = result;
  743. t._allItemSizeNoEdge = t._allItemSize - (t._sizeType ? t._topGap + t._bottomGap : t._leftGap + t._rightGap);
  744. if (t.cyclic) {
  745. var totalSize = t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width;
  746. t._cyclicPos1 = 0;
  747. totalSize -= t._cyclicPos1;
  748. t._cyclicNum = Math.ceil(totalSize / t._allItemSizeNoEdge) + 1;
  749. var spacing = t._sizeType ? t._lineGap : t._columnGap;
  750. t._cyclicPos2 = t._cyclicPos1 + t._allItemSizeNoEdge + spacing;
  751. t._cyclicAllItemSize = t._allItemSize + t._allItemSizeNoEdge * (t._cyclicNum - 1) + spacing * (t._cyclicNum - 1);
  752. t._cycilcAllItemSizeNoEdge = t._allItemSizeNoEdge * t._cyclicNum;
  753. t._cycilcAllItemSizeNoEdge += spacing * (t._cyclicNum - 1); // cc.log('_cyclicNum ->', t._cyclicNum, t._allItemSizeNoEdge, t._allItemSize, t._cyclicPos1, t._cyclicPos2);
  754. }
  755. t._lack = !t.cyclic && t._allItemSize < (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
  756. var slideOffset = (!t._lack || !t.lackCenter) && t.lackSlide ? 0 : .1;
  757. var targetWH = t._lack ? (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) - slideOffset : t.cyclic ? t._cyclicAllItemSize : t._allItemSize;
  758. if (targetWH < 0) targetWH = 0;
  759. if (t._sizeType) {
  760. t._contentUt.height = targetWH;
  761. } else {
  762. t._contentUt.width = targetWH;
  763. } // cc.log('_resizeContent() numItems =', t._numItems, ',content =', t.content);
  764. } //滚动进行时...
  765. _onScrolling(ev) {
  766. if (ev === void 0) {
  767. ev = null;
  768. }
  769. if (this.frameCount == null) this.frameCount = this._updateRate;
  770. if (!this._forceUpdate && ev && ev.type != 'scroll-ended' && this.frameCount > 0) {
  771. this.frameCount--;
  772. return;
  773. } else this.frameCount = this._updateRate;
  774. if (this._aniDelRuning) return; //循环列表处理
  775. if (this.cyclic) {
  776. var scrollPos = this.content.getPosition();
  777. scrollPos = this._sizeType ? scrollPos.y : scrollPos.x;
  778. var addVal = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap);
  779. var add = this._sizeType ? new Vec3(0, addVal, 0) : new Vec3(addVal, 0, 0);
  780. var contentPos = this.content.getPosition();
  781. switch (this._alignCalcType) {
  782. case 1:
  783. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  784. if (scrollPos > -this._cyclicPos1) {
  785. contentPos.set(-this._cyclicPos2, contentPos.y, contentPos.z);
  786. this.content.setPosition(contentPos);
  787. if (this._scrollView.isAutoScrolling()) {
  788. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  789. } // if (this._beganPos) {
  790. // this._beganPos += add;
  791. // }
  792. } else if (scrollPos < -this._cyclicPos2) {
  793. contentPos.set(-this._cyclicPos1, contentPos.y, contentPos.z);
  794. this.content.setPosition(contentPos);
  795. if (this._scrollView.isAutoScrolling()) {
  796. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  797. } // if (this._beganPos) {
  798. // this._beganPos -= add;
  799. // }
  800. }
  801. break;
  802. case 2:
  803. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  804. if (scrollPos < this._cyclicPos1) {
  805. contentPos.set(this._cyclicPos2, contentPos.y, contentPos.z);
  806. this.content.setPosition(contentPos);
  807. if (this._scrollView.isAutoScrolling()) {
  808. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  809. }
  810. } else if (scrollPos > this._cyclicPos2) {
  811. contentPos.set(this._cyclicPos1, contentPos.y, contentPos.z);
  812. this.content.setPosition(contentPos);
  813. if (this._scrollView.isAutoScrolling()) {
  814. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  815. }
  816. }
  817. break;
  818. case 3:
  819. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  820. if (scrollPos < this._cyclicPos1) {
  821. contentPos.set(contentPos.x, this._cyclicPos2, contentPos.z);
  822. this.content.setPosition(contentPos);
  823. if (this._scrollView.isAutoScrolling()) {
  824. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  825. }
  826. } else if (scrollPos > this._cyclicPos2) {
  827. contentPos.set(contentPos.x, this._cyclicPos1, contentPos.z);
  828. this.content.setPosition(contentPos);
  829. if (this._scrollView.isAutoScrolling()) {
  830. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  831. }
  832. }
  833. break;
  834. case 4:
  835. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  836. if (scrollPos > -this._cyclicPos1) {
  837. contentPos.set(contentPos.x, -this._cyclicPos2, contentPos.z);
  838. this.content.setPosition(contentPos);
  839. if (this._scrollView.isAutoScrolling()) {
  840. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
  841. }
  842. } else if (scrollPos < -this._cyclicPos2) {
  843. contentPos.set(contentPos.x, -this._cyclicPos1, contentPos.z);
  844. this.content.setPosition(contentPos);
  845. if (this._scrollView.isAutoScrolling()) {
  846. this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
  847. }
  848. }
  849. break;
  850. }
  851. }
  852. this._calcViewPos();
  853. var vTop, vRight, vBottom, vLeft;
  854. if (this._sizeType) {
  855. vTop = this.viewTop;
  856. vBottom = this.viewBottom;
  857. } else {
  858. vRight = this.viewRight;
  859. vLeft = this.viewLeft;
  860. }
  861. if (this._virtual) {
  862. this.displayData = [];
  863. var itemPos;
  864. var curId = 0;
  865. var endId = this._numItems - 1;
  866. if (this._customSize) {
  867. var breakFor = false; //如果该item的位置在可视区域内,就推入displayData
  868. for (; curId <= endId && !breakFor; curId++) {
  869. itemPos = this._calcItemPos(curId);
  870. switch (this._align) {
  871. case Layout.Type.HORIZONTAL:
  872. if (itemPos.right >= vLeft && itemPos.left <= vRight) {
  873. this.displayData.push(itemPos);
  874. } else if (curId != 0 && this.displayData.length > 0) {
  875. breakFor = true;
  876. }
  877. break;
  878. case Layout.Type.VERTICAL:
  879. if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
  880. this.displayData.push(itemPos);
  881. } else if (curId != 0 && this.displayData.length > 0) {
  882. breakFor = true;
  883. }
  884. break;
  885. case Layout.Type.GRID:
  886. switch (this._startAxis) {
  887. case Layout.AxisDirection.HORIZONTAL:
  888. if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
  889. this.displayData.push(itemPos);
  890. } else if (curId != 0 && this.displayData.length > 0) {
  891. breakFor = true;
  892. }
  893. break;
  894. case Layout.AxisDirection.VERTICAL:
  895. if (itemPos.right >= vLeft && itemPos.left <= vRight) {
  896. this.displayData.push(itemPos);
  897. } else if (curId != 0 && this.displayData.length > 0) {
  898. breakFor = true;
  899. }
  900. break;
  901. }
  902. break;
  903. }
  904. }
  905. } else {
  906. var ww = this._itemSize.width + this._columnGap;
  907. var hh = this._itemSize.height + this._lineGap;
  908. switch (this._alignCalcType) {
  909. case 1:
  910. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  911. curId = (vLeft - this._leftGap) / ww;
  912. endId = (vRight - this._leftGap) / ww;
  913. break;
  914. case 2:
  915. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  916. curId = (-vRight - this._rightGap) / ww;
  917. endId = (-vLeft - this._rightGap) / ww;
  918. break;
  919. case 3:
  920. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  921. curId = (-vTop - this._topGap) / hh;
  922. endId = (-vBottom - this._topGap) / hh;
  923. break;
  924. case 4:
  925. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  926. curId = (vBottom - this._bottomGap) / hh;
  927. endId = (vTop - this._bottomGap) / hh;
  928. break;
  929. }
  930. curId = Math.floor(curId) * this._colLineNum;
  931. endId = Math.ceil(endId) * this._colLineNum;
  932. endId--;
  933. if (curId < 0) curId = 0;
  934. if (endId >= this._numItems) endId = this._numItems - 1;
  935. for (; curId <= endId; curId++) {
  936. this.displayData.push(this._calcItemPos(curId));
  937. }
  938. }
  939. this._delRedundantItem();
  940. if (this.displayData.length <= 0 || !this._numItems) {
  941. //if none, delete all.
  942. this._lastDisplayData = [];
  943. return;
  944. }
  945. this.firstListId = this.displayData[0].id;
  946. this.displayItemNum = this.displayData.length;
  947. var len = this._lastDisplayData.length;
  948. var haveDataChange = this.displayItemNum != len;
  949. if (haveDataChange) {
  950. // 如果是逐帧渲染,需要排序
  951. if (this.frameByFrameRenderNum > 0) {
  952. this._lastDisplayData.sort((a, b) => {
  953. return a - b;
  954. });
  955. } // 因List的显示数据是有序的,所以只需要判断数组长度是否相等,以及头、尾两个元素是否相等即可。
  956. haveDataChange = this.firstListId != this._lastDisplayData[0] || this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[len - 1];
  957. }
  958. if (this._forceUpdate || haveDataChange) {
  959. //如果是强制更新
  960. if (this.frameByFrameRenderNum > 0) {
  961. // if (this._updateDone) {
  962. // this._lastDisplayData = [];
  963. //逐帧渲染
  964. if (this._numItems > 0) {
  965. if (!this._updateDone) {
  966. this._doneAfterUpdate = true;
  967. } else {
  968. this._updateCounter = 0;
  969. }
  970. this._updateDone = false;
  971. } else {
  972. this._updateCounter = 0;
  973. this._updateDone = true;
  974. } // }
  975. } else {
  976. //直接渲染
  977. this._lastDisplayData = []; // cc.log('List Display Data II::', this.displayData);
  978. for (var c = 0; c < this.displayItemNum; c++) {
  979. this._createOrUpdateItem(this.displayData[c]);
  980. }
  981. this._forceUpdate = false;
  982. }
  983. }
  984. this._calcNearestItem();
  985. }
  986. } //计算可视范围
  987. _calcViewPos() {
  988. var scrollPos = this.content.getPosition();
  989. switch (this._alignCalcType) {
  990. case 1:
  991. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  992. this.elasticLeft = scrollPos.x > 0 ? scrollPos.x : 0;
  993. this.viewLeft = (scrollPos.x < 0 ? -scrollPos.x : 0) - this.elasticLeft;
  994. this.viewRight = this.viewLeft + this._thisNodeUt.width;
  995. this.elasticRight = this.viewRight > this._contentUt.width ? Math.abs(this.viewRight - this._contentUt.width) : 0;
  996. this.viewRight += this.elasticRight; // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
  997. break;
  998. case 2:
  999. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1000. this.elasticRight = scrollPos.x < 0 ? -scrollPos.x : 0;
  1001. this.viewRight = (scrollPos.x > 0 ? -scrollPos.x : 0) + this.elasticRight;
  1002. this.viewLeft = this.viewRight - this._thisNodeUt.width;
  1003. this.elasticLeft = this.viewLeft < -this._contentUt.width ? Math.abs(this.viewLeft + this._contentUt.width) : 0;
  1004. this.viewLeft -= this.elasticLeft; // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
  1005. break;
  1006. case 3:
  1007. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1008. this.elasticTop = scrollPos.y < 0 ? Math.abs(scrollPos.y) : 0;
  1009. this.viewTop = (scrollPos.y > 0 ? -scrollPos.y : 0) + this.elasticTop;
  1010. this.viewBottom = this.viewTop - this._thisNodeUt.height;
  1011. this.elasticBottom = this.viewBottom < -this._contentUt.height ? Math.abs(this.viewBottom + this._contentUt.height) : 0;
  1012. this.viewBottom += this.elasticBottom; // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
  1013. break;
  1014. case 4:
  1015. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1016. this.elasticBottom = scrollPos.y > 0 ? Math.abs(scrollPos.y) : 0;
  1017. this.viewBottom = (scrollPos.y < 0 ? -scrollPos.y : 0) - this.elasticBottom;
  1018. this.viewTop = this.viewBottom + this._thisNodeUt.height;
  1019. this.elasticTop = this.viewTop > this._contentUt.height ? Math.abs(this.viewTop - this._contentUt.height) : 0;
  1020. this.viewTop -= this.elasticTop; // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
  1021. break;
  1022. }
  1023. } //计算位置 根据id
  1024. _calcItemPos(id) {
  1025. var width, height, top, bottom, left, right, itemX, itemY;
  1026. switch (this._align) {
  1027. case Layout.Type.HORIZONTAL:
  1028. switch (this._horizontalDir) {
  1029. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  1030. {
  1031. if (this._customSize) {
  1032. var fixed = this._getFixedSize(id);
  1033. left = this._leftGap + (this._itemSize.width + this._columnGap) * (id - fixed.count) + (fixed.val + this._columnGap * fixed.count);
  1034. var cs = this._customSize[id];
  1035. width = cs > 0 ? cs : this._itemSize.width;
  1036. } else {
  1037. left = this._leftGap + (this._itemSize.width + this._columnGap) * id;
  1038. width = this._itemSize.width;
  1039. }
  1040. if (this.lackCenter) {
  1041. left -= this._leftGap;
  1042. var offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
  1043. left += offset;
  1044. }
  1045. right = left + width;
  1046. return {
  1047. id: id,
  1048. left: left,
  1049. right: right,
  1050. x: left + this._itemTmpUt.anchorX * width,
  1051. y: this._itemTmp.y
  1052. };
  1053. }
  1054. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  1055. {
  1056. if (this._customSize) {
  1057. var _fixed2 = this._getFixedSize(id);
  1058. right = -this._rightGap - (this._itemSize.width + this._columnGap) * (id - _fixed2.count) - (_fixed2.val + this._columnGap * _fixed2.count);
  1059. var _cs = this._customSize[id];
  1060. width = _cs > 0 ? _cs : this._itemSize.width;
  1061. } else {
  1062. right = -this._rightGap - (this._itemSize.width + this._columnGap) * id;
  1063. width = this._itemSize.width;
  1064. }
  1065. if (this.lackCenter) {
  1066. right += this._rightGap;
  1067. var _offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
  1068. right -= _offset;
  1069. }
  1070. left = right - width;
  1071. return {
  1072. id: id,
  1073. right: right,
  1074. left: left,
  1075. x: left + this._itemTmpUt.anchorX * width,
  1076. y: this._itemTmp.y
  1077. };
  1078. }
  1079. }
  1080. break;
  1081. case Layout.Type.VERTICAL:
  1082. {
  1083. switch (this._verticalDir) {
  1084. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  1085. {
  1086. if (this._customSize) {
  1087. var _fixed3 = this._getFixedSize(id);
  1088. top = -this._topGap - (this._itemSize.height + this._lineGap) * (id - _fixed3.count) - (_fixed3.val + this._lineGap * _fixed3.count);
  1089. var _cs2 = this._customSize[id];
  1090. height = _cs2 > 0 ? _cs2 : this._itemSize.height;
  1091. } else {
  1092. top = -this._topGap - (this._itemSize.height + this._lineGap) * id;
  1093. height = this._itemSize.height;
  1094. }
  1095. if (this.lackCenter) {
  1096. top += this._topGap;
  1097. var _offset2 = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
  1098. top -= _offset2;
  1099. }
  1100. bottom = top - height;
  1101. return {
  1102. id: id,
  1103. top: top,
  1104. bottom: bottom,
  1105. x: this._itemTmp.x,
  1106. y: bottom + this._itemTmpUt.anchorY * height
  1107. };
  1108. }
  1109. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  1110. {
  1111. if (this._customSize) {
  1112. var _fixed4 = this._getFixedSize(id);
  1113. bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * (id - _fixed4.count) + (_fixed4.val + this._lineGap * _fixed4.count);
  1114. var _cs3 = this._customSize[id];
  1115. height = _cs3 > 0 ? _cs3 : this._itemSize.height;
  1116. } else {
  1117. bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * id;
  1118. height = this._itemSize.height;
  1119. }
  1120. if (this.lackCenter) {
  1121. bottom -= this._bottomGap;
  1122. var _offset3 = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
  1123. bottom += _offset3;
  1124. }
  1125. top = bottom + height;
  1126. return {
  1127. id: id,
  1128. top: top,
  1129. bottom: bottom,
  1130. x: this._itemTmp.x,
  1131. y: bottom + this._itemTmpUt.anchorY * height
  1132. };
  1133. break;
  1134. }
  1135. }
  1136. }
  1137. case Layout.Type.GRID:
  1138. {
  1139. var colLine = Math.floor(id / this._colLineNum);
  1140. switch (this._startAxis) {
  1141. case Layout.AxisDirection.HORIZONTAL:
  1142. {
  1143. switch (this._verticalDir) {
  1144. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  1145. {
  1146. top = -this._topGap - (this._itemSize.height + this._lineGap) * colLine;
  1147. bottom = top - this._itemSize.height;
  1148. itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
  1149. break;
  1150. }
  1151. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  1152. {
  1153. bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * colLine;
  1154. top = bottom + this._itemSize.height;
  1155. itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
  1156. break;
  1157. }
  1158. }
  1159. itemX = this._leftGap + id % this._colLineNum * (this._itemSize.width + this._columnGap);
  1160. switch (this._horizontalDir) {
  1161. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  1162. {
  1163. itemX += this._itemTmpUt.anchorX * this._itemSize.width;
  1164. itemX -= this._contentUt.anchorX * this._contentUt.width;
  1165. break;
  1166. }
  1167. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  1168. {
  1169. itemX += (1 - this._itemTmpUt.anchorX) * this._itemSize.width;
  1170. itemX -= (1 - this._contentUt.anchorX) * this._contentUt.width;
  1171. itemX *= -1;
  1172. break;
  1173. }
  1174. }
  1175. return {
  1176. id: id,
  1177. top: top,
  1178. bottom: bottom,
  1179. x: itemX,
  1180. y: itemY
  1181. };
  1182. }
  1183. case Layout.AxisDirection.VERTICAL:
  1184. {
  1185. switch (this._horizontalDir) {
  1186. case Layout.HorizontalDirection.LEFT_TO_RIGHT:
  1187. {
  1188. left = this._leftGap + (this._itemSize.width + this._columnGap) * colLine;
  1189. right = left + this._itemSize.width;
  1190. itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
  1191. itemX -= this._contentUt.anchorX * this._contentUt.width;
  1192. break;
  1193. }
  1194. case Layout.HorizontalDirection.RIGHT_TO_LEFT:
  1195. {
  1196. right = -this._rightGap - (this._itemSize.width + this._columnGap) * colLine;
  1197. left = right - this._itemSize.width;
  1198. itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
  1199. itemX += (1 - this._contentUt.anchorX) * this._contentUt.width;
  1200. break;
  1201. }
  1202. }
  1203. itemY = -this._topGap - id % this._colLineNum * (this._itemSize.height + this._lineGap);
  1204. switch (this._verticalDir) {
  1205. case Layout.VerticalDirection.TOP_TO_BOTTOM:
  1206. {
  1207. itemY -= (1 - this._itemTmpUt.anchorY) * this._itemSize.height;
  1208. itemY += (1 - this._contentUt.anchorY) * this._contentUt.height;
  1209. break;
  1210. }
  1211. case Layout.VerticalDirection.BOTTOM_TO_TOP:
  1212. {
  1213. itemY -= this._itemTmpUt.anchorY * this._itemSize.height;
  1214. itemY += this._contentUt.anchorY * this._contentUt.height;
  1215. itemY *= -1;
  1216. break;
  1217. }
  1218. }
  1219. return {
  1220. id: id,
  1221. left: left,
  1222. right: right,
  1223. x: itemX,
  1224. y: itemY
  1225. };
  1226. }
  1227. }
  1228. break;
  1229. }
  1230. }
  1231. } //计算已存在的Item的位置
  1232. _calcExistItemPos(id) {
  1233. var item = this.getItemByListId(id);
  1234. if (!item) return null;
  1235. var ut = item.getComponent(UITransform);
  1236. var pos = item.getPosition();
  1237. var data = {
  1238. id: id,
  1239. x: pos.x,
  1240. y: pos.y
  1241. };
  1242. if (this._sizeType) {
  1243. data.top = pos.y + ut.height * (1 - ut.anchorY);
  1244. data.bottom = pos.y - ut.height * ut.anchorY;
  1245. } else {
  1246. data.left = pos.x - ut.width * ut.anchorX;
  1247. data.right = pos.x + ut.width * (1 - ut.anchorX);
  1248. }
  1249. return data;
  1250. } //获取Item位置
  1251. getItemPos(id) {
  1252. if (this._virtual) return this._calcItemPos(id);else {
  1253. if (this.frameByFrameRenderNum) return this._calcItemPos(id);else return this._calcExistItemPos(id);
  1254. }
  1255. } //获取固定尺寸
  1256. _getFixedSize(listId) {
  1257. if (!this._customSize) return null;
  1258. if (listId == null) listId = this._numItems;
  1259. var fixed = 0;
  1260. var count = 0;
  1261. for (var id in this._customSize) {
  1262. if (parseInt(id) < listId) {
  1263. fixed += this._customSize[id];
  1264. count++;
  1265. }
  1266. }
  1267. return {
  1268. val: fixed,
  1269. count: count
  1270. };
  1271. } //滚动结束时..
  1272. _onScrollBegan() {
  1273. this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
  1274. } //滚动结束时..
  1275. _onScrollEnded() {
  1276. var t = this;
  1277. t._curScrollIsTouch = false;
  1278. if (t.scrollToListId != null) {
  1279. var item = t.getItemByListId(t.scrollToListId);
  1280. t.scrollToListId = null;
  1281. if (item) {
  1282. tween(item).to(.1, {
  1283. scale: 1.06
  1284. }).to(.1, {
  1285. scale: 1
  1286. }).start();
  1287. }
  1288. }
  1289. t._onScrolling();
  1290. if (t._slideMode == SlideType.ADHERING && !t.adhering) {
  1291. //cc.log(t.adhering, t._scrollView.isAutoScrolling(), t._scrollView.isScrolling());
  1292. t.adhere();
  1293. } else if (t._slideMode == SlideType.PAGE) {
  1294. if (t._beganPos != null && t._curScrollIsTouch) {
  1295. this._pageAdhere();
  1296. } else {
  1297. t.adhere();
  1298. }
  1299. }
  1300. } // 触摸时
  1301. _onTouchStart(ev, captureListeners) {
  1302. if (this._scrollView['_hasNestedViewGroup'](ev, captureListeners)) return;
  1303. this._curScrollIsTouch = true;
  1304. var isMe = ev.eventPhase === 2 && ev.target === this.node;
  1305. if (!isMe) {
  1306. var itemNode = ev.target;
  1307. while (itemNode._listId == null && itemNode.parent) itemNode = itemNode.parent;
  1308. this._scrollItem = itemNode._listId != null ? itemNode : ev.target;
  1309. }
  1310. } //触摸抬起时..
  1311. _onTouchUp() {
  1312. var t = this;
  1313. t._scrollPos = null;
  1314. if (t._slideMode == SlideType.ADHERING) {
  1315. if (this.adhering) this._adheringBarrier = true;
  1316. t.adhere();
  1317. } else if (t._slideMode == SlideType.PAGE) {
  1318. if (t._beganPos != null) {
  1319. this._pageAdhere();
  1320. } else {
  1321. t.adhere();
  1322. }
  1323. }
  1324. this._scrollItem = null;
  1325. }
  1326. _onTouchCancelled(ev, captureListeners) {
  1327. var t = this;
  1328. if (t._scrollView['_hasNestedViewGroup'](ev, captureListeners) || ev.simulate) return;
  1329. t._scrollPos = null;
  1330. if (t._slideMode == SlideType.ADHERING) {
  1331. if (t.adhering) t._adheringBarrier = true;
  1332. t.adhere();
  1333. } else if (t._slideMode == SlideType.PAGE) {
  1334. if (t._beganPos != null) {
  1335. t._pageAdhere();
  1336. } else {
  1337. t.adhere();
  1338. }
  1339. }
  1340. this._scrollItem = null;
  1341. } //当尺寸改变
  1342. _onSizeChanged() {
  1343. if (this.checkInited(false)) this._onScrolling();
  1344. } //当Item自适应
  1345. _onItemAdaptive(item) {
  1346. var ut = item.getComponent(UITransform); // if (this.checkInited(false)) {
  1347. if (!this._sizeType && ut.width != this._itemSize.width || this._sizeType && ut.height != this._itemSize.height) {
  1348. if (!this._customSize) this._customSize = {};
  1349. var val = this._sizeType ? ut.height : ut.width;
  1350. if (this._customSize[item._listId] != val) {
  1351. this._customSize[item._listId] = val;
  1352. this._resizeContent(); // this.content.children.forEach((child: Node) => {
  1353. // this._updateItemPos(child);
  1354. // });
  1355. this.updateAll(); // 如果当前正在运行 scrollTo,肯定会不准确,在这里做修正
  1356. if (this._scrollToListId != null) {
  1357. this._scrollPos = null;
  1358. this.unschedule(this._scrollToSo);
  1359. this.scrollTo(this._scrollToListId, Math.max(0, this._scrollToEndTime - new Date().getTime() / 1000));
  1360. }
  1361. }
  1362. } // }
  1363. } //PAGE粘附
  1364. _pageAdhere() {
  1365. var t = this;
  1366. if (!t.cyclic && (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0)) return;
  1367. var curPos = t._sizeType ? t.viewTop : t.viewLeft;
  1368. var dis = (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) * t.pageDistance;
  1369. var canSkip = Math.abs(t._beganPos - curPos) > dis;
  1370. if (canSkip) {
  1371. var timeInSecond = .5;
  1372. switch (t._alignCalcType) {
  1373. case 1: //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1374. case 4:
  1375. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1376. if (t._beganPos > curPos) {
  1377. t.prePage(timeInSecond); // cc.log('_pageAdhere PPPPPPPPPPPPPPP');
  1378. } else {
  1379. t.nextPage(timeInSecond); // cc.log('_pageAdhere NNNNNNNNNNNNNNN');
  1380. }
  1381. break;
  1382. case 2: //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1383. case 3:
  1384. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1385. if (t._beganPos < curPos) {
  1386. t.prePage(timeInSecond);
  1387. } else {
  1388. t.nextPage(timeInSecond);
  1389. }
  1390. break;
  1391. }
  1392. } else if (t.elasticTop <= 0 && t.elasticRight <= 0 && t.elasticBottom <= 0 && t.elasticLeft <= 0) {
  1393. t.adhere();
  1394. }
  1395. t._beganPos = null;
  1396. } //粘附
  1397. adhere() {
  1398. var t = this;
  1399. if (!t.checkInited()) return;
  1400. if (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0) return;
  1401. t.adhering = true;
  1402. t._calcNearestItem();
  1403. var offset = (t._sizeType ? t._topGap : t._leftGap) / (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
  1404. var timeInSecond = .7;
  1405. t.scrollTo(t.nearestListId, timeInSecond, offset);
  1406. } //Update..
  1407. update() {
  1408. if (this.frameByFrameRenderNum <= 0 || this._updateDone) return; // cc.log(this.displayData.length, this._updateCounter, this.displayData[this._updateCounter]);
  1409. if (this._virtual) {
  1410. var len = this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ? this.displayItemNum : this._updateCounter + this.frameByFrameRenderNum;
  1411. for (var n = this._updateCounter; n < len; n++) {
  1412. var data = this.displayData[n];
  1413. if (data) {
  1414. this._createOrUpdateItem(data);
  1415. }
  1416. }
  1417. if (this._updateCounter >= this.displayItemNum - 1) {
  1418. //最后一个
  1419. if (this._doneAfterUpdate) {
  1420. this._updateCounter = 0;
  1421. this._updateDone = false; // if (!this._scrollView.isScrolling())
  1422. this._doneAfterUpdate = false;
  1423. } else {
  1424. this._updateDone = true;
  1425. this._delRedundantItem();
  1426. this._forceUpdate = false;
  1427. this._calcNearestItem();
  1428. if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
  1429. }
  1430. } else {
  1431. this._updateCounter += this.frameByFrameRenderNum;
  1432. }
  1433. } else {
  1434. if (this._updateCounter < this._numItems) {
  1435. var _len = this._updateCounter + this.frameByFrameRenderNum > this._numItems ? this._numItems : this._updateCounter + this.frameByFrameRenderNum;
  1436. for (var _n2 = this._updateCounter; _n2 < _len; _n2++) {
  1437. this._createOrUpdateItem2(_n2);
  1438. }
  1439. this._updateCounter += this.frameByFrameRenderNum;
  1440. } else {
  1441. this._updateDone = true;
  1442. this._calcNearestItem();
  1443. if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
  1444. }
  1445. }
  1446. }
  1447. /**
  1448. * 创建或更新Item(虚拟列表用)
  1449. * @param {Object} data 数据
  1450. */
  1451. _createOrUpdateItem(data) {
  1452. var item = this.getItemByListId(data.id);
  1453. if (!item) {
  1454. //如果不存在
  1455. var canGet = this._pool.size() > 0;
  1456. if (canGet) {
  1457. item = this._pool.get(); // cc.log('从池中取出:: 旧id =', item['_listId'], ',新id =', data.id, item);
  1458. } else {
  1459. item = instantiate(this._itemTmp); // cc.log('新建::', data.id, item);
  1460. }
  1461. if (!canGet || !isValid(item)) {
  1462. item = instantiate(this._itemTmp);
  1463. canGet = false;
  1464. }
  1465. if (item._listId != data.id) {
  1466. item._listId = data.id;
  1467. var ut = item.getComponent(UITransform);
  1468. ut.setContentSize(this._itemSize);
  1469. }
  1470. item.setPosition(new Vec3(data.x, data.y, 0));
  1471. this._resetItemSize(item);
  1472. this.content.addChild(item);
  1473. if (canGet && this._needUpdateWidget) {
  1474. var widget = item.getComponent(Widget);
  1475. if (widget) widget.updateAlignment();
  1476. }
  1477. item.setSiblingIndex(this.content.children.length - 1);
  1478. var listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  1479. error: Error()
  1480. }), ListItem) : ListItem);
  1481. item['listItem'] = listItem;
  1482. if (listItem) {
  1483. listItem.listId = data.id;
  1484. listItem.list = this;
  1485. listItem._registerEvent();
  1486. }
  1487. if (this.renderEvent) {
  1488. EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
  1489. }
  1490. } else if (this._forceUpdate && this.renderEvent) {
  1491. //强制更新
  1492. item.setPosition(new Vec3(data.x, data.y, 0));
  1493. this._resetItemSize(item); // cc.log('ADD::', data.id, item);
  1494. if (this.renderEvent) {
  1495. EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
  1496. }
  1497. }
  1498. this._resetItemSize(item);
  1499. this._updateListItem(item['listItem']);
  1500. if (this._lastDisplayData.indexOf(data.id) < 0) {
  1501. this._lastDisplayData.push(data.id);
  1502. }
  1503. } //创建或更新Item(非虚拟列表用)
  1504. _createOrUpdateItem2(listId) {
  1505. var item = this.content.children[listId];
  1506. var listItem;
  1507. if (!item) {
  1508. //如果不存在
  1509. item = instantiate(this._itemTmp);
  1510. item._listId = listId;
  1511. this.content.addChild(item);
  1512. listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  1513. error: Error()
  1514. }), ListItem) : ListItem);
  1515. item['listItem'] = listItem;
  1516. if (listItem) {
  1517. listItem.listId = listId;
  1518. listItem.list = this;
  1519. listItem._registerEvent();
  1520. }
  1521. if (this.renderEvent) {
  1522. EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
  1523. }
  1524. } else if (this._forceUpdate && this.renderEvent) {
  1525. //强制更新
  1526. item._listId = listId;
  1527. if (listItem) listItem.listId = listId;
  1528. if (this.renderEvent) {
  1529. EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
  1530. }
  1531. }
  1532. this._updateListItem(listItem);
  1533. if (this._lastDisplayData.indexOf(listId) < 0) {
  1534. this._lastDisplayData.push(listId);
  1535. }
  1536. }
  1537. _updateListItem(listItem) {
  1538. if (!listItem) return;
  1539. if (this.selectedMode > SelectedType.NONE) {
  1540. var item = listItem.node;
  1541. switch (this.selectedMode) {
  1542. case SelectedType.SINGLE:
  1543. listItem.selected = this.selectedId == item._listId;
  1544. break;
  1545. case SelectedType.MULT:
  1546. listItem.selected = this.multSelected.indexOf(item._listId) >= 0;
  1547. break;
  1548. }
  1549. }
  1550. } //仅虚拟列表用
  1551. _resetItemSize(item) {
  1552. return;
  1553. var size;
  1554. var ut = item.getComponent(UITransform);
  1555. if (this._customSize && this._customSize[item._listId]) {
  1556. size = this._customSize[item._listId];
  1557. } else {
  1558. if (this._colLineNum > 1) ut.setContentSize(this._itemSize);else size = this._sizeType ? this._itemSize.height : this._itemSize.width;
  1559. }
  1560. if (size) {
  1561. if (this._sizeType) ut.height = size;else ut.width = size;
  1562. }
  1563. }
  1564. /**
  1565. * 更新Item位置
  1566. * @param {Number||Node} listIdOrItem
  1567. */
  1568. _updateItemPos(listIdOrItem) {
  1569. var item = isNaN(listIdOrItem) ? listIdOrItem : this.getItemByListId(listIdOrItem);
  1570. var pos = this.getItemPos(item._listId);
  1571. item.setPosition(pos.x, pos.y);
  1572. }
  1573. /**
  1574. * 设置多选
  1575. * @param {Array} args 可以是单个listId,也可是个listId数组
  1576. * @param {Boolean} bool 值,如果为null的话,则直接用args覆盖
  1577. */
  1578. setMultSelected(args, bool) {
  1579. var t = this;
  1580. if (!t.checkInited()) return;
  1581. if (!Array.isArray(args)) {
  1582. args = [args];
  1583. }
  1584. if (bool == null) {
  1585. t.multSelected = args;
  1586. } else {
  1587. var listId, sub;
  1588. if (bool) {
  1589. for (var n = args.length - 1; n >= 0; n--) {
  1590. listId = args[n];
  1591. sub = t.multSelected.indexOf(listId);
  1592. if (sub < 0) {
  1593. t.multSelected.push(listId);
  1594. }
  1595. }
  1596. } else {
  1597. for (var _n3 = args.length - 1; _n3 >= 0; _n3--) {
  1598. listId = args[_n3];
  1599. sub = t.multSelected.indexOf(listId);
  1600. if (sub >= 0) {
  1601. t.multSelected.splice(sub, 1);
  1602. }
  1603. }
  1604. }
  1605. }
  1606. t._forceUpdate = true;
  1607. t._onScrolling();
  1608. }
  1609. /**
  1610. * 获取多选数据
  1611. * @returns
  1612. */
  1613. getMultSelected() {
  1614. return this.multSelected;
  1615. }
  1616. /**
  1617. * 多选是否有选择
  1618. * @param {number} listId 索引
  1619. * @returns
  1620. */
  1621. hasMultSelected(listId) {
  1622. return this.multSelected && this.multSelected.indexOf(listId) >= 0;
  1623. }
  1624. /**
  1625. * 更新指定的Item
  1626. * @param {Array} args 单个listId,或者数组
  1627. * @returns
  1628. */
  1629. updateItem(args) {
  1630. if (!this.checkInited()) return;
  1631. if (!Array.isArray(args)) {
  1632. args = [args];
  1633. }
  1634. for (var n = 0, len = args.length; n < len; n++) {
  1635. var listId = args[n];
  1636. var item = this.getItemByListId(listId);
  1637. if (item) EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
  1638. }
  1639. }
  1640. /**
  1641. * 更新全部
  1642. */
  1643. updateAll() {
  1644. if (!this.checkInited()) return;
  1645. this.numItems = this.numItems;
  1646. }
  1647. /**
  1648. * 根据ListID获取Item
  1649. * @param {Number} listId
  1650. * @returns
  1651. */
  1652. getItemByListId(listId) {
  1653. if (this.content) {
  1654. for (var n = this.content.children.length - 1; n >= 0; n--) {
  1655. var item = this.content.children[n];
  1656. if (item._listId == listId) return item;
  1657. }
  1658. }
  1659. }
  1660. /**
  1661. * 获取在显示区域外的Item
  1662. * @returns
  1663. */
  1664. _getOutsideItem() {
  1665. var item;
  1666. var result = [];
  1667. for (var n = this.content.children.length - 1; n >= 0; n--) {
  1668. item = this.content.children[n];
  1669. if (!this.displayData.find(d => d.id == item._listId)) {
  1670. result.push(item);
  1671. }
  1672. }
  1673. return result;
  1674. } //删除显示区域以外的Item
  1675. _delRedundantItem() {
  1676. if (this._virtual) {
  1677. var arr = this._getOutsideItem();
  1678. for (var n = arr.length - 1; n >= 0; n--) {
  1679. var item = arr[n];
  1680. if (this._scrollItem && item._listId == this._scrollItem._listId) continue;
  1681. item.isCached = true;
  1682. this._pool.put(item);
  1683. for (var m = this._lastDisplayData.length - 1; m >= 0; m--) {
  1684. if (this._lastDisplayData[m] == item._listId) {
  1685. this._lastDisplayData.splice(m, 1);
  1686. break;
  1687. }
  1688. }
  1689. } // cc.log('存入::', str, ' pool.length =', this._pool.length);
  1690. } else {
  1691. while (this.content.children.length > this._numItems) {
  1692. this._delSingleItem(this.content.children[this.content.children.length - 1]);
  1693. }
  1694. }
  1695. } //删除单个Item
  1696. _delSingleItem(item) {
  1697. // cc.log('DEL::', item['_listId'], item);
  1698. item.removeFromParent();
  1699. if (item.destroy) item.destroy();
  1700. item = null;
  1701. }
  1702. /**
  1703. * 动效删除Item(此方法只适用于虚拟列表,即_virtual=true)
  1704. * 一定要在回调函数里重新设置新的numItems进行刷新,毕竟本List是靠数据驱动的。
  1705. */
  1706. aniDelItem(listId, callFunc, aniType) {
  1707. var t = this;
  1708. if (!t.checkInited() || t.cyclic || !t._virtual) return console.error('This function is not allowed to be called!');
  1709. 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!');
  1710. if (t._aniDelRuning) return console.warn('Please wait for the current deletion to finish!');
  1711. var item = t.getItemByListId(listId);
  1712. var listItem;
  1713. if (!item) {
  1714. callFunc(listId);
  1715. return;
  1716. } else {
  1717. listItem = item.getComponent(_crd && ListItem === void 0 ? (_reportPossibleCrUseOfListItem({
  1718. error: Error()
  1719. }), ListItem) : ListItem);
  1720. }
  1721. t._aniDelRuning = true;
  1722. t._aniDelCB = callFunc;
  1723. t._aniDelItem = item;
  1724. t._aniDelBeforePos = item.position;
  1725. t._aniDelBeforeScale = item.scale;
  1726. var curLastId = t.displayData[t.displayData.length - 1].id;
  1727. var resetSelectedId = listItem.selected;
  1728. listItem.showAni(aniType, () => {
  1729. //判断有没有下一个,如果有的话,创建粗来
  1730. var newId;
  1731. if (curLastId < t._numItems - 2) {
  1732. newId = curLastId + 1;
  1733. }
  1734. if (newId != null) {
  1735. var newData = t._calcItemPos(newId);
  1736. t.displayData.push(newData);
  1737. if (t._virtual) t._createOrUpdateItem(newData);else t._createOrUpdateItem2(newId);
  1738. } else t._numItems--;
  1739. if (t.selectedMode == SelectedType.SINGLE) {
  1740. if (resetSelectedId) {
  1741. t._selectedId = -1;
  1742. } else if (t._selectedId - 1 >= 0) {
  1743. t._selectedId--;
  1744. }
  1745. } else if (t.selectedMode == SelectedType.MULT && t.multSelected.length) {
  1746. var sub = t.multSelected.indexOf(listId);
  1747. if (sub >= 0) {
  1748. t.multSelected.splice(sub, 1);
  1749. } //多选的数据,在其后的全部减一
  1750. for (var n = t.multSelected.length - 1; n >= 0; n--) {
  1751. var id = t.multSelected[n];
  1752. if (id >= listId) t.multSelected[n]--;
  1753. }
  1754. }
  1755. if (t._customSize) {
  1756. if (t._customSize[listId]) delete t._customSize[listId];
  1757. var newCustomSize = {};
  1758. var size;
  1759. for (var _id in t._customSize) {
  1760. size = t._customSize[_id];
  1761. var idNumber = parseInt(_id);
  1762. newCustomSize[idNumber - (idNumber >= listId ? 1 : 0)] = size;
  1763. }
  1764. t._customSize = newCustomSize;
  1765. } //后面的Item向前怼的动效
  1766. var sec = .2333;
  1767. var twe, haveCB;
  1768. for (var _n4 = newId != null ? newId : curLastId; _n4 >= listId + 1; _n4--) {
  1769. item = t.getItemByListId(_n4);
  1770. if (item) {
  1771. var posData = t._calcItemPos(_n4 - 1);
  1772. twe = tween(item).to(sec, {
  1773. position: new Vec3(posData.x, posData.y, 0)
  1774. });
  1775. if (_n4 <= listId + 1) {
  1776. haveCB = true;
  1777. twe.call(() => {
  1778. t._aniDelRuning = false;
  1779. callFunc(listId);
  1780. delete t._aniDelCB;
  1781. });
  1782. }
  1783. twe.start();
  1784. }
  1785. }
  1786. if (!haveCB) {
  1787. t._aniDelRuning = false;
  1788. callFunc(listId);
  1789. t._aniDelCB = null;
  1790. }
  1791. }, true);
  1792. }
  1793. /**
  1794. * 滚动到..
  1795. * @param {Number} listId 索引(如果<0,则滚到首个Item位置,如果>=_numItems,则滚到最末Item位置)
  1796. * @param {Number} timeInSecond 时间
  1797. * @param {Number} offset 索引目标位置偏移,0-1
  1798. * @param {Boolean} overStress 滚动后是否强调该Item(这只是个实验功能)
  1799. */
  1800. scrollTo(listId, timeInSecond, offset, overStress) {
  1801. if (timeInSecond === void 0) {
  1802. timeInSecond = .5;
  1803. }
  1804. if (offset === void 0) {
  1805. offset = null;
  1806. }
  1807. if (overStress === void 0) {
  1808. overStress = false;
  1809. }
  1810. var t = this;
  1811. if (!t.checkInited(false)) return; // t._scrollView.stopAutoScroll();
  1812. if (timeInSecond == null) //默认0.5
  1813. timeInSecond = .5;else if (timeInSecond < 0) timeInSecond = 0;
  1814. if (listId < 0) listId = 0;else if (listId >= t._numItems) listId = t._numItems - 1; // 以防设置了numItems之后layout的尺寸还未更新
  1815. if (!t._virtual && t._layout && t._layout.enabled) t._layout.updateLayout();
  1816. var pos = t.getItemPos(listId);
  1817. if (!pos) {
  1818. return DEV && console.error('pos is null', listId);
  1819. }
  1820. var targetX, targetY;
  1821. switch (t._alignCalcType) {
  1822. case 1:
  1823. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1824. targetX = pos.left;
  1825. if (offset != null) targetX -= t._thisNodeUt.width * offset;else targetX -= t._leftGap;
  1826. pos = new Vec3(targetX, 0, 0);
  1827. break;
  1828. case 2:
  1829. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1830. targetX = pos.right - t._thisNodeUt.width;
  1831. if (offset != null) targetX += t._thisNodeUt.width * offset;else targetX += t._rightGap;
  1832. pos = new Vec3(targetX + t._contentUt.width, 0, 0);
  1833. break;
  1834. case 3:
  1835. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1836. targetY = pos.top;
  1837. if (offset != null) targetY += t._thisNodeUt.height * offset;else targetY += t._topGap;
  1838. pos = new Vec3(0, -targetY, 0);
  1839. break;
  1840. case 4:
  1841. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1842. targetY = pos.bottom + t._thisNodeUt.height;
  1843. if (offset != null) targetY -= t._thisNodeUt.height * offset;else targetY -= t._bottomGap;
  1844. pos = new Vec3(0, -targetY + t._contentUt.height, 0);
  1845. break;
  1846. }
  1847. var viewPos = t.content.getPosition();
  1848. viewPos = Math.abs(t._sizeType ? viewPos.y : viewPos.x);
  1849. var comparePos = t._sizeType ? pos.y : pos.x;
  1850. var runScroll = Math.abs((t._scrollPos != null ? t._scrollPos : viewPos) - comparePos) > .5; // cc.log(runScroll, t._scrollPos, viewPos, comparePos)
  1851. // t._scrollView.stopAutoScroll();
  1852. if (runScroll) {
  1853. t._scrollView.scrollToOffset(pos, timeInSecond);
  1854. t._scrollToListId = listId;
  1855. t._scrollToEndTime = new Date().getTime() / 1000 + timeInSecond; // cc.log(listId, t.content.width, t.content.getPosition(), pos);
  1856. t._scrollToSo = t.scheduleOnce(() => {
  1857. if (!t._adheringBarrier) {
  1858. t.adhering = t._adheringBarrier = false;
  1859. }
  1860. t._scrollPos = t._scrollToListId = t._scrollToEndTime = t._scrollToSo = null; //cc.log('2222222222', t._adheringBarrier)
  1861. if (overStress) {
  1862. // t.scrollToListId = listId;
  1863. var item = t.getItemByListId(listId);
  1864. if (item) {
  1865. tween(item).to(.1, {
  1866. scale: 1.05
  1867. }).to(.1, {
  1868. scale: 1
  1869. }).start();
  1870. }
  1871. }
  1872. }, timeInSecond + .1);
  1873. if (timeInSecond <= 0) {
  1874. t._onScrolling();
  1875. }
  1876. }
  1877. }
  1878. /**
  1879. * 计算当前滚动窗最近的Item
  1880. */
  1881. _calcNearestItem() {
  1882. var t = this;
  1883. t.nearestListId = null;
  1884. var data, center;
  1885. if (t._virtual) t._calcViewPos();
  1886. var vTop, vRight, vBottom, vLeft;
  1887. vTop = t.viewTop;
  1888. vRight = t.viewRight;
  1889. vBottom = t.viewBottom;
  1890. vLeft = t.viewLeft;
  1891. var breakFor = false;
  1892. for (var n = 0; n < t.content.children.length && !breakFor; n += t._colLineNum) {
  1893. data = t._virtual ? t.displayData[n] : t._calcExistItemPos(n);
  1894. if (data) {
  1895. center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
  1896. switch (t._alignCalcType) {
  1897. case 1:
  1898. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1899. if (data.right >= vLeft) {
  1900. t.nearestListId = data.id;
  1901. if (vLeft > center) t.nearestListId += t._colLineNum;
  1902. breakFor = true;
  1903. }
  1904. break;
  1905. case 2:
  1906. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1907. if (data.left <= vRight) {
  1908. t.nearestListId = data.id;
  1909. if (vRight < center) t.nearestListId += t._colLineNum;
  1910. breakFor = true;
  1911. }
  1912. break;
  1913. case 3:
  1914. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1915. if (data.bottom <= vTop) {
  1916. t.nearestListId = data.id;
  1917. if (vTop < center) t.nearestListId += t._colLineNum;
  1918. breakFor = true;
  1919. }
  1920. break;
  1921. case 4:
  1922. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1923. if (data.top >= vBottom) {
  1924. t.nearestListId = data.id;
  1925. if (vBottom > center) t.nearestListId += t._colLineNum;
  1926. breakFor = true;
  1927. }
  1928. break;
  1929. }
  1930. }
  1931. } //判断最后一个Item。。。(哎,这些判断真心恶心,判断了前面的还要判断最后一个。。。一开始呢,就只有一个布局(单列布局),那时候代码才三百行,后来就想着完善啊,艹..这坑真深,现在这行数都一千五了= =||)
  1932. data = t._virtual ? t.displayData[t.displayItemNum - 1] : t._calcExistItemPos(t._numItems - 1);
  1933. if (data && data.id == t._numItems - 1) {
  1934. center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
  1935. switch (t._alignCalcType) {
  1936. case 1:
  1937. //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
  1938. if (vRight > center) t.nearestListId = data.id;
  1939. break;
  1940. case 2:
  1941. //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
  1942. if (vLeft < center) t.nearestListId = data.id;
  1943. break;
  1944. case 3:
  1945. //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
  1946. if (vBottom < center) t.nearestListId = data.id;
  1947. break;
  1948. case 4:
  1949. //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
  1950. if (vTop > center) t.nearestListId = data.id;
  1951. break;
  1952. }
  1953. } // cc.log('t.nearestListId =', t.nearestListId);
  1954. } //上一页
  1955. prePage(timeInSecond) {
  1956. if (timeInSecond === void 0) {
  1957. timeInSecond = .5;
  1958. }
  1959. // cc.log('👈');
  1960. if (!this.checkInited()) return;
  1961. this.skipPage(this.curPageNum - 1, timeInSecond);
  1962. } //下一页
  1963. nextPage(timeInSecond) {
  1964. if (timeInSecond === void 0) {
  1965. timeInSecond = .5;
  1966. }
  1967. // cc.log('👉');
  1968. if (!this.checkInited()) return;
  1969. this.skipPage(this.curPageNum + 1, timeInSecond);
  1970. } //跳转到第几页
  1971. skipPage(pageNum, timeInSecond) {
  1972. var t = this;
  1973. if (!t.checkInited()) return;
  1974. if (t._slideMode != SlideType.PAGE) return console.error('This function is not allowed to be called, Must SlideMode = PAGE!');
  1975. if (pageNum < 0 || pageNum >= t._numItems) return;
  1976. if (t.curPageNum == pageNum) return; // cc.log(pageNum);
  1977. t.curPageNum = pageNum;
  1978. if (t.pageChangeEvent) {
  1979. EventHandler.emitEvents([t.pageChangeEvent], pageNum);
  1980. }
  1981. t.scrollTo(pageNum, timeInSecond);
  1982. } //计算 CustomSize(这个函数还是保留吧,某些罕见的情况的确还是需要手动计算customSize的)
  1983. calcCustomSize(numItems) {
  1984. var t = this;
  1985. if (!t.checkInited()) return;
  1986. if (!t._itemTmp) return console.error('Unset template item!');
  1987. if (!t.renderEvent) return console.error('Unset Render-Event!');
  1988. t._customSize = {};
  1989. var temp = instantiate(t._itemTmp);
  1990. var ut = temp.getComponent(UITransform);
  1991. t.content.addChild(temp);
  1992. for (var n = 0; n < numItems; n++) {
  1993. EventHandler.emitEvents([t.renderEvent], temp, n);
  1994. if (ut.height != t._itemSize.height || ut.width != t._itemSize.width) {
  1995. t._customSize[n] = t._sizeType ? ut.height : ut.width;
  1996. }
  1997. }
  1998. if (!Object.keys(t._customSize).length) t._customSize = null;
  1999. temp.removeFromParent();
  2000. if (temp.destroy) temp.destroy();
  2001. return t._customSize;
  2002. }
  2003. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "templateType", [_dec5], {
  2004. configurable: true,
  2005. enumerable: true,
  2006. writable: true,
  2007. initializer: function initializer() {
  2008. return TemplateType.NODE;
  2009. }
  2010. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tmpNode", [_dec6], {
  2011. configurable: true,
  2012. enumerable: true,
  2013. writable: true,
  2014. initializer: function initializer() {
  2015. return null;
  2016. }
  2017. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "tmpPrefab", [_dec7], {
  2018. configurable: true,
  2019. enumerable: true,
  2020. writable: true,
  2021. initializer: function initializer() {
  2022. return null;
  2023. }
  2024. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_slideMode", [_dec8], {
  2025. configurable: true,
  2026. enumerable: true,
  2027. writable: true,
  2028. initializer: function initializer() {
  2029. return SlideType.NORMAL;
  2030. }
  2031. }), _applyDecoratedDescriptor(_class2.prototype, "slideMode", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "slideMode"), _class2.prototype), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "pageDistance", [_dec10], {
  2032. configurable: true,
  2033. enumerable: true,
  2034. writable: true,
  2035. initializer: function initializer() {
  2036. return .3;
  2037. }
  2038. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "pageChangeEvent", [_dec11], {
  2039. configurable: true,
  2040. enumerable: true,
  2041. writable: true,
  2042. initializer: function initializer() {
  2043. return new EventHandler();
  2044. }
  2045. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "_virtual", [_dec12], {
  2046. configurable: true,
  2047. enumerable: true,
  2048. writable: true,
  2049. initializer: function initializer() {
  2050. return true;
  2051. }
  2052. }), _applyDecoratedDescriptor(_class2.prototype, "virtual", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "virtual"), _class2.prototype), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "cyclic", [_dec14], {
  2053. configurable: true,
  2054. enumerable: true,
  2055. writable: true,
  2056. initializer: function initializer() {
  2057. return false;
  2058. }
  2059. }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "lackCenter", [_dec15], {
  2060. configurable: true,
  2061. enumerable: true,
  2062. writable: true,
  2063. initializer: function initializer() {
  2064. return false;
  2065. }
  2066. }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "lackSlide", [_dec16], {
  2067. configurable: true,
  2068. enumerable: true,
  2069. writable: true,
  2070. initializer: function initializer() {
  2071. return false;
  2072. }
  2073. }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "_updateRate", [_dec17], {
  2074. configurable: true,
  2075. enumerable: true,
  2076. writable: true,
  2077. initializer: function initializer() {
  2078. return 0;
  2079. }
  2080. }), _applyDecoratedDescriptor(_class2.prototype, "updateRate", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "updateRate"), _class2.prototype), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "frameByFrameRenderNum", [_dec19], {
  2081. configurable: true,
  2082. enumerable: true,
  2083. writable: true,
  2084. initializer: function initializer() {
  2085. return 0;
  2086. }
  2087. }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "renderEvent", [_dec20], {
  2088. configurable: true,
  2089. enumerable: true,
  2090. writable: true,
  2091. initializer: function initializer() {
  2092. return new EventHandler();
  2093. }
  2094. }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "selectedMode", [_dec21], {
  2095. configurable: true,
  2096. enumerable: true,
  2097. writable: true,
  2098. initializer: function initializer() {
  2099. return SelectedType.NONE;
  2100. }
  2101. }), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "selectedEvent", [_dec22], {
  2102. configurable: true,
  2103. enumerable: true,
  2104. writable: true,
  2105. initializer: function initializer() {
  2106. return new EventHandler();
  2107. }
  2108. }), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "repeatEventSingle", [_dec23], {
  2109. configurable: true,
  2110. enumerable: true,
  2111. writable: true,
  2112. initializer: function initializer() {
  2113. return false;
  2114. }
  2115. }), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "_numItems", [_dec24], {
  2116. configurable: true,
  2117. enumerable: true,
  2118. writable: true,
  2119. initializer: function initializer() {
  2120. return 0;
  2121. }
  2122. })), _class2)) || _class) || _class) || _class) || _class) || _class));
  2123. _cclegacy._RF.pop();
  2124. _crd = false;
  2125. }
  2126. };
  2127. });
  2128. //# sourceMappingURL=d9ffd842e0d1c5a0c6b29396f172e2772497d53b.js.map