56ae9e35797d5e8240d73f72d113dd7717d70dd2.js 95 KB

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