@nativescript-community/ui-collectionview 5.3.8 → 5.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1255 @@
1
+ var _a, _b;
2
+ /* eslint-disable no-redeclare */
3
+ import { ChangeType, ContentView, CoreTypes, Length, Property, ProxyViewContainer, Trace, Utils, View, ViewBase, booleanConverter, paddingBottomProperty, paddingLeftProperty, paddingRightProperty, paddingTopProperty, profile } from '@nativescript/core';
4
+ import { itemOverlapProperty, reorderLongPressEnabledProperty, reorderingEnabledProperty, reverseLayoutProperty, scrollBarIndicatorVisibleProperty } from '.';
5
+ import { CLog, CLogTypes, CollectionViewBase, ListViewViewTypes, isScrollEnabledProperty, orientationProperty } from './index-common';
6
+ export * from './index-common';
7
+ var SimpleCallback = /** @class */ (function (_super) {
8
+ __extends(SimpleCallback, _super);
9
+ function SimpleCallback(param1, param2) {
10
+ var _this = _super.call(this, param1, param2) || this;
11
+ _this.startPosition = -1;
12
+ _this.endPosition = -1;
13
+ return global.__native(_this);
14
+ }
15
+ SimpleCallback.prototype.onMove = function (recyclerview, viewHolder, target) {
16
+ var _a;
17
+ var startPosition = viewHolder.getAdapterPosition();
18
+ var endPosition = target.getAdapterPosition();
19
+ if (this.startPosition === -1) {
20
+ this.startPosition = startPosition;
21
+ }
22
+ this.endPosition = endPosition;
23
+ var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
24
+ if (owner) {
25
+ owner._reorderItemInSource(startPosition, endPosition);
26
+ return true;
27
+ }
28
+ return false;
29
+ };
30
+ SimpleCallback.prototype.onSelectedChanged = function (viewHolder, state) {
31
+ var _a;
32
+ if (viewHolder) {
33
+ if (this.startPosition === -1) {
34
+ this.startPosition = viewHolder.getAdapterPosition();
35
+ }
36
+ }
37
+ if (!viewHolder) {
38
+ // this is where we identify the end of the drag and call the end event
39
+ var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get();
40
+ if (this.endPosition === -1) {
41
+ this.endPosition = this.startPosition;
42
+ }
43
+ if (owner) {
44
+ var item = owner.getItemAtIndex(this.startPosition);
45
+ owner._callItemReorderedEvent(this.startPosition, this.endPosition, item);
46
+ }
47
+ this.startPosition = -1;
48
+ this.endPosition = -1;
49
+ owner.isDragging = false;
50
+ }
51
+ };
52
+ SimpleCallback.prototype.onSwiped = function (viewHolder, direction) { };
53
+ SimpleCallback.prototype.isItemViewSwipeEnabled = function () {
54
+ // disabled for now
55
+ return false;
56
+ };
57
+ SimpleCallback.prototype.isLongPressDragEnabled = function () {
58
+ // we use our custom longpress gesture handler
59
+ return false;
60
+ };
61
+ return SimpleCallback;
62
+ }(androidx.recyclerview.widget.ItemTouchHelper.SimpleCallback));
63
+ var LongPressGestureListenerImpl = /** @class */ (function (_super) {
64
+ __extends(LongPressGestureListenerImpl, _super);
65
+ function LongPressGestureListenerImpl(_owner) {
66
+ var _this = _super.call(this) || this;
67
+ _this._owner = _owner;
68
+ return global.__native(_this);
69
+ }
70
+ LongPressGestureListenerImpl.prototype.onLongPress = function (motionEvent) {
71
+ var _a;
72
+ var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.get();
73
+ if (owner) {
74
+ owner.onReorderLongPress(motionEvent);
75
+ }
76
+ };
77
+ return LongPressGestureListenerImpl;
78
+ }(android.view.GestureDetector.SimpleOnGestureListener));
79
+ let LayoutParams;
80
+ const extraLayoutSpaceProperty = new Property({
81
+ name: 'extraLayoutSpace'
82
+ });
83
+ const itemViewCacheSizeProperty = new Property({
84
+ name: 'itemViewCacheSize'
85
+ });
86
+ const nestedScrollingEnabledProperty = new Property({
87
+ name: 'nestedScrollingEnabled',
88
+ defaultValue: true,
89
+ valueConverter: booleanConverter
90
+ });
91
+ export var SnapPosition;
92
+ (function (SnapPosition) {
93
+ SnapPosition[SnapPosition["START"] = 0] = "START";
94
+ SnapPosition[SnapPosition["END"] = 1] = "END";
95
+ })(SnapPosition || (SnapPosition = {}));
96
+ export class CollectionView extends CollectionViewBase {
97
+ constructor() {
98
+ super(...arguments);
99
+ this.templateTypeNumberString = new Map();
100
+ this.templateStringTypeNumber = new Map();
101
+ this._currentNativeItemType = 0;
102
+ this.currentSpanCount = 1;
103
+ // used to store viewHolder and thus their corresponding Views
104
+ // used to "destroy" cells when possible
105
+ this._viewHolders = new Set();
106
+ this._scrollOrLoadMoreChangeCount = 0;
107
+ this.scrolling = false;
108
+ this.needsScrollStartEvent = false;
109
+ this.animateItemUpdate = false;
110
+ this.mInPropertiesSet = false;
111
+ this.mShouldUpdateInnerSize = false;
112
+ this.mShouldUpdateSpanCount = false;
113
+ this.mShouldRefresh = false;
114
+ this.defaultPoolSize = 10;
115
+ this.desiredPoolSize = new Map();
116
+ this.isDragging = false;
117
+ this._layedOut = false;
118
+ this.bindedViewHolders = new Set();
119
+ }
120
+ onResumeNativeUpdates() {
121
+ // {N} suspends properties update on `_suspendNativeUpdates`. So we only need to do this in onResumeNativeUpdates
122
+ this.mInPropertiesSet = true;
123
+ super.onResumeNativeUpdates();
124
+ this.mInPropertiesSet = false;
125
+ if (this.mShouldUpdateInnerSize) {
126
+ this.updateInnerSize();
127
+ }
128
+ if (this.mShouldUpdateSpanCount) {
129
+ this.updateSpanCount();
130
+ }
131
+ if (this.mShouldRefresh) {
132
+ this.refresh();
133
+ }
134
+ }
135
+ createNativeView() {
136
+ // storing the class in a property for reuse in the future cause a materializing which is pretty slow!
137
+ if (!CollectionViewRecyclerView) {
138
+ CollectionViewRecyclerView = com.nativescript.collectionview.RecyclerView;
139
+ }
140
+ const recyclerView = CollectionViewRecyclerView.createRecyclerView(this._context);
141
+ // const expMgr = new RecyclerViewExpandableItemManager(null);
142
+ // adapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true); //Make headers sticky
143
+ // Endless scroll with 1 item threshold
144
+ // .setLoadingMoreAtStartUp(true)
145
+ // .setEndlessScrollListener(this, new ProgressItem())
146
+ // .setEndlessScrollThreshold(1); //Default=1
147
+ // const fastScroller = new com.l4digital.fastscroll.FastScroller(this._context);
148
+ // fastScroller.setSectionIndexer(adapter);
149
+ // fastScroller.attachRecyclerView(recyclerView);
150
+ return recyclerView;
151
+ }
152
+ initNativeView() {
153
+ super.initNativeView();
154
+ const nativeView = this.nativeViewProtected;
155
+ if (!this.recycledViewPool) {
156
+ this.recycledViewPool = new com.nativescript.collectionview.RecycledViewPool();
157
+ this.recycledViewPoolDisposeListener = new com.nativescript.collectionview.RecycledViewPool.ViewPoolListener({
158
+ onViewHolderDisposed: (holder) => {
159
+ if (Trace.isEnabled()) {
160
+ CLog(CLogTypes.log, 'onViewHolderDisposed', holder);
161
+ }
162
+ if (this._viewHolders) {
163
+ this._viewHolders.delete(holder);
164
+ }
165
+ const isNonSync = holder['defaultItemView'] === true;
166
+ const view = isNonSync ? holder.view.content : holder.view;
167
+ this.notifyForItemAtIndex(CollectionViewBase.itemDisposingEvent, view, holder.getAdapterPosition(), view.bindingContext, holder);
168
+ if (view && view.isLoaded) {
169
+ view.callUnloaded();
170
+ }
171
+ view._isAddedToNativeVisualTree = false;
172
+ //@ts-ignore
173
+ view.parent = null;
174
+ view._tearDownUI();
175
+ }
176
+ });
177
+ this.recycledViewPool.mListener = this.recycledViewPoolDisposeListener;
178
+ }
179
+ if (Trace.isEnabled() || this.hasListeners(CollectionViewBase.itemRecyclingEvent)) {
180
+ const recyclerListener = (this.recyclerListener = new androidx.recyclerview.widget.RecyclerView.RecyclerListener({
181
+ onViewRecycled: (holder) => {
182
+ if (Trace.isEnabled()) {
183
+ CLog(CLogTypes.log, 'onViewRecycled', this, nativeView, holder);
184
+ }
185
+ const isNonSync = holder['defaultItemView'] === true;
186
+ const view = isNonSync ? holder.view.content : holder.view;
187
+ this.notifyForItemAtIndex(CollectionViewBase.itemRecyclingEvent, view, holder.getAdapterPosition(), view.bindingContext, holder);
188
+ }
189
+ }));
190
+ nativeView.setRecyclerListener(recyclerListener);
191
+ }
192
+ nativeView.setRecycledViewPool(this.recycledViewPool);
193
+ let layoutManager;
194
+ if (CollectionViewBase.layoutStyles[this.layoutStyle]) {
195
+ layoutManager = CollectionViewBase.layoutStyles[this.layoutStyle].createLayout(this);
196
+ }
197
+ else {
198
+ layoutManager = new com.nativescript.collectionview.PreCachingGridLayoutManager(this._context, 1);
199
+ if (this.hasListeners(CollectionView.layoutCompletedEvent)) {
200
+ layoutManager.layoutCompletedListener = new com.nativescript.collectionview.GridLayoutManager.LayoutCompletedListener({
201
+ onLayoutCompleted: () => {
202
+ this.notify({ eventName: CollectionView.layoutCompletedEvent });
203
+ }
204
+ });
205
+ }
206
+ // layoutManager = new PreCachingGridLayoutManager(this._context, 1);
207
+ // (layoutManager as any).owner = new WeakRef(this);
208
+ }
209
+ // this.spanSize
210
+ nativeView.setLayoutManager(layoutManager);
211
+ nativeView.layoutManager = layoutManager;
212
+ nativeView.sizeChangedListener = new com.nativescript.collectionview.SizeChangedListener({
213
+ onLayout: (changed, left, top, right, bottom) => changed && this.onLayout(left, top, right, bottom),
214
+ onMeasure: (widthMeasureSpec, heightMeasureSpec) => this.onMeasure(widthMeasureSpec, heightMeasureSpec)
215
+ });
216
+ this.spanSize = this._getSpanSize;
217
+ // const animator = new jp.wasabeef.recyclerview.animators.FadeInAnimator();
218
+ // // animator.setInterpolator(new android.view.animation.OvershootInterpolator());
219
+ // animator.setMoveDuration(200);
220
+ // Change animations are enabled by default since support-v7-recyclerview v22.
221
+ // Need to disable them when using animation indicator.
222
+ // animator.setSupportsChangeAnimations(false);
223
+ // nativeView.setItemAnimator(animator);
224
+ // enforce the first refresh for the collectionview to be ready as soon as possible
225
+ this.refresh(true);
226
+ }
227
+ disposeNativeView() {
228
+ // this.eachChildView((view) => {
229
+ // view.parent._removeView(view);
230
+ // return true;
231
+ // });
232
+ // this._realizedItems.clear();
233
+ const nativeView = this.nativeViewProtected;
234
+ nativeView.setRecyclerListener(null);
235
+ nativeView.setRecycledViewPool(null);
236
+ this.recycledViewPoolDisposeListener = null;
237
+ this.recycledViewPool = null;
238
+ if (nativeView.scrollListener) {
239
+ this.nativeView.removeOnScrollListener(nativeView.scrollListener);
240
+ nativeView.scrollListener = null;
241
+ this._nScrollListener = null;
242
+ }
243
+ nativeView.sizeChangedListener = null;
244
+ nativeView.layoutManager = null;
245
+ this._listViewAdapter = null;
246
+ this._itemTouchHelper = null;
247
+ this._simpleItemTouchCallback = null;
248
+ this.disposeViewHolderViews();
249
+ this.clearTemplateTypes();
250
+ super.disposeNativeView();
251
+ }
252
+ onLoaded() {
253
+ super.onLoaded();
254
+ this.attachScrollListener();
255
+ // this.refresh();
256
+ }
257
+ getViewForItemAtIndex(index) {
258
+ return this.enumerateViewHolders((v) => (v.getAdapterPosition() === index ? v.view : undefined));
259
+ }
260
+ //@ts-ignore
261
+ set spanSize(inter) {
262
+ if (!(typeof inter === 'function')) {
263
+ return;
264
+ }
265
+ this._getSpanSize = inter;
266
+ const layoutManager = this.layoutManager;
267
+ if (layoutManager && layoutManager['setSpanSizeLookup']) {
268
+ if (inter) {
269
+ layoutManager['setSpanSizeLookup'](new com.nativescript.collectionview.SpanSizeLookup(new com.nativescript.collectionview.SpanSizeLookup.Interface({
270
+ getSpanSize: (position) => {
271
+ const dataItem = this.getItemAtIndex(position);
272
+ return Math.min(inter(dataItem, position), this.currentSpanCount);
273
+ }
274
+ })));
275
+ }
276
+ else {
277
+ layoutManager['setSpanSizeLookup'](null);
278
+ }
279
+ }
280
+ }
281
+ get spanSize() {
282
+ return this._getSpanSize;
283
+ }
284
+ attachScrollListener() {
285
+ if (this._scrollOrLoadMoreChangeCount > 0 && this.isLoaded) {
286
+ const nativeView = this.nativeViewProtected;
287
+ if (!nativeView.scrollListener) {
288
+ this._nScrollListener = new com.nativescript.collectionview.OnScrollListener.Listener({
289
+ onScrollStateChanged: this.onScrollStateChanged.bind(this),
290
+ onScrolled: this.onScrolled.bind(this)
291
+ });
292
+ const scrollListener = new com.nativescript.collectionview.OnScrollListener(this._nScrollListener);
293
+ nativeView.addOnScrollListener(scrollListener);
294
+ nativeView.scrollListener = scrollListener;
295
+ }
296
+ }
297
+ }
298
+ detachScrollListener() {
299
+ if (this._scrollOrLoadMoreChangeCount === 0 && this.isLoaded) {
300
+ const nativeView = this.nativeViewProtected;
301
+ if (nativeView.scrollListener) {
302
+ this.nativeView.removeOnScrollListener(nativeView.scrollListener);
303
+ nativeView.scrollListener = null;
304
+ this._nScrollListener = null;
305
+ }
306
+ }
307
+ }
308
+ computeScrollEventData(view, eventName, dx, dy) {
309
+ const horizontal = this.isHorizontal();
310
+ const offset = horizontal ? view.computeHorizontalScrollOffset() : view.computeVerticalScrollOffset();
311
+ const range = horizontal ? view.computeHorizontalScrollRange() : view.computeVerticalScrollRange();
312
+ const extent = horizontal ? view.computeHorizontalScrollExtent() : view.computeVerticalScrollExtent();
313
+ return {
314
+ object: this,
315
+ eventName,
316
+ scrollOffset: offset / Utils.layout.getDisplayDensity(),
317
+ scrollOffsetPercentage: offset / (range - extent),
318
+ dx,
319
+ dy
320
+ };
321
+ }
322
+ onScrolled(view, dx, dy) {
323
+ if (!this || !this.scrolling) {
324
+ return;
325
+ }
326
+ if (this.needsScrollStartEvent) {
327
+ this.needsScrollStartEvent = false;
328
+ if (this.hasListeners(CollectionViewBase.scrollStartEvent)) {
329
+ this.notify(this.computeScrollEventData(view, CollectionViewBase.scrollStartEvent, dx, dy));
330
+ }
331
+ }
332
+ if (this.hasListeners(CollectionViewBase.scrollEvent)) {
333
+ this.notify(this.computeScrollEventData(view, CollectionViewBase.scrollEvent, dx, dy));
334
+ }
335
+ if (this.hasListeners(CollectionViewBase.loadMoreItemsEvent) && this.items) {
336
+ const layoutManager = view.getLayoutManager();
337
+ if (layoutManager['findLastCompletelyVisibleItemPosition']) {
338
+ const lastVisibleItemPos = layoutManager['findLastCompletelyVisibleItemPosition']();
339
+ const loadMoreItemIndex = this.items.length - this.loadMoreThreshold;
340
+ if (lastVisibleItemPos === loadMoreItemIndex) {
341
+ this.notify({ eventName: CollectionViewBase.loadMoreItemsEvent });
342
+ }
343
+ }
344
+ else if (layoutManager['findLastCompletelyVisibleItemPositions'] && layoutManager['getSpanCount']) {
345
+ let positions = Array.create('int', layoutManager['getSpanCount']());
346
+ positions = layoutManager['findLastCompletelyVisibleItemPositions'](positions);
347
+ let lastVisibleItemPos = 0;
348
+ for (let i = 0; i < positions.length; i++) {
349
+ if (positions[i] > lastVisibleItemPos) {
350
+ lastVisibleItemPos = positions[i];
351
+ }
352
+ }
353
+ const loadMoreItemIndex = this.items.length - this.loadMoreThreshold;
354
+ if (lastVisibleItemPos >= loadMoreItemIndex) {
355
+ this.notify({ eventName: CollectionViewBase.loadMoreItemsEvent });
356
+ }
357
+ }
358
+ }
359
+ }
360
+ onScrollStateChanged(view, newState) {
361
+ if (this.scrolling && newState === 0) {
362
+ // SCROLL_STATE_IDLE
363
+ this.scrolling = false;
364
+ if (this.hasListeners(CollectionViewBase.scrollEndEvent)) {
365
+ this.notify(this.computeScrollEventData(view, CollectionViewBase.scrollEndEvent));
366
+ }
367
+ }
368
+ else if (!this.scrolling && newState === 1) {
369
+ //SCROLL_STATE_DRAGGING
370
+ this.needsScrollStartEvent = true;
371
+ this.scrolling = true;
372
+ }
373
+ }
374
+ addEventListener(arg, callback, thisArg) {
375
+ super.addEventListener(arg, callback, thisArg);
376
+ if (arg === CollectionViewBase.scrollEvent || arg === CollectionViewBase.scrollStartEvent || arg === CollectionViewBase.scrollEndEvent || arg === CollectionViewBase.loadMoreItemsEvent) {
377
+ this._scrollOrLoadMoreChangeCount++;
378
+ this.attachScrollListener();
379
+ }
380
+ }
381
+ removeEventListener(arg, callback, thisArg) {
382
+ super.removeEventListener(arg, callback, thisArg);
383
+ if (arg === CollectionViewBase.scrollEvent || arg === CollectionViewBase.scrollStartEvent || arg === CollectionViewBase.scrollEndEvent || arg === CollectionViewBase.loadMoreItemsEvent) {
384
+ this._scrollOrLoadMoreChangeCount--;
385
+ this.detachScrollListener();
386
+ }
387
+ }
388
+ //@ts-ignore
389
+ get android() {
390
+ return this.nativeView;
391
+ }
392
+ get layoutManager() {
393
+ return this.nativeViewProtected && this.nativeViewProtected.layoutManager;
394
+ }
395
+ _getViewLayoutParams() {
396
+ if (this.isHorizontal()) {
397
+ if (!this._hlayoutParams) {
398
+ LayoutParams = LayoutParams || android.view.ViewGroup.LayoutParams;
399
+ this._hlayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
400
+ }
401
+ return this._hlayoutParams;
402
+ }
403
+ else {
404
+ if (!this._vlayoutParams) {
405
+ LayoutParams = LayoutParams || android.view.ViewGroup.LayoutParams;
406
+ this._vlayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
407
+ }
408
+ return this._vlayoutParams;
409
+ }
410
+ }
411
+ setNativePoolSize(key, nativeIndex) {
412
+ if (this.desiredPoolSize.has(key)) {
413
+ this.nativeViewProtected.getRecycledViewPool().setMaxRecycledViews(nativeIndex, this.desiredPoolSize.get(key));
414
+ }
415
+ else {
416
+ if (this.defaultPoolSize >= 0) {
417
+ this.nativeViewProtected.getRecycledViewPool().setMaxRecycledViews(nativeIndex, this.defaultPoolSize);
418
+ }
419
+ }
420
+ }
421
+ setPoolSizes() {
422
+ if (!this.nativeViewProtected || !this.templateTypeNumberString) {
423
+ return;
424
+ }
425
+ this.desiredPoolSize.forEach((v, k) => {
426
+ if (this.templateTypeNumberString.has(k)) {
427
+ this.nativeViewProtected.getRecycledViewPool().setMaxRecycledViews(this.templateTypeNumberString.get(k), v);
428
+ }
429
+ });
430
+ }
431
+ setPoolSize(key, size) {
432
+ this.desiredPoolSize.set(key, size);
433
+ this.setPoolSizes();
434
+ }
435
+ [paddingTopProperty.getDefault]() {
436
+ return { value: this._defaultPaddingTop, unit: 'px' };
437
+ }
438
+ [paddingTopProperty.setNative](value) {
439
+ this._setPadding({ top: this.effectivePaddingTop });
440
+ }
441
+ [paddingRightProperty.getDefault]() {
442
+ return { value: this._defaultPaddingRight, unit: 'px' };
443
+ }
444
+ [paddingRightProperty.setNative](value) {
445
+ this._setPadding({ right: this.effectivePaddingRight });
446
+ }
447
+ [paddingBottomProperty.getDefault]() {
448
+ return { value: this._defaultPaddingBottom, unit: 'px' };
449
+ }
450
+ [paddingBottomProperty.setNative](value) {
451
+ this._setPadding({ bottom: this.effectivePaddingBottom });
452
+ }
453
+ [paddingLeftProperty.getDefault]() {
454
+ return { value: this._defaultPaddingLeft, unit: 'px' };
455
+ }
456
+ [paddingLeftProperty.setNative](value) {
457
+ this._setPadding({ left: this.effectivePaddingLeft });
458
+ }
459
+ [itemOverlapProperty.setNative](value) {
460
+ if (!value) {
461
+ if (this.decorator) {
462
+ this.nativeViewProtected.removeItemDecoration(this.decorator);
463
+ this.decorator = null;
464
+ }
465
+ }
466
+ else {
467
+ if (!this.decorator) {
468
+ this.decorator = new com.nativescript.collectionview.OverlapDecoration();
469
+ this.nativeViewProtected.addItemDecoration(this.decorator);
470
+ }
471
+ this.decorator.top = Length.toDevicePixels(value[0], 0);
472
+ this.decorator.right = Length.toDevicePixels(value[1], 0);
473
+ this.decorator.bottom = Length.toDevicePixels(value[2], 0);
474
+ this.decorator.left = Length.toDevicePixels(value[3], 0);
475
+ }
476
+ }
477
+ [orientationProperty.getDefault]() {
478
+ return 'vertical';
479
+ }
480
+ [orientationProperty.setNative](value) {
481
+ const layoutManager = this.layoutManager;
482
+ if (!layoutManager || !layoutManager['setOrientation']) {
483
+ return;
484
+ }
485
+ if (this.isHorizontal()) {
486
+ layoutManager['setOrientation'](0);
487
+ }
488
+ else {
489
+ layoutManager['setOrientation'](1);
490
+ }
491
+ this.updateScrollBarVisibility(this.scrollBarIndicatorVisible);
492
+ }
493
+ [isScrollEnabledProperty.setNative](value) {
494
+ const layoutManager = this.layoutManager;
495
+ if (layoutManager && layoutManager.setScrollEnabled) {
496
+ layoutManager.setScrollEnabled(value);
497
+ }
498
+ }
499
+ [reverseLayoutProperty.setNative](value) {
500
+ const layoutManager = this.layoutManager;
501
+ if (layoutManager && layoutManager.setReverseLayout) {
502
+ layoutManager.setReverseLayout(value);
503
+ // layoutManager['setStackFromEnd'](value);
504
+ }
505
+ }
506
+ [nestedScrollingEnabledProperty.setNative](value) {
507
+ this.nativeViewProtected.setNestedScrollingEnabled(value);
508
+ }
509
+ [extraLayoutSpaceProperty.setNative](value) {
510
+ const layoutManager = this.layoutManager;
511
+ if (layoutManager && layoutManager['setExtraLayoutSpace']) {
512
+ layoutManager['setExtraLayoutSpace'](value);
513
+ }
514
+ }
515
+ [itemViewCacheSizeProperty.setNative](value) {
516
+ this.nativeViewProtected.setItemViewCacheSize(value);
517
+ }
518
+ [scrollBarIndicatorVisibleProperty.getDefault]() {
519
+ return true;
520
+ }
521
+ [scrollBarIndicatorVisibleProperty.setNative](value) {
522
+ this.updateScrollBarVisibility(value);
523
+ }
524
+ updateScrollBarVisibility(value) {
525
+ if (!this.nativeViewProtected) {
526
+ return;
527
+ }
528
+ if (this.orientation === 'horizontal') {
529
+ this.nativeViewProtected.setHorizontalScrollBarEnabled(value);
530
+ }
531
+ else {
532
+ this.nativeViewProtected.setVerticalScrollBarEnabled(value);
533
+ }
534
+ }
535
+ enumerateViewHolders(cb) {
536
+ let result, v;
537
+ for (let it = this._viewHolders.values(), cellItemView = null; (cellItemView = it.next().value);) {
538
+ if (cellItemView['position'] === undefined) {
539
+ continue;
540
+ }
541
+ result = cb(cellItemView);
542
+ if (result) {
543
+ return result;
544
+ }
545
+ }
546
+ return result;
547
+ }
548
+ async enumerateViewHoldersAsync(cb) {
549
+ let result, v;
550
+ for (let it = this._viewHolders.values(), cellItemView = null; (cellItemView = it.next().value);) {
551
+ if (cellItemView['position'] === undefined) {
552
+ continue;
553
+ }
554
+ result = await cb(cellItemView);
555
+ if (result) {
556
+ return result;
557
+ }
558
+ }
559
+ return result;
560
+ }
561
+ startDragging(index) {
562
+ if (this.reorderEnabled && this._itemTouchHelper) {
563
+ // let viewHolder: CollectionViewCellHolder;
564
+ const viewHolder = this.enumerateViewHolders((v) => (v.getAdapterPosition() === index ? v : undefined));
565
+ if (viewHolder) {
566
+ this.startViewHolderDragging(index, viewHolder);
567
+ }
568
+ }
569
+ }
570
+ startViewHolderDragging(index, viewHolder) {
571
+ // isDragging is to prevent longPress from triggering and starting a new drag
572
+ // when triggered manually
573
+ if (!this.isDragging && this.shouldMoveItemAtIndex(index)) {
574
+ this.isDragging = true;
575
+ this._itemTouchHelper.startDrag(viewHolder);
576
+ }
577
+ }
578
+ onReorderLongPress(motionEvent) {
579
+ const collectionView = this.nativeViewProtected;
580
+ if (!collectionView) {
581
+ return;
582
+ }
583
+ const view = collectionView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
584
+ const viewHolder = view != null ? collectionView.getChildViewHolder(view) : null;
585
+ if (viewHolder) {
586
+ this.startViewHolderDragging(viewHolder.getAdapterPosition(), viewHolder);
587
+ }
588
+ }
589
+ _reorderItemInSource(oldPosition, newPosition) {
590
+ const adapter = this._listViewAdapter;
591
+ // 3. Tell adapter to render the model update.
592
+ adapter.notifyItemMoved(oldPosition, newPosition);
593
+ // on android _reorderItemInSource is call on every "move" and needs to update the adapter/items
594
+ // we will call events only at then end
595
+ super._reorderItemInSource(oldPosition, newPosition, false);
596
+ }
597
+ [_a = reorderLongPressEnabledProperty.setNative](value) {
598
+ if (value) {
599
+ if (!this._longPressGesture) {
600
+ this._longPressGesture = new androidx.core.view.GestureDetectorCompat(this._context, new LongPressGestureListenerImpl(new WeakRef(this)));
601
+ this._itemTouchListerner = new androidx.recyclerview.widget.RecyclerView.OnItemTouchListener({
602
+ onInterceptTouchEvent: (view, event) => {
603
+ if (this.reorderEnabled && this._longPressGesture) {
604
+ this._longPressGesture.onTouchEvent(event);
605
+ }
606
+ return false;
607
+ },
608
+ onTouchEvent: (param0, param1) => { },
609
+ onRequestDisallowInterceptTouchEvent: (disallowIntercept) => { }
610
+ });
611
+ }
612
+ this.nativeViewProtected.addOnItemTouchListener(this._itemTouchListerner);
613
+ }
614
+ else {
615
+ if (this._itemTouchListerner) {
616
+ this.nativeViewProtected.removeOnItemTouchListener(this._itemTouchListerner);
617
+ }
618
+ }
619
+ }
620
+ [_b = reorderingEnabledProperty.setNative](value) {
621
+ if (value) {
622
+ if (!this._simpleItemTouchCallback) {
623
+ const ItemTouchHelper = androidx.recyclerview.widget.ItemTouchHelper;
624
+ this._simpleItemTouchCallback = new SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.START | ItemTouchHelper.END, 0);
625
+ this._simpleItemTouchCallback.owner = new WeakRef(this);
626
+ this._itemTouchHelper = new androidx.recyclerview.widget.ItemTouchHelper(this._simpleItemTouchCallback);
627
+ this._itemTouchHelper.attachToRecyclerView(this.nativeViewProtected);
628
+ }
629
+ }
630
+ }
631
+ onItemViewLoaderChanged() {
632
+ if (this.itemViewLoader) {
633
+ this.refresh();
634
+ }
635
+ }
636
+ onItemTemplateSelectorChanged(oldValue, newValue) {
637
+ super.onItemTemplateSelectorChanged(oldValue, newValue);
638
+ this.clearTemplateTypes();
639
+ this.refresh();
640
+ }
641
+ onItemTemplateChanged(oldValue, newValue) {
642
+ super.onItemTemplateChanged(oldValue, newValue); // TODO: update current template with the new one
643
+ this.refresh();
644
+ }
645
+ onItemTemplatesChanged(oldValue, newValue) {
646
+ super.onItemTemplatesChanged(oldValue, newValue); // TODO: update current template with the new one
647
+ this.refresh();
648
+ }
649
+ updateSpanCount(requestLayout = true) {
650
+ if (this.mInPropertiesSet) {
651
+ this.mShouldUpdateSpanCount = true;
652
+ return false;
653
+ }
654
+ this.mShouldUpdateSpanCount = false;
655
+ const layoutManager = this.layoutManager;
656
+ if (layoutManager && layoutManager['setSpanCount']) {
657
+ const newValue = (this.currentSpanCount = this.computeSpanCount());
658
+ if (newValue !== layoutManager['getSpanCount']()) {
659
+ layoutManager['setSpanCount'](newValue);
660
+ if (requestLayout) {
661
+ layoutManager.requestLayout();
662
+ }
663
+ return true;
664
+ }
665
+ }
666
+ return false;
667
+ }
668
+ updateInnerSize() {
669
+ if (this.mInPropertiesSet) {
670
+ this.mShouldUpdateInnerSize = true;
671
+ return false;
672
+ }
673
+ this.mShouldUpdateInnerSize = false;
674
+ const result = super.updateInnerSize();
675
+ if (result) {
676
+ this.updateSpanCount();
677
+ }
678
+ // there is no need to call refresh if it was triggered before with same size.
679
+ // this refresh is just to handle size change
680
+ const layoutKey = this._innerWidth + '_' + this._innerHeight;
681
+ if (this._isDataDirty || (this._lastLayoutKey && this._lastLayoutKey !== layoutKey)) {
682
+ // setTimeout(() => this.refresh(false), 0);
683
+ }
684
+ this._lastLayoutKey = layoutKey;
685
+ return result;
686
+ }
687
+ _onColWidthPropertyChanged(oldValue, newValue) {
688
+ this.updateSpanCount();
689
+ super._onColWidthPropertyChanged(oldValue, newValue);
690
+ }
691
+ _onRowHeightPropertyChanged(oldValue, newValue) {
692
+ this.updateSpanCount();
693
+ super._onRowHeightPropertyChanged(oldValue, newValue);
694
+ }
695
+ onLayout(left, top, right, bottom) {
696
+ this._layedOut = true;
697
+ // super.onLayout(left, top, right, bottom);
698
+ const p = CollectionViewBase.plugins[this.layoutStyle];
699
+ if (p && p.onLayout) {
700
+ p.onLayout(this, left, top, right, bottom);
701
+ }
702
+ this.plugins.forEach((k) => {
703
+ const p = CollectionViewBase.plugins[k];
704
+ p.onLayout && p.onLayout(this, left, top, right, bottom);
705
+ });
706
+ }
707
+ onMeasure(widthMeasureSpec, heightMeasureSpec) {
708
+ const lastLayoutKey = this._lastLayoutKey;
709
+ this.updateInnerSize();
710
+ if (lastLayoutKey !== this._lastLayoutKey) {
711
+ //we need to refresh visible cells so that they measure to the new size
712
+ // for some reason it gets animated even with setSupportsChangeAnimations(false)
713
+ // so we clear until it is done
714
+ const nativeView = this.nativeViewProtected;
715
+ const animator = nativeView.getItemAnimator();
716
+ nativeView.setItemAnimator(null);
717
+ this.refreshVisibleItems();
718
+ setTimeout(() => {
719
+ nativeView.setItemAnimator(animator);
720
+ }, 0);
721
+ }
722
+ const p = CollectionViewBase.plugins[this.layoutStyle];
723
+ if (p && p.onMeasure) {
724
+ p.onMeasure(this, widthMeasureSpec, heightMeasureSpec);
725
+ }
726
+ this.plugins.forEach((k) => {
727
+ const p = CollectionViewBase.plugins[k];
728
+ p.onMeasure && p.onMeasure(this, widthMeasureSpec, heightMeasureSpec);
729
+ });
730
+ }
731
+ onSourceCollectionChanged(event) {
732
+ if (!this._listViewAdapter || this._dataUpdatesSuspended) {
733
+ return;
734
+ }
735
+ if (Trace.isEnabled()) {
736
+ CLog(CLogTypes.log, 'onItemsChanged', event.action, event.index, event.addedCount, event.removed, event.removed && event.removed.length);
737
+ }
738
+ switch (event.action) {
739
+ case ChangeType.Delete: {
740
+ this._listViewAdapter.notifyItemRangeRemoved(event.index, event.removed.length);
741
+ return;
742
+ }
743
+ case ChangeType.Add: {
744
+ if (event.addedCount > 0) {
745
+ this._listViewAdapter.notifyItemRangeInserted(event.index, event.addedCount);
746
+ }
747
+ // Reload the items to avoid duplicate Load on Demand indicators:
748
+ return;
749
+ }
750
+ case ChangeType.Update: {
751
+ if (event.addedCount > 0) {
752
+ this._listViewAdapter.notifyItemRangeChanged(event.index, event.addedCount);
753
+ }
754
+ return;
755
+ }
756
+ case ChangeType.Splice: {
757
+ const added = event.addedCount;
758
+ const removed = (event.removed && event.removed.length) || 0;
759
+ if (added > 0 && added === removed) {
760
+ // notifyItemRangeChanged wont create a fade effect
761
+ if (!this.animateItemUpdate) {
762
+ this._listViewAdapter.notifyItemRangeChanged(event.index, added);
763
+ }
764
+ else {
765
+ this._listViewAdapter.notifyItemRangeRemoved(event.index, added);
766
+ this._listViewAdapter.notifyItemRangeInserted(event.index, added);
767
+ }
768
+ }
769
+ else {
770
+ if (!this.animateItemUpdate) {
771
+ if (added > removed) {
772
+ if (removed > 0) {
773
+ this._listViewAdapter.notifyItemRangeChanged(event.index, removed);
774
+ }
775
+ this._listViewAdapter.notifyItemRangeInserted(event.index + removed, added - removed);
776
+ }
777
+ else {
778
+ if (added > 0) {
779
+ this._listViewAdapter.notifyItemRangeChanged(event.index, added);
780
+ }
781
+ this._listViewAdapter.notifyItemRangeRemoved(event.index + added, removed - added);
782
+ }
783
+ }
784
+ else {
785
+ if (event.removed && event.removed.length > 0) {
786
+ this._listViewAdapter.notifyItemRangeRemoved(event.index, event.removed.length);
787
+ }
788
+ if (event.addedCount > 0) {
789
+ this._listViewAdapter.notifyItemRangeInserted(event.index, event.addedCount);
790
+ }
791
+ }
792
+ }
793
+ return;
794
+ }
795
+ }
796
+ this._listViewAdapter.notifyDataSetChanged();
797
+ }
798
+ eachChild(callback) {
799
+ // used for css updates (like theme change)
800
+ this.enumerateViewHolders((v) => {
801
+ const view = v.view;
802
+ if (view) {
803
+ if (view.parent instanceof CollectionView) {
804
+ callback(view);
805
+ }
806
+ else {
807
+ // in some cases (like item is unloaded from another place (like angular) view.parent becomes undefined)
808
+ if (view.parent) {
809
+ callback(view.parent);
810
+ }
811
+ }
812
+ }
813
+ });
814
+ }
815
+ async eachChildAsync(callback) {
816
+ return this.enumerateViewHoldersAsync(async (v) => {
817
+ const view = v.view;
818
+ if (view) {
819
+ if (view.parent instanceof CollectionView) {
820
+ await callback(view);
821
+ }
822
+ else {
823
+ // in some cases (like item is unloaded from another place (like angular) view.parent becomes undefined)
824
+ if (view.parent) {
825
+ await callback(view.parent);
826
+ }
827
+ }
828
+ }
829
+ });
830
+ }
831
+ refreshVisibleItems() {
832
+ const view = this.nativeViewProtected;
833
+ if (!view) {
834
+ return;
835
+ }
836
+ const ids = Array.from(this.bindedViewHolders).sort((a, b) => a - b);
837
+ this._listViewAdapter.notifyItemRangeChanged(ids[0], ids[ids.length - 1] - ids[0] + 1);
838
+ }
839
+ isItemAtIndexVisible(index) {
840
+ const view = this.nativeViewProtected;
841
+ if (!view) {
842
+ return false;
843
+ }
844
+ const layoutManager = this.layoutManager;
845
+ if (layoutManager['findFirstVisibleItemPosition']) {
846
+ const first = layoutManager.findFirstVisibleItemPosition();
847
+ const last = layoutManager.findLastVisibleItemPosition();
848
+ return index >= first && index <= last;
849
+ }
850
+ return false;
851
+ }
852
+ refresh(forceRefresh = false, updateSpanCountRequestsLayout = false) {
853
+ if (this.mInPropertiesSet) {
854
+ this.mShouldRefresh = true;
855
+ return;
856
+ }
857
+ this.mShouldRefresh = false;
858
+ const view = this.nativeViewProtected;
859
+ if (!view) {
860
+ return;
861
+ }
862
+ // seems like we refresh sooner
863
+ // not sure why it was needed before and not now.
864
+ if (!forceRefresh && (!this.isLoaded || !this.nativeView)) {
865
+ this._isDataDirty = true;
866
+ return;
867
+ }
868
+ this._isDataDirty = false;
869
+ this._lastLayoutKey = this._innerWidth + '_' + this._innerHeight;
870
+ let adapter = this._listViewAdapter;
871
+ if (!adapter) {
872
+ adapter = this._listViewAdapter = this.createComposedAdapter(view);
873
+ adapter.setHasStableIds(!!this._itemIdGenerator);
874
+ view.setAdapter(adapter);
875
+ }
876
+ else if (!view.getAdapter()) {
877
+ view.setAdapter(adapter);
878
+ }
879
+ this.updateSpanCount(updateSpanCountRequestsLayout);
880
+ adapter.notifyDataSetChanged();
881
+ this.notify({ eventName: CollectionViewBase.dataPopulatedEvent });
882
+ }
883
+ //@ts-ignore
884
+ get scrollOffset() {
885
+ const view = this.nativeViewProtected;
886
+ if (!view) {
887
+ return 0;
888
+ }
889
+ return (this.isHorizontal() ? view.computeHorizontalScrollOffset() : view.computeVerticalScrollOffset()) / Utils.layout.getDisplayDensity();
890
+ }
891
+ get verticalOffsetX() {
892
+ const view = this.nativeViewProtected;
893
+ if (!view) {
894
+ return 0;
895
+ }
896
+ return view.computeHorizontalScrollOffset() / Utils.layout.getDisplayDensity();
897
+ }
898
+ get verticalOffsetY() {
899
+ const view = this.nativeViewProtected;
900
+ if (!view) {
901
+ return 0;
902
+ }
903
+ return view.computeVerticalScrollOffset() / Utils.layout.getDisplayDensity();
904
+ }
905
+ scrollToIndex(index, animated = true, snap = SnapPosition.START) {
906
+ const view = this.nativeViewProtected;
907
+ if (!view) {
908
+ return;
909
+ }
910
+ if (animated) {
911
+ view.smoothScrollToPosition(index, snap);
912
+ }
913
+ else {
914
+ view.scrollToPosition(index);
915
+ }
916
+ }
917
+ scrollToOffset(offSetValue) {
918
+ const view = this.nativeViewProtected;
919
+ if (view && this.isScrollEnabled) {
920
+ if (this.orientation === 'horizontal') {
921
+ view.scrollBy(offSetValue, 0);
922
+ }
923
+ else {
924
+ view.scrollBy(0, offSetValue);
925
+ }
926
+ }
927
+ }
928
+ _setPadding(newPadding) {
929
+ const nativeView = this.nativeViewProtected;
930
+ const padding = {
931
+ top: nativeView.getPaddingTop(),
932
+ right: nativeView.getPaddingRight(),
933
+ bottom: nativeView.getPaddingBottom(),
934
+ left: nativeView.getPaddingLeft()
935
+ };
936
+ // tslint:disable-next-line:prefer-object-spread
937
+ const newValue = Object.assign(padding, newPadding);
938
+ nativeView.setClipToPadding(false);
939
+ nativeView.setPadding(newValue.left, newValue.top, newValue.right, newValue.bottom);
940
+ this.updateInnerSize();
941
+ }
942
+ createComposedAdapter(recyclerView) {
943
+ const adapter = new com.nativescript.collectionview.Adapter();
944
+ adapter.adapterInterface = new com.nativescript.collectionview.AdapterInterface({
945
+ getItemId: this.getItemId.bind(this),
946
+ getItemViewType: this.getItemViewType.bind(this),
947
+ getItemCount: this.getItemCount.bind(this),
948
+ onCreateViewHolder: this.onCreateViewHolder.bind(this),
949
+ onBindViewHolder: this.onBindViewHolder.bind(this),
950
+ onViewRecycled: this.onViewRecycled.bind(this)
951
+ });
952
+ // const composedAdapter = new com.h6ah4i.android.widget.advrecyclerview.composedadapter.ComposedAdapter();
953
+ // composedAdapter.addAdapter(new CollectionViewAdapter(new WeakRef(this)));
954
+ return adapter;
955
+ }
956
+ getItemCount() {
957
+ return this.items ? this.items.length : 0;
958
+ }
959
+ getItem(i) {
960
+ if (this.items && i < this.items.length) {
961
+ return this.getItemAtIndex(i);
962
+ }
963
+ return null;
964
+ }
965
+ getItemId(i) {
966
+ let id = -1;
967
+ if (this._itemIdGenerator && this.items) {
968
+ const item = this.getItemAtIndex(i);
969
+ id = this._itemIdGenerator(item, i, this.items);
970
+ }
971
+ return long(id);
972
+ }
973
+ onItemIdGeneratorChanged(oldValue, newValue) {
974
+ super.onItemIdGeneratorChanged(oldValue, newValue);
975
+ if (this._listViewAdapter) {
976
+ this._listViewAdapter.setHasStableIds(!!newValue);
977
+ }
978
+ }
979
+ clearTemplateTypes() {
980
+ this._currentNativeItemType = 0;
981
+ this.templateTypeNumberString.clear();
982
+ this.templateStringTypeNumber.clear();
983
+ }
984
+ getItemViewType(position) {
985
+ let selectorType = 'default';
986
+ if (this._itemTemplateSelector) {
987
+ const selector = this._itemTemplateSelector;
988
+ const dataItem = this.getItemAtIndex(position);
989
+ if (dataItem) {
990
+ selectorType = selector.call(this, dataItem, position, this.items);
991
+ }
992
+ }
993
+ return this.templateKeyToNativeItem(selectorType);
994
+ // if (!this.templateTypeNumberString.has(selectorType)) {
995
+ // resultType = this._currentNativeItemType;
996
+ // this.templateTypeNumberString.set(selectorType, resultType);
997
+ // this.templateStringTypeNumber.set(resultType, selectorType);
998
+ // this._currentNativeItemType++;
999
+ // } else {
1000
+ // resultType = this.templateTypeNumberString.get(selectorType);
1001
+ // }
1002
+ // return resultType;
1003
+ }
1004
+ templateKeyToNativeItem(key) {
1005
+ if (!this.templateTypeNumberString) {
1006
+ this.templateTypeNumberString = new Map();
1007
+ this._currentNativeItemType = 0;
1008
+ this._itemTemplatesInternal.forEach((v, i) => {
1009
+ this.templateTypeNumberString.set(v.key, this._currentNativeItemType);
1010
+ this.templateStringTypeNumber.set(this._currentNativeItemType, v.key);
1011
+ this.setNativePoolSize(v.key, this._currentNativeItemType);
1012
+ this._currentNativeItemType++;
1013
+ });
1014
+ this._currentNativeItemType = Math.max(this._itemTemplatesInternal.size, 100);
1015
+ // templates will be numbered 0,1,2,3... for named templates
1016
+ // default/unnamed templates will be numbered 100, 101, 102, 103...
1017
+ }
1018
+ if (!this.templateTypeNumberString.has(key)) {
1019
+ this.templateTypeNumberString.set(key, this._currentNativeItemType);
1020
+ this.templateStringTypeNumber.set(this._currentNativeItemType, key);
1021
+ this.setNativePoolSize(key, this._currentNativeItemType);
1022
+ this._currentNativeItemType++;
1023
+ }
1024
+ return this.templateTypeNumberString.get(key);
1025
+ }
1026
+ // public nativeItemToTemplateKey(item: number): string {
1027
+ // let result: string;
1028
+ // this.templateTypeNumberString?.forEach((value, key, map) => {
1029
+ // if (value === item) {
1030
+ // result = key;
1031
+ // }
1032
+ // }, this);
1033
+ // return result;
1034
+ // }
1035
+ disposeViewHolderViews() {
1036
+ this.enumerateViewHolders((v) => {
1037
+ const view = v.view;
1038
+ if (view) {
1039
+ if (view.isLoaded) {
1040
+ view.callUnloaded();
1041
+ }
1042
+ view._isAddedToNativeVisualTree = false;
1043
+ view._tearDownUI();
1044
+ }
1045
+ v.view = null;
1046
+ v.clickListener = null;
1047
+ });
1048
+ this._viewHolders = new Set();
1049
+ }
1050
+ getKeyByValue(viewType) {
1051
+ return this.templateStringTypeNumber.get(viewType);
1052
+ }
1053
+ onCreateViewHolder(parent, viewType) {
1054
+ const start = Date.now();
1055
+ let view = this.getViewForViewType(ListViewViewTypes.ItemView, this.getKeyByValue(viewType));
1056
+ const isNonSync = view === undefined;
1057
+ // dont create unecessary StackLayout if template.createView returns. Will happend when not using Vue or angular
1058
+ if (isNonSync || view instanceof ProxyViewContainer) {
1059
+ const parentView = new ContentView();
1060
+ parentView.id = 'collectionViewHolder';
1061
+ view = parentView;
1062
+ }
1063
+ view._setupAsRootView(this._context);
1064
+ view._isAddedToNativeVisualTree = true;
1065
+ //@ts-ignore
1066
+ view.parent = this;
1067
+ view.callLoaded();
1068
+ if (!CollectionViewCellHolder) {
1069
+ CollectionViewCellHolder = com.nativescript.collectionview.CollectionViewCellHolder;
1070
+ }
1071
+ const holder = new CollectionViewCellHolder(view.nativeView);
1072
+ const collectionView = this;
1073
+ const clickListener = new android.view.View.OnClickListener({
1074
+ onClick: () => {
1075
+ const position = holder.getAdapterPosition();
1076
+ collectionView.notify({
1077
+ eventName: CollectionViewBase.itemTapEvent,
1078
+ object: collectionView,
1079
+ index: position,
1080
+ item: collectionView.getItem(position),
1081
+ view: holder.view
1082
+ });
1083
+ }
1084
+ });
1085
+ view.nativeView.setOnClickListener(clickListener);
1086
+ holder.clickListener = clickListener;
1087
+ holder.view = view;
1088
+ const layoutParams = this._getViewLayoutParams();
1089
+ view.nativeView.setLayoutParams(layoutParams);
1090
+ if (isNonSync) {
1091
+ holder['defaultItemView'] = true;
1092
+ }
1093
+ this._viewHolders.add(holder);
1094
+ if (Trace.isEnabled()) {
1095
+ CLog(CLogTypes.log, 'onCreateViewHolder', this, this.nativeView, viewType, this.getKeyByValue(viewType), holder, Date.now() - start, 'ms');
1096
+ }
1097
+ return holder;
1098
+ }
1099
+ notifyForItemAtIndex(eventName, view, index, bindingContext, native) {
1100
+ const args = { eventName, object: this, index, view, ios: native, bindingContext };
1101
+ this.notify(args);
1102
+ return args;
1103
+ }
1104
+ onBindViewHolder(holder, position) {
1105
+ const start = Date.now();
1106
+ if (Trace.isEnabled()) {
1107
+ CLog(CLogTypes.log, 'onBindViewHolder', this, this.nativeView, position, holder, holder.view);
1108
+ }
1109
+ let view = holder.view;
1110
+ const isNonSync = holder['defaultItemView'] === true;
1111
+ view = isNonSync ? view.content : view;
1112
+ const bindingContext = this._prepareItem(view, position);
1113
+ if (holder['position'] !== undefined) {
1114
+ this.bindedViewHolders.delete(holder['position']);
1115
+ }
1116
+ holder['position'] = position;
1117
+ this.bindedViewHolders.add(holder['position']);
1118
+ const args = this.notifyForItemAtIndex(CollectionViewBase.itemLoadingEvent, view, position, bindingContext, holder);
1119
+ if (isNonSync && args.view !== view) {
1120
+ view = args.view;
1121
+ // the view has been changed on the event handler
1122
+ holder.view.content = args.view;
1123
+ }
1124
+ view.bindingContext = bindingContext;
1125
+ view.notify({ eventName: CollectionViewBase.bindedEvent });
1126
+ let width = this._effectiveColWidth;
1127
+ let height = this._effectiveRowHeight;
1128
+ if (this._getSpanSize) {
1129
+ const spanSize = this._getSpanSize(bindingContext, position);
1130
+ const horizontal = this.isHorizontal();
1131
+ if (horizontal) {
1132
+ height *= spanSize;
1133
+ }
1134
+ else {
1135
+ width *= spanSize;
1136
+ }
1137
+ }
1138
+ if (width || !view.width) {
1139
+ view.width = Utils.layout.toDeviceIndependentPixels(width);
1140
+ }
1141
+ if (height || !view.height) {
1142
+ view.height = Utils.layout.toDeviceIndependentPixels(height);
1143
+ }
1144
+ if (this.hasListeners(CollectionViewBase.displayItemEvent)) {
1145
+ this.notify({
1146
+ eventName: CollectionViewBase.displayItemEvent,
1147
+ index: position,
1148
+ object: this
1149
+ });
1150
+ }
1151
+ if (Trace.isEnabled()) {
1152
+ CLog(CLogTypes.log, 'onBindViewHolder done ', position, Date.now() - start, 'ms');
1153
+ }
1154
+ }
1155
+ onViewRecycled(holder) {
1156
+ delete this.bindedViewHolders[holder['position']];
1157
+ holder['position'] = undefined;
1158
+ }
1159
+ }
1160
+ CollectionView.layoutCompletedEvent = 'layoutCompleted';
1161
+ CollectionView.DEFAULT_TEMPLATE_VIEW_TYPE = 0;
1162
+ CollectionView.CUSTOM_TEMPLATE_ITEM_TYPE = 1;
1163
+ __decorate([
1164
+ profile
1165
+ ], CollectionView.prototype, "createNativeView", null);
1166
+ __decorate([
1167
+ profile
1168
+ ], CollectionView.prototype, "initNativeView", null);
1169
+ __decorate([
1170
+ profile
1171
+ ], CollectionView.prototype, "disposeNativeView", null);
1172
+ __decorate([
1173
+ profile
1174
+ ], CollectionView.prototype, "onLoaded", null);
1175
+ __decorate([
1176
+ profile
1177
+ ], CollectionView.prototype, "attachScrollListener", null);
1178
+ __decorate([
1179
+ profile
1180
+ ], CollectionView.prototype, "setNativePoolSize", null);
1181
+ __decorate([
1182
+ profile
1183
+ ], CollectionView.prototype, "setPoolSizes", null);
1184
+ __decorate([
1185
+ profile
1186
+ ], CollectionView.prototype, _a, null);
1187
+ __decorate([
1188
+ profile
1189
+ ], CollectionView.prototype, _b, null);
1190
+ __decorate([
1191
+ profile
1192
+ ], CollectionView.prototype, "onItemViewLoaderChanged", null);
1193
+ __decorate([
1194
+ profile
1195
+ ], CollectionView.prototype, "onItemTemplateSelectorChanged", null);
1196
+ __decorate([
1197
+ profile
1198
+ ], CollectionView.prototype, "onItemTemplateChanged", null);
1199
+ __decorate([
1200
+ profile
1201
+ ], CollectionView.prototype, "onItemTemplatesChanged", null);
1202
+ __decorate([
1203
+ profile
1204
+ ], CollectionView.prototype, "updateSpanCount", null);
1205
+ __decorate([
1206
+ profile
1207
+ ], CollectionView.prototype, "updateInnerSize", null);
1208
+ __decorate([
1209
+ profile
1210
+ ], CollectionView.prototype, "_onColWidthPropertyChanged", null);
1211
+ __decorate([
1212
+ profile
1213
+ ], CollectionView.prototype, "_onRowHeightPropertyChanged", null);
1214
+ __decorate([
1215
+ profile
1216
+ ], CollectionView.prototype, "onLayout", null);
1217
+ __decorate([
1218
+ profile
1219
+ ], CollectionView.prototype, "onMeasure", null);
1220
+ __decorate([
1221
+ profile
1222
+ ], CollectionView.prototype, "refresh", null);
1223
+ __decorate([
1224
+ profile
1225
+ ], CollectionView.prototype, "_setPadding", null);
1226
+ __decorate([
1227
+ profile
1228
+ ], CollectionView.prototype, "createComposedAdapter", null);
1229
+ __decorate([
1230
+ profile
1231
+ ], CollectionView.prototype, "clearTemplateTypes", null);
1232
+ __decorate([
1233
+ profile
1234
+ ], CollectionView.prototype, "getItemViewType", null);
1235
+ __decorate([
1236
+ profile
1237
+ ], CollectionView.prototype, "templateKeyToNativeItem", null);
1238
+ __decorate([
1239
+ profile
1240
+ ], CollectionView.prototype, "disposeViewHolderViews", null);
1241
+ __decorate([
1242
+ profile
1243
+ ], CollectionView.prototype, "onCreateViewHolder", null);
1244
+ __decorate([
1245
+ profile
1246
+ ], CollectionView.prototype, "notifyForItemAtIndex", null);
1247
+ __decorate([
1248
+ profile
1249
+ ], CollectionView.prototype, "onBindViewHolder", null);
1250
+ let CollectionViewCellHolder;
1251
+ let CollectionViewRecyclerView;
1252
+ itemViewCacheSizeProperty.register(CollectionViewBase);
1253
+ extraLayoutSpaceProperty.register(CollectionViewBase);
1254
+ nestedScrollingEnabledProperty.register(CollectionViewBase);
1255
+ //# sourceMappingURL=index.android.js.map