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