@nativescript-community/ui-collectionview 5.3.6 → 5.3.8
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.
- package/CHANGELOG.md +8 -0
- package/package.json +2 -2
- package/angular/collectionview-comp.d.ts +0 -82
- package/angular/index.d.ts +0 -8
- package/index-common.d.ts +0 -172
- package/index-common.js +0 -692
- package/index-common.js.map +0 -1
- package/index.android.d.ts +0 -131
- package/index.android.js +0 -1219
- package/index.android.js.map +0 -1
- package/index.d.ts +0 -49
- package/index.ios.d.ts +0 -111
- package/index.ios.js +0 -1215
- package/index.ios.js.map +0 -1
- package/react/index.d.ts +0 -119
- package/react/index.js +0 -153
- package/react/index.js.map +0 -1
- package/references.d.ts +0 -3
- package/svelte/index.d.ts +0 -20
- package/svelte/index.js +0 -137
- package/svelte/index.js.map +0 -1
- package/typings/android.d.ts +0 -90
- package/typings/android.wasabeef.d.ts +0 -843
- package/typings/arv.d.ts +0 -3706
- package/typings/ios.d.ts +0 -3
- package/vue/component.d.ts +0 -38
- package/vue/component.js +0 -105
- package/vue/component.js.map +0 -1
- package/vue/index.d.ts +0 -4
- package/vue/index.js +0 -12
- package/vue/index.js.map +0 -1
- package/vue3/component.d.ts +0 -36
- package/vue3/component.js +0 -105
- package/vue3/component.js.map +0 -1
- package/vue3/index.d.ts +0 -11
- package/vue3/index.js +0 -14
- package/vue3/index.js.map +0 -1
package/index.ios.js
DELETED
@@ -1,1215 +0,0 @@
|
|
1
|
-
import { ChangeType, ContentView, CoreTypes, Observable, Property, ProxyViewContainer, Trace, Utils, View, ViewBase, paddingBottomProperty, paddingLeftProperty, paddingRightProperty, paddingTopProperty, profile } from '@nativescript/core';
|
2
|
-
import { reorderLongPressEnabledProperty, reorderingEnabledProperty, reverseLayoutProperty, scrollBarIndicatorVisibleProperty } from '.';
|
3
|
-
import { CLog, CLogTypes, CollectionViewBase, ListViewViewTypes, isBounceEnabledProperty, isScrollEnabledProperty, itemTemplatesProperty, orientationProperty } from './index-common';
|
4
|
-
export * from './index-common';
|
5
|
-
const infinity = Utils.layout.makeMeasureSpec(0, Utils.layout.UNSPECIFIED);
|
6
|
-
export var ContentInsetAdjustmentBehavior;
|
7
|
-
(function (ContentInsetAdjustmentBehavior) {
|
8
|
-
ContentInsetAdjustmentBehavior[ContentInsetAdjustmentBehavior["Always"] = 3] = "Always";
|
9
|
-
ContentInsetAdjustmentBehavior[ContentInsetAdjustmentBehavior["Automatic"] = 0] = "Automatic";
|
10
|
-
ContentInsetAdjustmentBehavior[ContentInsetAdjustmentBehavior["Never"] = 2] = "Never";
|
11
|
-
ContentInsetAdjustmentBehavior[ContentInsetAdjustmentBehavior["ScrollableAxes"] = 1] = "ScrollableAxes";
|
12
|
-
})(ContentInsetAdjustmentBehavior || (ContentInsetAdjustmentBehavior = {}));
|
13
|
-
function parseContentInsetAdjustmentBehavior(value) {
|
14
|
-
if (typeof value === 'string') {
|
15
|
-
switch (value) {
|
16
|
-
case 'always':
|
17
|
-
return ContentInsetAdjustmentBehavior.Always;
|
18
|
-
case 'never':
|
19
|
-
return ContentInsetAdjustmentBehavior.Never;
|
20
|
-
case 'scrollableAxes':
|
21
|
-
return ContentInsetAdjustmentBehavior.ScrollableAxes;
|
22
|
-
default:
|
23
|
-
case 'automatic':
|
24
|
-
return ContentInsetAdjustmentBehavior.Automatic;
|
25
|
-
}
|
26
|
-
}
|
27
|
-
else {
|
28
|
-
return value;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
export const contentInsetAdjustmentBehaviorProperty = new Property({
|
32
|
-
name: 'contentInsetAdjustmentBehavior',
|
33
|
-
valueConverter: parseContentInsetAdjustmentBehavior,
|
34
|
-
defaultValue: ContentInsetAdjustmentBehavior.Automatic
|
35
|
-
});
|
36
|
-
export var SnapPosition;
|
37
|
-
(function (SnapPosition) {
|
38
|
-
SnapPosition[SnapPosition["START"] = -1] = "START";
|
39
|
-
SnapPosition[SnapPosition["END"] = 1] = "END"; // = androidx.recyclerview.widget.LinearSmoothScroller.SNAP_TO_END
|
40
|
-
})(SnapPosition || (SnapPosition = {}));
|
41
|
-
export class CollectionView extends CollectionViewBase {
|
42
|
-
constructor() {
|
43
|
-
super();
|
44
|
-
this._preparingCell = false;
|
45
|
-
this.reorderStartingRow = -1;
|
46
|
-
this.reorderEndingRow = -1;
|
47
|
-
this.manualDragging = false;
|
48
|
-
this.scrollEnabledBeforeDragging = true;
|
49
|
-
this.needsScrollStartEvent = false;
|
50
|
-
this.isScrolling = false;
|
51
|
-
this._map = new Map();
|
52
|
-
// this._sizes = new Array<number[]>();
|
53
|
-
}
|
54
|
-
createNativeView() {
|
55
|
-
let layout;
|
56
|
-
if (CollectionViewBase.layoutStyles[this.layoutStyle]) {
|
57
|
-
layout = this._layout = CollectionViewBase.layoutStyles[this.layoutStyle].createLayout(this);
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
layout = this._layout = UICollectionViewFlowLayout.alloc().init();
|
61
|
-
}
|
62
|
-
if (layout instanceof UICollectionViewFlowLayout) {
|
63
|
-
layout.minimumLineSpacing = 0;
|
64
|
-
layout.minimumInteritemSpacing = 0;
|
65
|
-
}
|
66
|
-
const view = UICollectionView.alloc().initWithFrameCollectionViewLayout(CGRectMake(0, 0, 0, 0), layout);
|
67
|
-
view.backgroundColor = UIColor.clearColor;
|
68
|
-
this._itemTemplatesInternal.forEach((t) => {
|
69
|
-
view.registerClassForCellWithReuseIdentifier(CollectionViewCell.class(), t.key.toLowerCase());
|
70
|
-
});
|
71
|
-
view.autoresizesSubviews = false;
|
72
|
-
view.autoresizingMask = 0 /* UIViewAutoresizing.None */;
|
73
|
-
this.lastContentOffset = view.contentOffset;
|
74
|
-
return view;
|
75
|
-
}
|
76
|
-
onTemplateAdded(t) {
|
77
|
-
super.onTemplateAdded(t);
|
78
|
-
if (this.nativeViewProtected) {
|
79
|
-
this.nativeViewProtected.registerClassForCellWithReuseIdentifier(CollectionViewCell.class(), t.key.toLowerCase());
|
80
|
-
}
|
81
|
-
}
|
82
|
-
initNativeView() {
|
83
|
-
super.initNativeView();
|
84
|
-
const nativeView = this.nativeView;
|
85
|
-
this._dataSource = CollectionViewDataSource.initWithOwner(this);
|
86
|
-
nativeView.dataSource = this._dataSource;
|
87
|
-
// delegate will be set in first onLayout because we need computed _effectiveColWidth and _effectiveRowHeight
|
88
|
-
this._measureCellMap = new Map();
|
89
|
-
// waterfall requires the delegate to be set as soon as possible
|
90
|
-
// but default delegates need _effectiveRowHeight and _effectiveColWidth
|
91
|
-
// so we need to wait
|
92
|
-
const layoutStyle = CollectionViewBase.layoutStyles[this.layoutStyle];
|
93
|
-
if (layoutStyle && layoutStyle.createDelegate) {
|
94
|
-
this._delegate = layoutStyle.createDelegate(this);
|
95
|
-
this.nativeViewProtected.delegate = this._delegate;
|
96
|
-
}
|
97
|
-
this._setNativeClipToBounds();
|
98
|
-
}
|
99
|
-
disposeNativeView() {
|
100
|
-
if (Trace.isEnabled()) {
|
101
|
-
CLog(CLogTypes.log, 'disposeNativeView');
|
102
|
-
}
|
103
|
-
const nativeView = this.nativeView;
|
104
|
-
nativeView.delegate = null;
|
105
|
-
this._delegate = null;
|
106
|
-
nativeView.dataSource = null;
|
107
|
-
this._dataSource = null;
|
108
|
-
this._layout = null;
|
109
|
-
this.reorderLongPressHandler = null;
|
110
|
-
this.reorderLongPressGesture = null;
|
111
|
-
this.clearRealizedCells();
|
112
|
-
super.disposeNativeView();
|
113
|
-
}
|
114
|
-
// _onSizeChanged() {
|
115
|
-
// super._onSizeChanged();
|
116
|
-
// this.onSizeChanged(this.getMeasuredWidth(), this.getMeasuredHeight());
|
117
|
-
// }
|
118
|
-
get _childrenCount() {
|
119
|
-
return this._map.size;
|
120
|
-
}
|
121
|
-
eachChild(callback) {
|
122
|
-
// used for css updates (like theme change)
|
123
|
-
this._map.forEach((view) => {
|
124
|
-
if (view.parent instanceof CollectionView) {
|
125
|
-
callback(view);
|
126
|
-
}
|
127
|
-
else {
|
128
|
-
// in some cases (like item is unloaded from another place (like angular) view.parent becomes undefined)
|
129
|
-
if (view.parent) {
|
130
|
-
callback(view.parent);
|
131
|
-
}
|
132
|
-
}
|
133
|
-
});
|
134
|
-
}
|
135
|
-
getViewForItemAtIndex(index) {
|
136
|
-
let result;
|
137
|
-
if (this.nativeViewProtected) {
|
138
|
-
const cell = this.nativeViewProtected.cellForItemAtIndexPath(NSIndexPath.indexPathForRowInSection(index, 0));
|
139
|
-
return cell?.view;
|
140
|
-
}
|
141
|
-
return result;
|
142
|
-
}
|
143
|
-
startDragging(index, pointer) {
|
144
|
-
if (this.reorderEnabled && this.nativeViewProtected) {
|
145
|
-
this.manualDragging = true;
|
146
|
-
this.draggingStartDelta = null;
|
147
|
-
if (pointer) {
|
148
|
-
const view = this.getViewForItemAtIndex(index);
|
149
|
-
if (view) {
|
150
|
-
const size = view.nativeViewProtected.bounds.size;
|
151
|
-
const point = pointer.ios.locationInView(view.nativeViewProtected);
|
152
|
-
this.draggingStartDelta = [point.x - size.width / 2, point.y - size.height / 2];
|
153
|
-
}
|
154
|
-
}
|
155
|
-
this.nativeViewProtected.beginInteractiveMovementForItemAtIndexPath(NSIndexPath.indexPathForRowInSection(index, 0));
|
156
|
-
this.scrollEnabledBeforeDragging = this.isScrollEnabled;
|
157
|
-
this.nativeViewProtected.scrollEnabled = false;
|
158
|
-
}
|
159
|
-
}
|
160
|
-
onReorderingTouch(event) {
|
161
|
-
if (!this.manualDragging) {
|
162
|
-
return;
|
163
|
-
}
|
164
|
-
const collectionView = this.nativeViewProtected;
|
165
|
-
const pointer = event.getActivePointers()[0];
|
166
|
-
switch (event.action) {
|
167
|
-
case 'move':
|
168
|
-
let x = pointer.getX();
|
169
|
-
let y = pointer.getY();
|
170
|
-
if (this.draggingStartDelta) {
|
171
|
-
x -= this.draggingStartDelta[0];
|
172
|
-
y -= this.draggingStartDelta[1];
|
173
|
-
}
|
174
|
-
collectionView.updateInteractiveMovementTargetPosition(CGPointMake(x, y));
|
175
|
-
break;
|
176
|
-
case 'up':
|
177
|
-
this.manualDragging = false;
|
178
|
-
collectionView && collectionView.endInteractiveMovement();
|
179
|
-
this.nativeViewProtected.scrollEnabled = this.scrollEnabledBeforeDragging;
|
180
|
-
this.handleReorderEnd();
|
181
|
-
break;
|
182
|
-
case 'cancel':
|
183
|
-
this.manualDragging = false;
|
184
|
-
collectionView && collectionView.cancelInteractiveMovement();
|
185
|
-
this.nativeViewProtected.scrollEnabled = this.scrollEnabledBeforeDragging;
|
186
|
-
this.handleReorderEnd();
|
187
|
-
break;
|
188
|
-
}
|
189
|
-
}
|
190
|
-
handleReorderEnd() {
|
191
|
-
// we call all events from here because the delegate
|
192
|
-
// does not handle the case start dragging => cancel or
|
193
|
-
// start dragging => end over the same item
|
194
|
-
if (!this.reorderEndingRow) {
|
195
|
-
this.reorderEndingRow = this.reorderStartingRow;
|
196
|
-
}
|
197
|
-
const item = this.getItemAtIndex(this.reorderStartingRow);
|
198
|
-
this._callItemReorderedEvent(this.reorderStartingRow, this.reorderEndingRow, item);
|
199
|
-
this.reorderEndingRow = -1;
|
200
|
-
this.reorderEndingRow = -1;
|
201
|
-
}
|
202
|
-
onReorderLongPress(gesture) {
|
203
|
-
const collectionView = this.nativeViewProtected;
|
204
|
-
if (!collectionView) {
|
205
|
-
return;
|
206
|
-
}
|
207
|
-
switch (gesture.state) {
|
208
|
-
case 1 /* UIGestureRecognizerState.Began */:
|
209
|
-
const selectedIndexPath = collectionView.indexPathForItemAtPoint(gesture.locationInView(collectionView));
|
210
|
-
collectionView.beginInteractiveMovementForItemAtIndexPath(selectedIndexPath);
|
211
|
-
break;
|
212
|
-
case 2 /* UIGestureRecognizerState.Changed */:
|
213
|
-
collectionView.updateInteractiveMovementTargetPosition(gesture.locationInView(collectionView));
|
214
|
-
break;
|
215
|
-
case 3 /* UIGestureRecognizerState.Ended */:
|
216
|
-
collectionView.endInteractiveMovement();
|
217
|
-
this.handleReorderEnd();
|
218
|
-
break;
|
219
|
-
default:
|
220
|
-
collectionView.cancelInteractiveMovement();
|
221
|
-
this.handleReorderEnd();
|
222
|
-
break;
|
223
|
-
}
|
224
|
-
}
|
225
|
-
[contentInsetAdjustmentBehaviorProperty.setNative](value) {
|
226
|
-
this.nativeViewProtected.contentInsetAdjustmentBehavior = value;
|
227
|
-
}
|
228
|
-
[paddingTopProperty.setNative](value) {
|
229
|
-
this._setPadding({ top: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingTop) });
|
230
|
-
}
|
231
|
-
[paddingRightProperty.setNative](value) {
|
232
|
-
this._setPadding({ right: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingRight) });
|
233
|
-
}
|
234
|
-
[paddingBottomProperty.setNative](value) {
|
235
|
-
this._setPadding({ bottom: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingBottom) });
|
236
|
-
}
|
237
|
-
[paddingLeftProperty.setNative](value) {
|
238
|
-
this._setPadding({ left: Utils.layout.toDeviceIndependentPixels(this.effectivePaddingLeft) });
|
239
|
-
}
|
240
|
-
[orientationProperty.setNative](value) {
|
241
|
-
const layout = this._layout;
|
242
|
-
if (layout instanceof UICollectionViewFlowLayout) {
|
243
|
-
if (value === 'horizontal') {
|
244
|
-
layout.scrollDirection = 1 /* UICollectionViewScrollDirection.Horizontal */;
|
245
|
-
}
|
246
|
-
else {
|
247
|
-
layout.scrollDirection = 0 /* UICollectionViewScrollDirection.Vertical */;
|
248
|
-
}
|
249
|
-
}
|
250
|
-
this.updateScrollBarVisibility(this.scrollBarIndicatorVisible);
|
251
|
-
}
|
252
|
-
[isScrollEnabledProperty.setNative](value) {
|
253
|
-
this.nativeViewProtected.scrollEnabled = value;
|
254
|
-
this.scrollEnabledBeforeDragging = value;
|
255
|
-
}
|
256
|
-
[isBounceEnabledProperty.setNative](value) {
|
257
|
-
this.nativeViewProtected.bounces = value;
|
258
|
-
// this.nativeViewProtected.alwaysBounceHorizontal = value;
|
259
|
-
}
|
260
|
-
[itemTemplatesProperty.getDefault]() {
|
261
|
-
return null;
|
262
|
-
}
|
263
|
-
[reverseLayoutProperty.setNative](value) {
|
264
|
-
this.nativeViewProtected.transform = value ? CGAffineTransformMakeRotation(-Math.PI) : null;
|
265
|
-
}
|
266
|
-
[reorderLongPressEnabledProperty.setNative](value) {
|
267
|
-
if (value) {
|
268
|
-
if (!this.reorderLongPressGesture) {
|
269
|
-
this.reorderLongPressHandler = ReorderLongPressImpl.initWithOwner(new WeakRef(this));
|
270
|
-
this.reorderLongPressGesture = UILongPressGestureRecognizer.alloc().initWithTargetAction(this.reorderLongPressHandler, 'longPress');
|
271
|
-
this.nativeViewProtected.addGestureRecognizer(this.reorderLongPressGesture);
|
272
|
-
}
|
273
|
-
else {
|
274
|
-
this.reorderLongPressGesture.enabled = true;
|
275
|
-
}
|
276
|
-
}
|
277
|
-
else {
|
278
|
-
if (this.reorderLongPressGesture) {
|
279
|
-
this.reorderLongPressGesture.enabled = false;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
[reorderingEnabledProperty.setNative](value) {
|
284
|
-
if (value) {
|
285
|
-
this.on('touch', this.onReorderingTouch, this);
|
286
|
-
}
|
287
|
-
else {
|
288
|
-
this.off('touch', this.onReorderingTouch, this);
|
289
|
-
}
|
290
|
-
}
|
291
|
-
[scrollBarIndicatorVisibleProperty.getDefault]() {
|
292
|
-
return true;
|
293
|
-
}
|
294
|
-
[scrollBarIndicatorVisibleProperty.setNative](value) {
|
295
|
-
this.updateScrollBarVisibility(value);
|
296
|
-
}
|
297
|
-
updateScrollBarVisibility(value) {
|
298
|
-
if (!this.nativeViewProtected) {
|
299
|
-
return;
|
300
|
-
}
|
301
|
-
if (this.orientation === 'horizontal') {
|
302
|
-
this.nativeViewProtected.showsHorizontalScrollIndicator = value;
|
303
|
-
}
|
304
|
-
else {
|
305
|
-
this.nativeViewProtected.showsVerticalScrollIndicator = value;
|
306
|
-
}
|
307
|
-
}
|
308
|
-
eachChildView(callback) {
|
309
|
-
this._map.forEach((view, key) => {
|
310
|
-
callback(view);
|
311
|
-
});
|
312
|
-
}
|
313
|
-
onLayout(left, top, right, bottom) {
|
314
|
-
super.onLayout(left, top, right, bottom);
|
315
|
-
const p = CollectionViewBase.plugins[this.layoutStyle];
|
316
|
-
if (p && p.onLayout) {
|
317
|
-
p.onLayout(this, left, top, right, bottom);
|
318
|
-
}
|
319
|
-
this.plugins.forEach((k) => {
|
320
|
-
const p = CollectionViewBase.plugins[k];
|
321
|
-
p.onLayout && p.onLayout(this, left, top, right, bottom);
|
322
|
-
});
|
323
|
-
const layoutView = this.nativeViewProtected.collectionViewLayout;
|
324
|
-
if (!layoutView) {
|
325
|
-
return;
|
326
|
-
}
|
327
|
-
if (!this._delegate) {
|
328
|
-
const layoutStyle = CollectionViewBase.layoutStyles[this.layoutStyle];
|
329
|
-
if (layoutStyle && layoutStyle.createDelegate) {
|
330
|
-
this._delegate = layoutStyle.createDelegate(this);
|
331
|
-
}
|
332
|
-
else {
|
333
|
-
// if we use fixed col and row size we want a delegate
|
334
|
-
// without collectionViewLayoutSizeForItemAtIndexPath
|
335
|
-
// because it is not needed and faster
|
336
|
-
if (this._effectiveColWidth && this._effectiveRowHeight) {
|
337
|
-
this._delegate = UICollectionViewDelegateFixedSizeImpl.initWithOwner(this);
|
338
|
-
}
|
339
|
-
else {
|
340
|
-
this._delegate = UICollectionViewDelegateImpl.initWithOwner(this);
|
341
|
-
}
|
342
|
-
}
|
343
|
-
// this._delegate._owner = new WeakRef(this);
|
344
|
-
this.nativeViewProtected.delegate = this._delegate;
|
345
|
-
}
|
346
|
-
if (layoutView instanceof UICollectionViewFlowLayout) {
|
347
|
-
if (this._effectiveRowHeight && this._effectiveColWidth) {
|
348
|
-
layoutView.itemSize = CGSizeMake(Utils.layout.toDeviceIndependentPixels(this._effectiveColWidth), Utils.layout.toDeviceIndependentPixels(this._effectiveRowHeight));
|
349
|
-
}
|
350
|
-
else {
|
351
|
-
layoutView.estimatedItemSize = CGSizeMake(Utils.layout.toDeviceIndependentPixels(this._effectiveColWidth), Utils.layout.toDeviceIndependentPixels(this._effectiveRowHeight));
|
352
|
-
}
|
353
|
-
}
|
354
|
-
layoutView.invalidateLayout();
|
355
|
-
// there is no need to call refresh if it was triggered before with same size.
|
356
|
-
// this refresh is just to handle size change
|
357
|
-
const layoutKey = this._innerWidth + '_' + this._innerHeight;
|
358
|
-
if (this._lastLayoutKey !== layoutKey) {
|
359
|
-
this.refresh();
|
360
|
-
}
|
361
|
-
}
|
362
|
-
isHorizontal() {
|
363
|
-
return this.orientation === 'horizontal';
|
364
|
-
}
|
365
|
-
onSourceCollectionChanged(event) {
|
366
|
-
const view = this.nativeViewProtected;
|
367
|
-
if (!view || this._dataUpdatesSuspended || !this._lastLayoutKey) {
|
368
|
-
return;
|
369
|
-
}
|
370
|
-
if (Trace.isEnabled()) {
|
371
|
-
CLog(CLogTypes.log, 'onItemsChanged', ChangeType.Update, event.action, event.index, event.addedCount, event.removed && event.removed.length);
|
372
|
-
}
|
373
|
-
// we need to clear stored cell sizes and it wont be correct anymore
|
374
|
-
// this.clearCellSize();
|
375
|
-
const sizes = this._delegate instanceof UICollectionViewDelegateImpl ? this._delegate.cachedSizes : null;
|
376
|
-
switch (event.action) {
|
377
|
-
case ChangeType.Delete: {
|
378
|
-
const indexes = NSMutableArray.new();
|
379
|
-
for (let index = 0; index < event.addedCount; index++) {
|
380
|
-
indexes.addObject(NSIndexPath.indexPathForRowInSection(event.index + index, 0));
|
381
|
-
if (sizes) {
|
382
|
-
sizes.removeObjectAtIndex(event.index);
|
383
|
-
}
|
384
|
-
}
|
385
|
-
// this._sizes.splice(event.index, event.addedCount);
|
386
|
-
this.unbindUnusedCells(event.removed);
|
387
|
-
if (Trace.isEnabled()) {
|
388
|
-
CLog(CLogTypes.info, 'deleteItemsAtIndexPaths', indexes.count);
|
389
|
-
}
|
390
|
-
view.performBatchUpdatesCompletion(() => {
|
391
|
-
view.deleteItemsAtIndexPaths(indexes);
|
392
|
-
}, null);
|
393
|
-
return;
|
394
|
-
}
|
395
|
-
case ChangeType.Update: {
|
396
|
-
const indexes = NSMutableArray.new();
|
397
|
-
indexes.addObject(NSIndexPath.indexPathForRowInSection(event.index, 0));
|
398
|
-
if (sizes) {
|
399
|
-
sizes.replaceObjectAtIndexWithObject(event.index, NSValue.valueWithCGSize(CGSizeZero));
|
400
|
-
}
|
401
|
-
// this._sizes[event.index] = null;
|
402
|
-
if (Trace.isEnabled()) {
|
403
|
-
CLog(CLogTypes.info, 'reloadItemsAtIndexPaths', event.index, indexes.count);
|
404
|
-
}
|
405
|
-
view.performBatchUpdatesCompletion(() => {
|
406
|
-
view.reloadItemsAtIndexPaths(indexes);
|
407
|
-
}, null);
|
408
|
-
return;
|
409
|
-
}
|
410
|
-
case ChangeType.Add: {
|
411
|
-
const indexes = NSMutableArray.new();
|
412
|
-
for (let index = 0; index < event.addedCount; index++) {
|
413
|
-
indexes.addObject(NSIndexPath.indexPathForRowInSection(event.index + index, 0));
|
414
|
-
if (sizes) {
|
415
|
-
sizes.insertObjectAtIndex(NSValue.valueWithCGSize(CGSizeZero), event.index);
|
416
|
-
}
|
417
|
-
// this._sizes.splice(index, 0, null);
|
418
|
-
}
|
419
|
-
if (Trace.isEnabled()) {
|
420
|
-
CLog(CLogTypes.info, 'insertItemsAtIndexPaths', indexes.count);
|
421
|
-
}
|
422
|
-
view.performBatchUpdatesCompletion(() => {
|
423
|
-
view.insertItemsAtIndexPaths(indexes);
|
424
|
-
}, null);
|
425
|
-
return;
|
426
|
-
}
|
427
|
-
case ChangeType.Splice: {
|
428
|
-
view.performBatchUpdatesCompletion(() => {
|
429
|
-
const added = event.addedCount;
|
430
|
-
const removed = (event.removed && event.removed.length) || 0;
|
431
|
-
if (added > 0 && added === removed) {
|
432
|
-
const indexes = NSMutableArray.new();
|
433
|
-
for (let index = 0; index < added; index++) {
|
434
|
-
indexes.addObject(NSIndexPath.indexPathForRowInSection(event.index + index, 0));
|
435
|
-
if (sizes) {
|
436
|
-
sizes.replaceObjectAtIndexWithObject(event.index + index, NSValue.valueWithCGSize(CGSizeZero));
|
437
|
-
}
|
438
|
-
// this._sizes[event.index + index] = null;
|
439
|
-
}
|
440
|
-
view.reloadItemsAtIndexPaths(indexes);
|
441
|
-
}
|
442
|
-
else {
|
443
|
-
if (event.removed && event.removed.length > 0) {
|
444
|
-
const indexes = NSMutableArray.new();
|
445
|
-
for (let index = 0; index < event.removed.length; index++) {
|
446
|
-
indexes.addObject(NSIndexPath.indexPathForItemInSection(event.index + index, 0));
|
447
|
-
if (sizes) {
|
448
|
-
sizes.removeObjectAtIndex(event.index);
|
449
|
-
}
|
450
|
-
}
|
451
|
-
// this._sizes.splice(event.index, event.removed.length);
|
452
|
-
this.unbindUnusedCells(event.removed);
|
453
|
-
if (Trace.isEnabled()) {
|
454
|
-
CLog(CLogTypes.info, 'deleteItemsAtIndexPaths', indexes.count);
|
455
|
-
}
|
456
|
-
view.deleteItemsAtIndexPaths(indexes);
|
457
|
-
}
|
458
|
-
if (event.addedCount > 0) {
|
459
|
-
const indexes = NSMutableArray.alloc().init();
|
460
|
-
for (let index = 0; index < event.addedCount; index++) {
|
461
|
-
indexes.addObject(NSIndexPath.indexPathForItemInSection(event.index + index, 0));
|
462
|
-
if (sizes) {
|
463
|
-
sizes.insertObjectAtIndex(NSValue.valueWithCGSize(CGSizeZero), event.index);
|
464
|
-
}
|
465
|
-
// this._sizes.splice(event.index, 0, null);
|
466
|
-
}
|
467
|
-
if (Trace.isEnabled()) {
|
468
|
-
CLog(CLogTypes.info, 'insertItemsAtIndexPaths', indexes.count);
|
469
|
-
}
|
470
|
-
view.insertItemsAtIndexPaths(indexes);
|
471
|
-
}
|
472
|
-
}
|
473
|
-
// view.collectionViewLayout.invalidateLayout();
|
474
|
-
}, null);
|
475
|
-
return;
|
476
|
-
}
|
477
|
-
}
|
478
|
-
this.refresh();
|
479
|
-
}
|
480
|
-
onItemTemplatesChanged(oldValue, newValue) {
|
481
|
-
super.onItemTemplatesChanged(oldValue, newValue);
|
482
|
-
if (!this.nativeViewProtected) {
|
483
|
-
return;
|
484
|
-
}
|
485
|
-
const view = this.nativeViewProtected;
|
486
|
-
this._itemTemplatesInternal.forEach((t) => {
|
487
|
-
view.registerClassForCellWithReuseIdentifier(CollectionViewCell.class(), t.key.toLowerCase());
|
488
|
-
});
|
489
|
-
}
|
490
|
-
unbindUnusedCells(removedDataItems) {
|
491
|
-
this._map.forEach((view, nativeView, map) => {
|
492
|
-
if (!view || !view.bindingContext) {
|
493
|
-
return;
|
494
|
-
}
|
495
|
-
if (removedDataItems.indexOf(view.bindingContext) !== -1) {
|
496
|
-
view.bindingContext = undefined;
|
497
|
-
}
|
498
|
-
}, this);
|
499
|
-
}
|
500
|
-
refreshVisibleItems() {
|
501
|
-
const view = this.nativeViewProtected;
|
502
|
-
if (!view) {
|
503
|
-
return;
|
504
|
-
}
|
505
|
-
const sizes = this._delegate instanceof UICollectionViewDelegateImpl ? this._delegate.cachedSizes : null;
|
506
|
-
const visibles = view.indexPathsForVisibleItems;
|
507
|
-
if (sizes) {
|
508
|
-
const indexes = Array.from(visibles);
|
509
|
-
indexes.forEach((value) => {
|
510
|
-
sizes.replaceObjectAtIndexWithObject(value.row, NSValue.valueWithCGSize(CGSizeZero));
|
511
|
-
});
|
512
|
-
}
|
513
|
-
UIView.performWithoutAnimation(() => {
|
514
|
-
view.performBatchUpdatesCompletion(() => {
|
515
|
-
view.reloadItemsAtIndexPaths(visibles);
|
516
|
-
}, null);
|
517
|
-
});
|
518
|
-
}
|
519
|
-
isItemAtIndexVisible(itemIndex) {
|
520
|
-
const view = this.nativeViewProtected;
|
521
|
-
if (!view) {
|
522
|
-
return false;
|
523
|
-
}
|
524
|
-
const indexes = Array.from(view.indexPathsForVisibleItems);
|
525
|
-
return indexes.some((visIndex) => visIndex.row === itemIndex);
|
526
|
-
}
|
527
|
-
refresh() {
|
528
|
-
if (!this.isLoaded || !this.nativeView) {
|
529
|
-
this._isDataDirty = true;
|
530
|
-
return;
|
531
|
-
}
|
532
|
-
this._isDataDirty = false;
|
533
|
-
this._lastLayoutKey = this._innerWidth + '_' + this._innerHeight;
|
534
|
-
if (Trace.isEnabled()) {
|
535
|
-
CLog(CLogTypes.info, 'refresh');
|
536
|
-
}
|
537
|
-
// we need to clear stored cell sizes and it wont be correct anymore
|
538
|
-
// this.clearCellSize();
|
539
|
-
const sizes = this._delegate instanceof UICollectionViewDelegateImpl ? this._delegate.cachedSizes : null;
|
540
|
-
if (sizes) {
|
541
|
-
sizes.removeAllObjects();
|
542
|
-
}
|
543
|
-
// clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate
|
544
|
-
this._map.forEach((view, nativeView, map) => {
|
545
|
-
if (!(view.bindingContext instanceof Observable)) {
|
546
|
-
view.bindingContext = null;
|
547
|
-
}
|
548
|
-
});
|
549
|
-
// TODO: this is ugly look here: https://github.com/nativescript-vue/nativescript-vue/issues/525
|
550
|
-
// this.clearRealizedCells();
|
551
|
-
// dispatch_async(main_queue, () => {
|
552
|
-
this.nativeViewProtected.reloadData();
|
553
|
-
// });
|
554
|
-
this.notify({ eventName: CollectionViewBase.dataPopulatedEvent });
|
555
|
-
}
|
556
|
-
//@ts-ignore
|
557
|
-
get scrollOffset() {
|
558
|
-
const view = this.nativeViewProtected;
|
559
|
-
return (this.isHorizontal() ? view?.contentOffset.x : view?.contentOffset.y) || 0;
|
560
|
-
}
|
561
|
-
get verticalOffsetX() {
|
562
|
-
return this.nativeViewProtected?.contentOffset.x || 0;
|
563
|
-
}
|
564
|
-
get verticalOffsetY() {
|
565
|
-
return this.nativeViewProtected?.contentOffset.y || 0;
|
566
|
-
}
|
567
|
-
scrollToIndex(index, animated = true, snap = SnapPosition.START) {
|
568
|
-
let scrollPosition = 1 /* UICollectionViewScrollPosition.Top */;
|
569
|
-
if (this.orientation === 'vertical') {
|
570
|
-
scrollPosition = snap === SnapPosition.START ? 1 /* UICollectionViewScrollPosition.Top */ : 4 /* UICollectionViewScrollPosition.Bottom */;
|
571
|
-
}
|
572
|
-
else {
|
573
|
-
scrollPosition = snap === SnapPosition.START ? 8 /* UICollectionViewScrollPosition.Left */ : 32 /* UICollectionViewScrollPosition.Right */;
|
574
|
-
}
|
575
|
-
this.nativeViewProtected.scrollToItemAtIndexPathAtScrollPositionAnimated(NSIndexPath.indexPathForItemInSection(index, 0), scrollPosition, animated);
|
576
|
-
}
|
577
|
-
scrollToOffset(value, animated) {
|
578
|
-
const view = this.nativeViewProtected;
|
579
|
-
if (view && this.isScrollEnabled) {
|
580
|
-
const { width, height } = view.bounds.size;
|
581
|
-
let rect;
|
582
|
-
if (this.orientation === 'vertical') {
|
583
|
-
rect = CGRectMake(0, value, width, height);
|
584
|
-
}
|
585
|
-
else {
|
586
|
-
rect = CGRectMake(value, 0, width, height);
|
587
|
-
}
|
588
|
-
if (rect) {
|
589
|
-
view.scrollRectToVisibleAnimated(rect, animated);
|
590
|
-
}
|
591
|
-
}
|
592
|
-
}
|
593
|
-
requestLayout() {
|
594
|
-
// When preparing cell don't call super - no need to invalidate our measure when cell desiredSize is changed.
|
595
|
-
if (!this._preparingCell) {
|
596
|
-
super.requestLayout();
|
597
|
-
}
|
598
|
-
}
|
599
|
-
_setNativeClipToBounds() {
|
600
|
-
this.nativeView.clipsToBounds = true;
|
601
|
-
}
|
602
|
-
notifyForItemAtIndex(eventName, view, index, bindingContext, native) {
|
603
|
-
const args = { eventName, object: this, index, view, ios: native, bindingContext };
|
604
|
-
this.notify(args);
|
605
|
-
return args;
|
606
|
-
}
|
607
|
-
_getItemTemplateType(indexPath) {
|
608
|
-
const selector = this._itemTemplateSelector;
|
609
|
-
let type = this._defaultTemplate.key;
|
610
|
-
if (selector) {
|
611
|
-
type = selector.call(this, this.getItemAtIndex(indexPath.item), indexPath.item, this.items);
|
612
|
-
}
|
613
|
-
return type.toLowerCase();
|
614
|
-
}
|
615
|
-
getItemTemplateContent(index, templateType) {
|
616
|
-
return this.getViewForViewType(ListViewViewTypes.ItemView, templateType);
|
617
|
-
}
|
618
|
-
_prepareCell(cell, indexPath, templateType, notForCellSizeComp = true) {
|
619
|
-
let cellSize;
|
620
|
-
try {
|
621
|
-
this._preparingCell = true;
|
622
|
-
const firstRender = !cell.view;
|
623
|
-
let view = cell.view;
|
624
|
-
const index = indexPath.row;
|
625
|
-
if (!view) {
|
626
|
-
view = this.getItemTemplateContent(index, templateType);
|
627
|
-
}
|
628
|
-
const bindingContext = this._prepareItem(view, index);
|
629
|
-
if (Trace.isEnabled()) {
|
630
|
-
CLog(CLogTypes.log, '_prepareCell', index, templateType, !!cell.view, !!view, cell.view !== view, notForCellSizeComp);
|
631
|
-
}
|
632
|
-
const args = this.notifyForItemAtIndex(CollectionViewBase.itemLoadingEvent, view, indexPath.row, bindingContext, cell);
|
633
|
-
view = args.view;
|
634
|
-
if (firstRender) {
|
635
|
-
view['iosIgnoreSafeArea'] = true;
|
636
|
-
}
|
637
|
-
view.bindingContext = bindingContext;
|
638
|
-
if (view instanceof ProxyViewContainer) {
|
639
|
-
const sp = new ContentView();
|
640
|
-
sp.content = view;
|
641
|
-
view = sp;
|
642
|
-
}
|
643
|
-
if (!cell.view) {
|
644
|
-
cell.owner = new WeakRef(view);
|
645
|
-
}
|
646
|
-
else if (cell.view !== view) {
|
647
|
-
this._removeContainer(cell);
|
648
|
-
cell.view.nativeViewProtected.removeFromSuperview();
|
649
|
-
cell.owner = new WeakRef(view);
|
650
|
-
}
|
651
|
-
cell.currentIndex = indexPath.row;
|
652
|
-
if (notForCellSizeComp) {
|
653
|
-
this._map.set(cell, view);
|
654
|
-
}
|
655
|
-
if (view && !view.parent) {
|
656
|
-
this._addView(view);
|
657
|
-
const innerView = NSCellView.new();
|
658
|
-
innerView.autoresizingMask = 2 /* UIViewAutoresizing.FlexibleWidth */ | 16 /* UIViewAutoresizing.FlexibleHeight */;
|
659
|
-
innerView.view = new WeakRef(view);
|
660
|
-
if (notForCellSizeComp && this.autoReloadItemOnLayout) {
|
661
|
-
// for a cell to update correctly on cell layout change we need
|
662
|
-
// to do it ourself instead of "propagating it"
|
663
|
-
view['performLayout'] = () => {
|
664
|
-
if (!this._preparingCell) {
|
665
|
-
const index = cell.currentIndex;
|
666
|
-
const nativeView = this.nativeViewProtected;
|
667
|
-
const sizes = this._delegate instanceof UICollectionViewDelegateImpl ? this._delegate.cachedSizes : null;
|
668
|
-
if (sizes) {
|
669
|
-
sizes.replaceObjectAtIndexWithObject(index, NSValue.valueWithCGSize(CGSizeZero));
|
670
|
-
}
|
671
|
-
nativeView.performBatchUpdatesCompletion(() => {
|
672
|
-
this.measureCell(cell, view, index);
|
673
|
-
this.notifyForItemAtIndex(CollectionViewBase.itemLoadingEvent, view, indexPath.row, view.bindingContext, cell);
|
674
|
-
cell.contentView.subviews.objectAtIndex(0)?.layoutSubviews();
|
675
|
-
nativeView.collectionViewLayout.invalidateLayout();
|
676
|
-
}, null);
|
677
|
-
}
|
678
|
-
};
|
679
|
-
}
|
680
|
-
innerView.addSubview(view.nativeViewProtected);
|
681
|
-
cell.contentView.addSubview(innerView);
|
682
|
-
}
|
683
|
-
cellSize = this.measureCell(cell, view, indexPath.row);
|
684
|
-
if (notForCellSizeComp) {
|
685
|
-
view.notify({ eventName: CollectionViewBase.bindedEvent });
|
686
|
-
}
|
687
|
-
if (Trace.isEnabled()) {
|
688
|
-
CLog(CLogTypes.log, '_prepareCell done', index, cellSize);
|
689
|
-
}
|
690
|
-
}
|
691
|
-
finally {
|
692
|
-
this._preparingCell = false;
|
693
|
-
}
|
694
|
-
return cellSize;
|
695
|
-
}
|
696
|
-
getCellSize(index) {
|
697
|
-
// let result = this._sizes[index];
|
698
|
-
let result;
|
699
|
-
// CLog(CLogTypes.log, 'getCellSize', index, result, this._effectiveColWidth, this._effectiveRowHeight, this.getMeasuredWidth(), this.getMeasuredHeight());
|
700
|
-
if (!result) {
|
701
|
-
let width = this._effectiveColWidth;
|
702
|
-
let height = this._effectiveRowHeight;
|
703
|
-
if (this.spanSize) {
|
704
|
-
const dataItem = this.getItemAtIndex(index);
|
705
|
-
const spanSize = this.spanSize(dataItem, index);
|
706
|
-
const horizontal = this.isHorizontal();
|
707
|
-
if (horizontal) {
|
708
|
-
height *= spanSize;
|
709
|
-
}
|
710
|
-
else {
|
711
|
-
width *= spanSize;
|
712
|
-
}
|
713
|
-
}
|
714
|
-
if (width && height) {
|
715
|
-
result = [width, height];
|
716
|
-
}
|
717
|
-
else if (height && this.orientation === 'vertical') {
|
718
|
-
result = [this.getMeasuredWidth(), height];
|
719
|
-
}
|
720
|
-
else if (width && this.orientation === 'horizontal') {
|
721
|
-
result = [width, this.getMeasuredHeight()];
|
722
|
-
}
|
723
|
-
}
|
724
|
-
// return undefined;
|
725
|
-
return result;
|
726
|
-
}
|
727
|
-
// public storeCellSize(index: number, value) {
|
728
|
-
// this._sizes[index] = value;
|
729
|
-
// }
|
730
|
-
// public clearCellSize() {
|
731
|
-
// this._sizes = new Array<number[]>();
|
732
|
-
// }
|
733
|
-
measureCell(cell, cellView, position) {
|
734
|
-
if (cellView) {
|
735
|
-
let width = this._effectiveColWidth;
|
736
|
-
let height = this._effectiveRowHeight;
|
737
|
-
const horizontal = this.isHorizontal();
|
738
|
-
if (this.spanSize) {
|
739
|
-
const dataItem = this.getItemAtIndex(position);
|
740
|
-
const spanSize = this.spanSize(dataItem, position);
|
741
|
-
if (horizontal) {
|
742
|
-
height *= spanSize;
|
743
|
-
}
|
744
|
-
else {
|
745
|
-
width *= spanSize;
|
746
|
-
}
|
747
|
-
}
|
748
|
-
const widthMeasureSpec = width ? Utils.layout.makeMeasureSpec(width, Utils.layout.EXACTLY) : horizontal ? infinity : Utils.layout.makeMeasureSpec(this._innerWidth, Utils.layout.EXACTLY);
|
749
|
-
const heightMeasureSpec = height
|
750
|
-
? Utils.layout.makeMeasureSpec(height, Utils.layout.EXACTLY)
|
751
|
-
: horizontal
|
752
|
-
? Utils.layout.makeMeasureSpec(this._innerHeight, Utils.layout.EXACTLY)
|
753
|
-
: infinity;
|
754
|
-
if (Trace.isEnabled()) {
|
755
|
-
CLog(CLogTypes.log, 'measureCell', position, width, height, this._innerWidth, this._innerHeight, widthMeasureSpec, heightMeasureSpec);
|
756
|
-
}
|
757
|
-
const measuredSize = View.measureChild(this, cellView, widthMeasureSpec, heightMeasureSpec);
|
758
|
-
const result = [measuredSize.measuredWidth, measuredSize.measuredHeight];
|
759
|
-
// this.storeCellSize(index.row, result);
|
760
|
-
return result;
|
761
|
-
}
|
762
|
-
return undefined;
|
763
|
-
}
|
764
|
-
layoutCell(index, cell, cellView) {
|
765
|
-
// const cellSize = this.getCellSize(index);
|
766
|
-
const size = cell.bounds.size;
|
767
|
-
View.layoutChild(this, cellView, 0, 0, Utils.layout.toDevicePixels(size.width), Utils.layout.toDevicePixels(size.height));
|
768
|
-
if (Trace.isEnabled()) {
|
769
|
-
CLog(CLogTypes.log, 'layoutCell', index, cellView.getMeasuredWidth(), cellView.getMeasuredHeight());
|
770
|
-
}
|
771
|
-
}
|
772
|
-
clearRealizedCells() {
|
773
|
-
this._map.forEach((value, key) => {
|
774
|
-
this._removeContainer(key);
|
775
|
-
this._clearCellViews(key);
|
776
|
-
});
|
777
|
-
this._map.clear();
|
778
|
-
}
|
779
|
-
_clearCellViews(cell) {
|
780
|
-
if (cell && cell.view) {
|
781
|
-
if (cell.view.nativeViewProtected) {
|
782
|
-
cell.view.nativeViewProtected.removeFromSuperview();
|
783
|
-
}
|
784
|
-
cell.owner = undefined;
|
785
|
-
}
|
786
|
-
}
|
787
|
-
_removeContainer(cell) {
|
788
|
-
const view = cell.view;
|
789
|
-
// This is to clear the StackLayout that is used to wrap ProxyViewContainer instances.
|
790
|
-
if (!(view.parent instanceof CollectionView)) {
|
791
|
-
this._removeView(view.parent);
|
792
|
-
}
|
793
|
-
// No need to request layout when we are removing cells.
|
794
|
-
const preparing = this._preparingCell;
|
795
|
-
this._preparingCell = true;
|
796
|
-
view.parent._removeView(view);
|
797
|
-
this._preparingCell = preparing;
|
798
|
-
this._map.delete(cell);
|
799
|
-
}
|
800
|
-
_setPadding(newPadding) {
|
801
|
-
const layout = this._layout;
|
802
|
-
const padding = {
|
803
|
-
top: layout['sectionInset'].top,
|
804
|
-
right: layout['sectionInset'].right,
|
805
|
-
bottom: layout['sectionInset'].bottom,
|
806
|
-
left: layout['sectionInset'].left
|
807
|
-
};
|
808
|
-
// tslint:disable-next-line:prefer-object-spread
|
809
|
-
const newValue = Object.assign(padding, newPadding);
|
810
|
-
layout['sectionInset'] = newValue;
|
811
|
-
}
|
812
|
-
numberOfSectionsInCollectionView(collectionView) {
|
813
|
-
if (!this._lastLayoutKey) {
|
814
|
-
return 0;
|
815
|
-
}
|
816
|
-
return 1;
|
817
|
-
}
|
818
|
-
collectionViewNumberOfItemsInSection(collectionView, section) {
|
819
|
-
return this.items?.length || 0;
|
820
|
-
}
|
821
|
-
collectionViewCellForItemAtIndexPath(collectionView, indexPath) {
|
822
|
-
const templateType = this._getItemTemplateType(indexPath);
|
823
|
-
let cell = collectionView.dequeueReusableCellWithReuseIdentifierForIndexPath(templateType, indexPath);
|
824
|
-
if (!cell) {
|
825
|
-
cell = CollectionViewCell.new();
|
826
|
-
}
|
827
|
-
// should we force clipsToBounds? not doing so allows more complex layouts like overlapping
|
828
|
-
cell.clipsToBounds = true;
|
829
|
-
// we set zPosition to allow overlap. Should we make it an option?
|
830
|
-
// cell.layer.zPosition = indexPath.row;
|
831
|
-
const firstRender = !cell.view;
|
832
|
-
if (Trace.isEnabled()) {
|
833
|
-
CLog(CLogTypes.log, 'collectionViewCellForItemAtIndexPath', indexPath.row, templateType, !!cell.view, cell);
|
834
|
-
}
|
835
|
-
this._prepareCell(cell, indexPath, templateType);
|
836
|
-
// the cell layout will be called from NSCellView layoutSubviews
|
837
|
-
const cellView = cell.view;
|
838
|
-
if (!firstRender && cellView['isLayoutRequired']) {
|
839
|
-
this.layoutCell(indexPath.row, cell, cellView);
|
840
|
-
}
|
841
|
-
return cell;
|
842
|
-
}
|
843
|
-
collectionViewWillDisplayCellForItemAtIndexPath(collectionView, cell, indexPath) {
|
844
|
-
if (this.reverseLayout) {
|
845
|
-
cell.transform = CGAffineTransformMakeRotation(-Math.PI);
|
846
|
-
}
|
847
|
-
if (this.items) {
|
848
|
-
const loadMoreItemIndex = this.items.length - this.loadMoreThreshold;
|
849
|
-
if (indexPath.row === loadMoreItemIndex && this.hasListeners(CollectionViewBase.loadMoreItemsEvent)) {
|
850
|
-
this.notify({
|
851
|
-
eventName: CollectionViewBase.loadMoreItemsEvent,
|
852
|
-
object: this
|
853
|
-
});
|
854
|
-
}
|
855
|
-
}
|
856
|
-
// if (this.hasListeners(CollectionViewBase.displayItemEvent) ) {
|
857
|
-
// this.notify<CollectionViewItemDisplayEventData>({
|
858
|
-
// eventName: CollectionViewBase.displayItemEvent,
|
859
|
-
// index:indexPath.row,
|
860
|
-
// object: this,
|
861
|
-
// });
|
862
|
-
// }
|
863
|
-
if (cell.preservesSuperviewLayoutMargins) {
|
864
|
-
cell.preservesSuperviewLayoutMargins = false;
|
865
|
-
}
|
866
|
-
if (cell.layoutMargins) {
|
867
|
-
cell.layoutMargins = UIEdgeInsetsZero;
|
868
|
-
}
|
869
|
-
}
|
870
|
-
collectionViewDidSelectItemAtIndexPath(collectionView, indexPath) {
|
871
|
-
const cell = collectionView.cellForItemAtIndexPath(indexPath);
|
872
|
-
const position = indexPath.row;
|
873
|
-
this.notify({
|
874
|
-
eventName: CollectionViewBase.itemTapEvent,
|
875
|
-
object: this,
|
876
|
-
item: this.getItemAtIndex(position),
|
877
|
-
index: position,
|
878
|
-
view: cell.view
|
879
|
-
});
|
880
|
-
cell.highlighted = false;
|
881
|
-
return indexPath;
|
882
|
-
}
|
883
|
-
collectionViewLayoutSizeForItemAtIndexPath(collectionView, collectionViewLayout, indexPath) {
|
884
|
-
const row = indexPath.row;
|
885
|
-
let measuredSize = this.getCellSize(row);
|
886
|
-
if (!measuredSize) {
|
887
|
-
if (Trace.isEnabled()) {
|
888
|
-
CLog(CLogTypes.log, 'collectionViewLayoutSizeForItemAtIndexPath', row);
|
889
|
-
}
|
890
|
-
const templateType = this._getItemTemplateType(indexPath);
|
891
|
-
if (templateType) {
|
892
|
-
const measureData = this._measureCellMap.get(templateType);
|
893
|
-
let cell = measureData && measureData.cell;
|
894
|
-
let needsSet = false;
|
895
|
-
if (!cell) {
|
896
|
-
cell = CollectionViewCell.new();
|
897
|
-
needsSet = true;
|
898
|
-
}
|
899
|
-
else if (!cell.view) {
|
900
|
-
cell.owner = new WeakRef(measureData.view);
|
901
|
-
needsSet = true;
|
902
|
-
}
|
903
|
-
measuredSize = this._prepareCell(cell, indexPath, templateType, false);
|
904
|
-
if (needsSet) {
|
905
|
-
this._measureCellMap.set(templateType, { cell, view: cell.view });
|
906
|
-
}
|
907
|
-
}
|
908
|
-
}
|
909
|
-
if (Trace.isEnabled()) {
|
910
|
-
CLog(CLogTypes.log, 'collectionViewLayoutSizeForItemAtIndexPath', row, measuredSize);
|
911
|
-
}
|
912
|
-
if (measuredSize) {
|
913
|
-
return CGSizeMake(Utils.layout.toDeviceIndependentPixels(measuredSize[0]), Utils.layout.toDeviceIndependentPixels(measuredSize[1]));
|
914
|
-
}
|
915
|
-
return CGSizeZero;
|
916
|
-
}
|
917
|
-
computeScrollEventData(scrollView, eventName, dx, dy) {
|
918
|
-
const horizontal = this.isHorizontal();
|
919
|
-
const safeAreaInsetsTop = this.iosIgnoreSafeArea ? 0 : scrollView.safeAreaInsets.top;
|
920
|
-
const offset = horizontal ? scrollView.contentOffset.x : scrollView.contentOffset.y + safeAreaInsetsTop;
|
921
|
-
const size = horizontal ? scrollView.contentSize.width - scrollView.bounds.size.width : scrollView.contentSize.height - scrollView.bounds.size.height + safeAreaInsetsTop;
|
922
|
-
return {
|
923
|
-
object: this,
|
924
|
-
eventName,
|
925
|
-
scrollOffset: offset,
|
926
|
-
scrollOffsetPercentage: offset / size,
|
927
|
-
dx,
|
928
|
-
dy: dy + safeAreaInsetsTop
|
929
|
-
};
|
930
|
-
}
|
931
|
-
scrollViewWillBeginDragging(scrollView) {
|
932
|
-
this.lastContentOffset = scrollView.contentOffset;
|
933
|
-
this.needsScrollStartEvent = true;
|
934
|
-
this.isScrolling = true;
|
935
|
-
}
|
936
|
-
scrollViewDidScroll(scrollView) {
|
937
|
-
const contentOffset = scrollView.contentOffset;
|
938
|
-
const dx = contentOffset.x - this.lastContentOffset.x;
|
939
|
-
const dy = contentOffset.y - this.lastContentOffset.y;
|
940
|
-
this.lastContentOffset = scrollView.contentOffset;
|
941
|
-
if (this.needsScrollStartEvent) {
|
942
|
-
this.needsScrollStartEvent = false;
|
943
|
-
if (this.hasListeners(CollectionViewBase.scrollStartEvent)) {
|
944
|
-
this.notify(this.computeScrollEventData(scrollView, CollectionViewBase.scrollStartEvent, dx, dy));
|
945
|
-
}
|
946
|
-
}
|
947
|
-
this.notify(this.computeScrollEventData(scrollView, CollectionViewBase.scrollEvent, dx, dy));
|
948
|
-
}
|
949
|
-
stopScrolling(scrollView) {
|
950
|
-
if (this.isScrolling) {
|
951
|
-
this.isScrolling = false;
|
952
|
-
this.notify(this.computeScrollEventData(scrollView, CollectionViewBase.scrollEndEvent));
|
953
|
-
}
|
954
|
-
}
|
955
|
-
scrollViewDidEndDecelerating(scrollView) {
|
956
|
-
this.stopScrolling(scrollView);
|
957
|
-
}
|
958
|
-
scrollViewWillEndDraggingWithVelocityTargetContentOffset(scrollView, velocity, targetContentOffset) {
|
959
|
-
this.stopScrolling(scrollView);
|
960
|
-
}
|
961
|
-
scrollViewDidEndDraggingWillDecelerate(scrollView, decelerate) {
|
962
|
-
this.stopScrolling(scrollView);
|
963
|
-
}
|
964
|
-
scrollViewDidEndScrollingAnimation(scrollView) {
|
965
|
-
this.stopScrolling(scrollView);
|
966
|
-
}
|
967
|
-
}
|
968
|
-
__decorate([
|
969
|
-
profile
|
970
|
-
], CollectionView.prototype, "refresh", null);
|
971
|
-
contentInsetAdjustmentBehaviorProperty.register(CollectionView);
|
972
|
-
var NSCellView = /** @class */ (function (_super) {
|
973
|
-
__extends(NSCellView, _super);
|
974
|
-
function NSCellView() {
|
975
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
976
|
-
}
|
977
|
-
NSCellView.prototype.layoutSubviews = function () {
|
978
|
-
_super.prototype.layoutSubviews.call(this);
|
979
|
-
var view = this.view && this.view.get();
|
980
|
-
if (!view) {
|
981
|
-
return;
|
982
|
-
}
|
983
|
-
this.frame = this.superview.bounds;
|
984
|
-
var size = this.bounds.size;
|
985
|
-
View.layoutChild(null, view, 0, 0, Utils.layout.toDevicePixels(size.width), Utils.layout.toDevicePixels(size.height));
|
986
|
-
};
|
987
|
-
return NSCellView;
|
988
|
-
}(UIView));
|
989
|
-
var CollectionViewCell = /** @class */ (function (_super) {
|
990
|
-
__extends(CollectionViewCell, _super);
|
991
|
-
function CollectionViewCell() {
|
992
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
993
|
-
}
|
994
|
-
Object.defineProperty(CollectionViewCell.prototype, "view", {
|
995
|
-
get: function () {
|
996
|
-
return this.owner ? this.owner.get() : null;
|
997
|
-
},
|
998
|
-
enumerable: true,
|
999
|
-
configurable: true
|
1000
|
-
});
|
1001
|
-
return CollectionViewCell;
|
1002
|
-
}(UICollectionViewCell));
|
1003
|
-
var CollectionViewDataSource = /** @class */ (function (_super) {
|
1004
|
-
__extends(CollectionViewDataSource, _super);
|
1005
|
-
function CollectionViewDataSource() {
|
1006
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
1007
|
-
}
|
1008
|
-
CollectionViewDataSource.initWithOwner = function (owner) {
|
1009
|
-
var delegate = CollectionViewDataSource.new();
|
1010
|
-
delegate._owner = new WeakRef(owner);
|
1011
|
-
return delegate;
|
1012
|
-
};
|
1013
|
-
CollectionViewDataSource.prototype.numberOfSectionsInCollectionView = function (collectionView) {
|
1014
|
-
var owner = this._owner.get();
|
1015
|
-
if (owner) {
|
1016
|
-
return owner.numberOfSectionsInCollectionView(collectionView);
|
1017
|
-
}
|
1018
|
-
return 0;
|
1019
|
-
};
|
1020
|
-
CollectionViewDataSource.prototype.collectionViewNumberOfItemsInSection = function (collectionView, section) {
|
1021
|
-
var owner = this._owner.get();
|
1022
|
-
if (owner) {
|
1023
|
-
return owner.collectionViewNumberOfItemsInSection(collectionView, section);
|
1024
|
-
}
|
1025
|
-
return 0;
|
1026
|
-
};
|
1027
|
-
CollectionViewDataSource.prototype.collectionViewCellForItemAtIndexPath = function (collectionView, indexPath) {
|
1028
|
-
var owner = this._owner.get();
|
1029
|
-
if (owner) {
|
1030
|
-
return owner.collectionViewCellForItemAtIndexPath(collectionView, indexPath);
|
1031
|
-
}
|
1032
|
-
return null;
|
1033
|
-
};
|
1034
|
-
CollectionViewDataSource.prototype.collectionViewMoveItemAtIndexPathToIndexPath = function (collectionView, sourceIndexPath, destinationIndexPath) {
|
1035
|
-
var owner = this._owner.get();
|
1036
|
-
if (owner) {
|
1037
|
-
owner.reorderStartingRow = sourceIndexPath.row;
|
1038
|
-
owner.reorderEndingRow = destinationIndexPath.row;
|
1039
|
-
owner._reorderItemInSource(sourceIndexPath.row, destinationIndexPath.row, false);
|
1040
|
-
}
|
1041
|
-
};
|
1042
|
-
CollectionViewDataSource.prototype.collectionViewTargetIndexPathForMoveFromItemAtIndexPathToProposedIndexPath = function (collectionView, originalIndexPath, proposedIndexPath) {
|
1043
|
-
var owner = this._owner.get();
|
1044
|
-
if (owner) {
|
1045
|
-
owner.reorderEndingRow = proposedIndexPath.row;
|
1046
|
-
}
|
1047
|
-
return proposedIndexPath;
|
1048
|
-
};
|
1049
|
-
CollectionViewDataSource.prototype.collectionViewCanMoveItemAtIndexPath = function (collectionView, indexPath) {
|
1050
|
-
var owner = this._owner.get();
|
1051
|
-
if (owner) {
|
1052
|
-
var result = owner.shouldMoveItemAtIndex(indexPath.row);
|
1053
|
-
if (result) {
|
1054
|
-
owner.reorderStartingRow = indexPath.row;
|
1055
|
-
}
|
1056
|
-
return result;
|
1057
|
-
}
|
1058
|
-
return false;
|
1059
|
-
};
|
1060
|
-
CollectionViewDataSource.ObjCProtocols = [UICollectionViewDataSource];
|
1061
|
-
return CollectionViewDataSource;
|
1062
|
-
}(NSObject));
|
1063
|
-
var UICollectionViewDelegateImpl = /** @class */ (function (_super) {
|
1064
|
-
__extends(UICollectionViewDelegateImpl, _super);
|
1065
|
-
function UICollectionViewDelegateImpl() {
|
1066
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
1067
|
-
}
|
1068
|
-
UICollectionViewDelegateImpl.initWithOwner = function (owner) {
|
1069
|
-
var delegate = UICollectionViewDelegateImpl.new();
|
1070
|
-
delegate._owner = new WeakRef(owner);
|
1071
|
-
return delegate;
|
1072
|
-
};
|
1073
|
-
UICollectionViewDelegateImpl.prototype.collectionViewWillDisplayCellForItemAtIndexPath = function (collectionView, cell, indexPath) {
|
1074
|
-
var owner = this._owner.get();
|
1075
|
-
if (owner) {
|
1076
|
-
owner.collectionViewWillDisplayCellForItemAtIndexPath(collectionView, cell, indexPath);
|
1077
|
-
}
|
1078
|
-
};
|
1079
|
-
UICollectionViewDelegateImpl.prototype.collectionViewDidSelectItemAtIndexPath = function (collectionView, indexPath) {
|
1080
|
-
var owner = this._owner.get();
|
1081
|
-
if (owner) {
|
1082
|
-
return owner.collectionViewDidSelectItemAtIndexPath(collectionView, indexPath);
|
1083
|
-
}
|
1084
|
-
return indexPath;
|
1085
|
-
};
|
1086
|
-
UICollectionViewDelegateImpl.prototype.collectionViewLayoutComputedSizeForItemAtIndexPath = function (collectionView, collectionViewLayout, indexPath) {
|
1087
|
-
var owner = this._owner.get();
|
1088
|
-
if (owner) {
|
1089
|
-
return owner.collectionViewLayoutSizeForItemAtIndexPath(collectionView, collectionViewLayout, indexPath);
|
1090
|
-
}
|
1091
|
-
return CGSizeZero;
|
1092
|
-
};
|
1093
|
-
UICollectionViewDelegateImpl.prototype.scrollViewDidScroll = function (scrollView) {
|
1094
|
-
var owner = this._owner.get();
|
1095
|
-
if (owner) {
|
1096
|
-
owner.scrollViewDidScroll(scrollView);
|
1097
|
-
}
|
1098
|
-
};
|
1099
|
-
UICollectionViewDelegateImpl.prototype.scrollViewWillBeginDragging = function (scrollView) {
|
1100
|
-
var owner = this._owner.get();
|
1101
|
-
if (owner) {
|
1102
|
-
owner.scrollViewWillBeginDragging(scrollView);
|
1103
|
-
}
|
1104
|
-
};
|
1105
|
-
UICollectionViewDelegateImpl.prototype.scrollViewDidEndDecelerating = function (scrollView) {
|
1106
|
-
var owner = this._owner.get();
|
1107
|
-
if (owner) {
|
1108
|
-
owner.scrollViewDidEndDecelerating(scrollView);
|
1109
|
-
}
|
1110
|
-
};
|
1111
|
-
UICollectionViewDelegateImpl.prototype.scrollViewWillEndDraggingWithVelocityTargetContentOffset = function (scrollView, velocity, targetContentOffset) {
|
1112
|
-
var owner = this._owner.get();
|
1113
|
-
if (owner) {
|
1114
|
-
owner.scrollViewWillEndDraggingWithVelocityTargetContentOffset(scrollView, velocity, targetContentOffset);
|
1115
|
-
}
|
1116
|
-
};
|
1117
|
-
UICollectionViewDelegateImpl.prototype.scrollViewDidEndDraggingWillDecelerate = function (scrollView, decelerate) {
|
1118
|
-
var owner = this._owner.get();
|
1119
|
-
if (owner) {
|
1120
|
-
owner.scrollViewDidEndDraggingWillDecelerate(scrollView, decelerate);
|
1121
|
-
}
|
1122
|
-
};
|
1123
|
-
UICollectionViewDelegateImpl.prototype.scrollViewDidEndScrollingAnimation = function (scrollView) {
|
1124
|
-
var owner = this._owner.get();
|
1125
|
-
if (owner) {
|
1126
|
-
owner.scrollViewDidEndScrollingAnimation(scrollView);
|
1127
|
-
}
|
1128
|
-
};
|
1129
|
-
UICollectionViewDelegateImpl.ObjCProtocols = [UICollectionViewDelegate, UICollectionViewDelegateFlowLayout];
|
1130
|
-
return UICollectionViewDelegateImpl;
|
1131
|
-
}(UICollectionViewCacheDelegateFlowLayout));
|
1132
|
-
var UICollectionViewDelegateFixedSizeImpl = /** @class */ (function (_super) {
|
1133
|
-
__extends(UICollectionViewDelegateFixedSizeImpl, _super);
|
1134
|
-
function UICollectionViewDelegateFixedSizeImpl() {
|
1135
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
1136
|
-
}
|
1137
|
-
UICollectionViewDelegateFixedSizeImpl.initWithOwner = function (owner) {
|
1138
|
-
var delegate = UICollectionViewDelegateFixedSizeImpl.new();
|
1139
|
-
delegate._owner = new WeakRef(owner);
|
1140
|
-
return delegate;
|
1141
|
-
};
|
1142
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.collectionViewWillDisplayCellForItemAtIndexPath = function (collectionView, cell, indexPath) {
|
1143
|
-
var owner = this._owner.get();
|
1144
|
-
if (owner) {
|
1145
|
-
owner.collectionViewWillDisplayCellForItemAtIndexPath(collectionView, cell, indexPath);
|
1146
|
-
}
|
1147
|
-
};
|
1148
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.collectionViewDidSelectItemAtIndexPath = function (collectionView, indexPath) {
|
1149
|
-
var owner = this._owner.get();
|
1150
|
-
if (owner) {
|
1151
|
-
return owner.collectionViewDidSelectItemAtIndexPath(collectionView, indexPath);
|
1152
|
-
}
|
1153
|
-
return indexPath;
|
1154
|
-
};
|
1155
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.scrollViewDidScroll = function (scrollView) {
|
1156
|
-
var owner = this._owner.get();
|
1157
|
-
if (owner) {
|
1158
|
-
owner.scrollViewDidScroll(scrollView);
|
1159
|
-
}
|
1160
|
-
};
|
1161
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.scrollViewWillBeginDragging = function (scrollView) {
|
1162
|
-
var owner = this._owner.get();
|
1163
|
-
if (owner) {
|
1164
|
-
owner.scrollViewWillBeginDragging(scrollView);
|
1165
|
-
}
|
1166
|
-
};
|
1167
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.scrollViewDidEndDecelerating = function (scrollView) {
|
1168
|
-
var owner = this._owner.get();
|
1169
|
-
if (owner) {
|
1170
|
-
owner.scrollViewDidEndDecelerating(scrollView);
|
1171
|
-
}
|
1172
|
-
};
|
1173
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.scrollViewWillEndDraggingWithVelocityTargetContentOffset = function (scrollView, velocity, targetContentOffset) {
|
1174
|
-
var owner = this._owner.get();
|
1175
|
-
if (owner) {
|
1176
|
-
owner.scrollViewWillEndDraggingWithVelocityTargetContentOffset(scrollView, velocity, targetContentOffset);
|
1177
|
-
}
|
1178
|
-
};
|
1179
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.scrollViewDidEndDraggingWillDecelerate = function (scrollView, decelerate) {
|
1180
|
-
var owner = this._owner.get();
|
1181
|
-
if (owner) {
|
1182
|
-
owner.scrollViewDidEndDraggingWillDecelerate(scrollView, decelerate);
|
1183
|
-
}
|
1184
|
-
};
|
1185
|
-
UICollectionViewDelegateFixedSizeImpl.prototype.scrollViewDidEndScrollingAnimation = function (scrollView) {
|
1186
|
-
var owner = this._owner.get();
|
1187
|
-
if (owner) {
|
1188
|
-
owner.scrollViewDidEndScrollingAnimation(scrollView);
|
1189
|
-
}
|
1190
|
-
};
|
1191
|
-
UICollectionViewDelegateFixedSizeImpl.ObjCProtocols = [UICollectionViewDelegate, UICollectionViewDelegateFlowLayout];
|
1192
|
-
return UICollectionViewDelegateFixedSizeImpl;
|
1193
|
-
}(NSObject));
|
1194
|
-
var ReorderLongPressImpl = /** @class */ (function (_super) {
|
1195
|
-
__extends(ReorderLongPressImpl, _super);
|
1196
|
-
function ReorderLongPressImpl() {
|
1197
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
1198
|
-
}
|
1199
|
-
ReorderLongPressImpl.initWithOwner = function (owner) {
|
1200
|
-
var handler = ReorderLongPressImpl.new();
|
1201
|
-
handler._owner = owner;
|
1202
|
-
return handler;
|
1203
|
-
};
|
1204
|
-
ReorderLongPressImpl.prototype.longPress = function (recognizer) {
|
1205
|
-
var owner = this._owner && this._owner.get();
|
1206
|
-
if (owner) {
|
1207
|
-
owner.onReorderLongPress(recognizer);
|
1208
|
-
}
|
1209
|
-
};
|
1210
|
-
ReorderLongPressImpl.ObjCExposedMethods = {
|
1211
|
-
longPress: { returns: interop.types.void, params: [interop.types.id] }
|
1212
|
-
};
|
1213
|
-
return ReorderLongPressImpl;
|
1214
|
-
}(NSObject));
|
1215
|
-
//# sourceMappingURL=index.ios.js.map
|