bm-core-ui 2.7.0
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 +1624 -0
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/build/@types/index.d.ts +14078 -0
- package/build/BMCodeEditor/BMCodeEditor.js +707 -0
- package/build/BMCollectionView/BMCollectionView.js +5861 -0
- package/build/BMCollectionView/BMCollectionViewCell.js +688 -0
- package/build/BMCollectionView/BMCollectionViewFlowLayout.js +4467 -0
- package/build/BMCollectionView/BMCollectionViewLayout.js +830 -0
- package/build/BMCollectionView/BMCollectionViewLayoutAttributes.js +673 -0
- package/build/BMCollectionView/BMCollectionViewMasonryLayout.js +491 -0
- package/build/BMCollectionView/BMCollectionViewStackLayout.js +634 -0
- package/build/BMCollectionView/BMCollectionViewTileLayout.js +1121 -0
- package/build/BMCoreUI.css +2833 -0
- package/build/BMView/BMAttributedLabelView.js +310 -0
- package/build/BMView/BMLayoutConstraint_v2.5.js +1813 -0
- package/build/BMView/BMLayoutGuide.js +192 -0
- package/build/BMView/BMLayoutSizeClass.js +466 -0
- package/build/BMView/BMMenu.js +574 -0
- package/build/BMView/BMScrollView.js +247 -0
- package/build/BMView/BMTextField.js +512 -0
- package/build/BMView/BMTextFieldDelegate.js +71 -0
- package/build/BMView/BMView_v2.5.js +3572 -0
- package/build/BMView/BMViewport.js +221 -0
- package/build/BMViewLayoutEditor/BMLayoutEditor.js +6117 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorConstraintSettings.js +417 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorDelegate.js +59 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingCells.js +1653 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettings.js +1480 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingsComplexCells.js +431 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorSettingsDelegate.js +46 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorVariablesController.js +460 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorViewGroupSettings.js +293 -0
- package/build/BMViewLayoutEditor/BMLayoutEditorViewSettings.js +382 -0
- package/build/BMViewLayoutEditor/BMLayoutVariableProvider.js +202 -0
- package/build/BMWindow/BMConfirmationPopup.js +477 -0
- package/build/BMWindow/BMKeyboardShortcut.js +151 -0
- package/build/BMWindow/BMPopover/BMPopover.js +492 -0
- package/build/BMWindow/BMToolWindow.js +71 -0
- package/build/BMWindow/BMWindow.js +2000 -0
- package/build/Core/BMAnimationContext.js +1181 -0
- package/build/Core/BMColor.js +991 -0
- package/build/Core/BMCoreUI.js +470 -0
- package/build/Core/BMFunctionCollection.js +110 -0
- package/build/Core/BMIndexPath.js +165 -0
- package/build/Core/BMInset.js +138 -0
- package/build/Core/BMKeyPath.js +100 -0
- package/build/Core/BMPoint.js +291 -0
- package/build/Core/BMRect.js +556 -0
- package/build/Core/BMSize.js +137 -0
- package/build/iScroll/LICENSE +22 -0
- package/build/iScroll/iscroll-probe.js +2154 -0
- package/build/images/AlignBottom.png +0 -0
- package/build/images/AlignCenterX.png +0 -0
- package/build/images/AlignCenterY.png +0 -0
- package/build/images/AlignLeading.png +0 -0
- package/build/images/AlignTop.png +0 -0
- package/build/images/AlignTrailing.png +0 -0
- package/build/images/AllConstraints.png +0 -0
- package/build/images/BottomConstraint.png +0 -0
- package/build/images/CenterXConstraint.png +0 -0
- package/build/images/CenterYConstraint.png +0 -0
- package/build/images/CoreUI2.png +0 -0
- package/build/images/CoreUI2@2x.png +0 -0
- package/build/images/Desktop.png +0 -0
- package/build/images/DesktopMini.png +0 -0
- package/build/images/EqualHeight.png +0 -0
- package/build/images/EqualHorizontalSpacing.png +0 -0
- package/build/images/EqualHorizontalSpacingInSuperview.png +0 -0
- package/build/images/EqualVerticalSpacing.png +0 -0
- package/build/images/EqualVerticalSpacingInSuperview.png +0 -0
- package/build/images/EqualWidth.png +0 -0
- package/build/images/HeightConstraint.png +0 -0
- package/build/images/InactiveConstraints.png +0 -0
- package/build/images/Layout.png +0 -0
- package/build/images/LayoutVariables.png +0 -0
- package/build/images/LeftConstraint.png +0 -0
- package/build/images/OwnConstraints.png +0 -0
- package/build/images/Phone.png +0 -0
- package/build/images/PhoneLandscape.png +0 -0
- package/build/images/PhoneLandscapeMini.png +0 -0
- package/build/images/PhoneMini.png +0 -0
- package/build/images/PhonePortrait.png +0 -0
- package/build/images/PhonePortraitMini.png +0 -0
- package/build/images/Properties.png +0 -0
- package/build/images/RightConstraint.png +0 -0
- package/build/images/SubviewConstraints.png +0 -0
- package/build/images/Tablet.png +0 -0
- package/build/images/TabletLandscape.png +0 -0
- package/build/images/TabletLandscapeMini.png +0 -0
- package/build/images/TabletMini.png +0 -0
- package/build/images/TabletPortrait.png +0 -0
- package/build/images/TabletPortraitMini.png +0 -0
- package/build/images/TopConstraint.png +0 -0
- package/build/images/WidthConstraint.png +0 -0
- package/build/index.js +40 -0
- package/lib/@types/BMCoreUI.min.d.ts +14078 -0
- package/lib/BMCoreUI.min.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {YES, NO, BMExtend} from '../Core/BMCoreUI'
|
|
4
|
+
import {BMSizeMake} from '../Core/BMSize'
|
|
5
|
+
import {BMRectMake} from '../Core/BMRect'
|
|
6
|
+
import {BMCollectionViewLayoutAttributesMakeForCellAtIndexPath} from './BMCollectionViewLayoutAttributes'
|
|
7
|
+
import {BMCollectionViewLayout} from './BMCollectionViewLayout'
|
|
8
|
+
|
|
9
|
+
// @type BMCollectionViewMasonryLayout extends BMCollectionViewLayout
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The masonry layout arranges cells in a vertically scrolling container. Cells will be laid out in equally wide columns and each new cell will be positioned
|
|
13
|
+
* in the column with the topmost space available, starting from the leftmost cell.
|
|
14
|
+
* Additionally, columns in the masonry layout may have a speed assigned to them which affects the scrolling for that column alone. When a column has a higher scrolling speed,
|
|
15
|
+
* it may contain more items for the same container height. Note that while layout order is deterministic, it does not always respect the order the items appear in the data set.
|
|
16
|
+
* When using the masonry layout, the collection view must have a delegate that implements the method
|
|
17
|
+
* Number collectionViewHeightForCellAtIndexPath(BMCollectionView BMIndexPath, {forColumnWidth: Number}) which returns the height to use for the cell at the given index path.
|
|
18
|
+
* Because the masonry layout is a cached layout, it is not suitable for excessively large data sets.
|
|
19
|
+
* The masonry layout does not support supplementary view and will ignore sections.
|
|
20
|
+
*/
|
|
21
|
+
export function BMCollectionViewMasonryLayout() {}; // <constructor>
|
|
22
|
+
|
|
23
|
+
BMCollectionViewMasonryLayout.prototype = BMExtend({}, BMCollectionViewLayout.prototype, {
|
|
24
|
+
|
|
25
|
+
// @override - BMCollectionViewLayout
|
|
26
|
+
get supportsCopying() {
|
|
27
|
+
return YES;
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Mutually exclusive with numberOfColumns. If set, controls the minimum size a column may have.
|
|
32
|
+
* Columns' width may be larger than this value, but this a the breakpoint based on which it is decided when to add or remove columns.
|
|
33
|
+
*/
|
|
34
|
+
_minimumColumnWidth: 128, // <Number, nullable>
|
|
35
|
+
get minimumColumnWidth() { return this._minimumColumnWidth; },
|
|
36
|
+
set minimumColumnWidth(width) {
|
|
37
|
+
this._minimumColumnWidth = width;
|
|
38
|
+
|
|
39
|
+
this.invalidateLayout();
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Mutually exclusive with minimumColumns. If set, has priority over minimumColumnWidth and controls how many columns the masonry layout should use.
|
|
44
|
+
* Columns will be resized so they fit.
|
|
45
|
+
*/
|
|
46
|
+
_numberOfColumns: undefined, // <Number, nullable>
|
|
47
|
+
get numberOfColumns() { return this._numberOfColumns; },
|
|
48
|
+
set numberOfColumns(number) {
|
|
49
|
+
this._numberOfColumns = number;
|
|
50
|
+
|
|
51
|
+
this.invalidateLayout();
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Controls the horizontal spacing between columns.
|
|
56
|
+
*/
|
|
57
|
+
_columnSpacing: 22, // <Number>
|
|
58
|
+
get columnSpacing() { return this._columnSpacing; },
|
|
59
|
+
set columnSpacing(spacing) {
|
|
60
|
+
this._columnSpacing = spacing;
|
|
61
|
+
|
|
62
|
+
this.invalidateLayout();
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Controls the vertical spacing between the cells in a column.
|
|
67
|
+
*/
|
|
68
|
+
_cellSpacing: 22, // <Number>
|
|
69
|
+
get cellSpacing() { return this._cellSpacing; },
|
|
70
|
+
set cellSpacing(spacing) {
|
|
71
|
+
this._cellSpacing = spacing;
|
|
72
|
+
|
|
73
|
+
this.invalidateLayout();
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Controls how fast each column scrolls.
|
|
78
|
+
*/
|
|
79
|
+
_columnSpeeds: [], // <[Number]>
|
|
80
|
+
get columnSpeeds() { return this._columnSpeeds; },
|
|
81
|
+
set columnSpeeds(speeds) {
|
|
82
|
+
this._columnSpeeds = speeds;
|
|
83
|
+
|
|
84
|
+
this.invalidateLayout();
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The padding from the top edge to the first item.
|
|
89
|
+
*/
|
|
90
|
+
_topPadding: 22, // <Number>
|
|
91
|
+
get topPadding() { return this._topPadding; },
|
|
92
|
+
set topPadding(padding) {
|
|
93
|
+
this._topPadding = padding;
|
|
94
|
+
|
|
95
|
+
this.invalidateLayout();
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The padding from the bottom edge to the last item.
|
|
100
|
+
*/
|
|
101
|
+
_bottomPadding: 22, // <Number>
|
|
102
|
+
get bottomPadding() { return this._bottomPadding; },
|
|
103
|
+
set bottomPadding(padding) {
|
|
104
|
+
this._bottomPadding = padding;
|
|
105
|
+
|
|
106
|
+
this.invalidateLayout();
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Contains the cached layout attributes for all objects in the collection view.
|
|
111
|
+
*/
|
|
112
|
+
cachedLayout: undefined, // <Object>
|
|
113
|
+
|
|
114
|
+
// @override - BMCollectionViewLayout
|
|
115
|
+
prepareLayout: function () {
|
|
116
|
+
if (this.isChangingBounds) return;
|
|
117
|
+
|
|
118
|
+
this.previousLayout = this.cachedLayout;
|
|
119
|
+
this.cachedLayout = {};
|
|
120
|
+
|
|
121
|
+
var cachedLayout = this.cachedLayout;
|
|
122
|
+
|
|
123
|
+
var width = this.collectionView.frame.size.width;
|
|
124
|
+
var columnSpacing = this.columnSpacing;
|
|
125
|
+
var cellSpacing = this.cellSpacing;
|
|
126
|
+
|
|
127
|
+
var numberOfColumns = this.numberOfColumns;
|
|
128
|
+
var columnWidth;
|
|
129
|
+
|
|
130
|
+
var columnSpeeds = this.columnSpeeds;
|
|
131
|
+
|
|
132
|
+
if (!numberOfColumns) {
|
|
133
|
+
// If the number of columns isn't specifically set, determine it based on the minimum column width
|
|
134
|
+
// The actual column width should also be determined as the minimum column width is just a guideline
|
|
135
|
+
columnWidth = this.minimumColumnWidth;
|
|
136
|
+
|
|
137
|
+
numberOfColumns = (width / columnWidth) | 0;
|
|
138
|
+
|
|
139
|
+
// If adding the spacing causes the total width to go over the collection view frame's width, then just decrease the count by 1
|
|
140
|
+
// This can technically fail if the columns are narrower than the spacing, but in most cases it should work fine
|
|
141
|
+
if (numberOfColumns * columnWidth + (numberOfColumns + 1) * columnSpacing > width) {
|
|
142
|
+
numberOfColumns -= 1;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Determine the actual column width
|
|
146
|
+
var usableSpace = width - (numberOfColumns + 1) * columnSpacing;
|
|
147
|
+
columnWidth = (usableSpace / numberOfColumns) | 0;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Otherwise determine the width of the columns only
|
|
152
|
+
var usableSpace = width - (numberOfColumns + 1) * columnSpacing;
|
|
153
|
+
columnWidth = (usableSpace / numberOfColumns) | 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Create the columns
|
|
157
|
+
cachedLayout.columns = [];
|
|
158
|
+
for (var i = 0; i < numberOfColumns; i++) {
|
|
159
|
+
cachedLayout.columns.push({
|
|
160
|
+
height: this._topPadding,
|
|
161
|
+
speedHeight: this._topPadding / (columnSpeeds[i] || 1),
|
|
162
|
+
speed: columnSpeeds[i] || 1,
|
|
163
|
+
attributes: [],
|
|
164
|
+
x: columnSpacing + i * (columnSpacing + columnWidth)
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Enumerate all of the objects, ignoring their sections
|
|
169
|
+
var numberOfSections = this.collectionView.numberOfSections();
|
|
170
|
+
|
|
171
|
+
for (var i = 0; i < numberOfSections; i++) {
|
|
172
|
+
var numberOfObjects = this.collectionView.numberOfObjectsInSectionAtIndex(i);
|
|
173
|
+
|
|
174
|
+
for (var j = 0; j < numberOfObjects; j++) {
|
|
175
|
+
|
|
176
|
+
var indexPath = this.collectionView.indexPathForObjectAtRow(j, {inSectionAtIndex: i});
|
|
177
|
+
|
|
178
|
+
var cellHeight = this.collectionView.delegate.collectionViewHeightForCellAtIndexPath(this.collectionView, indexPath, {forColumnWidth: columnWidth});
|
|
179
|
+
|
|
180
|
+
var targetColumnTop = cachedLayout.columns[0].speedHeight;
|
|
181
|
+
var targetColumnIndex = 0;
|
|
182
|
+
|
|
183
|
+
// Find the column in which this cell should go
|
|
184
|
+
for (var columnIndex = 1; columnIndex < numberOfColumns; columnIndex++) {
|
|
185
|
+
var column = cachedLayout.columns[columnIndex];
|
|
186
|
+
|
|
187
|
+
if (column.speedHeight < targetColumnTop) {
|
|
188
|
+
targetColumnTop = column.speedHeight;
|
|
189
|
+
targetColumnIndex = columnIndex;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
var column = cachedLayout.columns[targetColumnIndex];
|
|
194
|
+
|
|
195
|
+
// Then construct and add the object's attributes
|
|
196
|
+
var attributes = BMCollectionViewLayoutAttributesMakeForCellAtIndexPath(indexPath);
|
|
197
|
+
|
|
198
|
+
attributes.frame = BMRectMake(column.x, column.height, columnWidth, cellHeight);
|
|
199
|
+
attributes.style = {translateZ: 0};
|
|
200
|
+
|
|
201
|
+
column.attributes.push(attributes);
|
|
202
|
+
|
|
203
|
+
// Adjust the column's height and speed height
|
|
204
|
+
column.height += cellHeight + cellSpacing;
|
|
205
|
+
column.speedHeight += (cellHeight + cellSpacing) / column.speed;
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Add the bottom padding to the column heights
|
|
212
|
+
for (var columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
|
|
213
|
+
var column = cachedLayout.columns[columnIndex];
|
|
214
|
+
|
|
215
|
+
column.height += this._bottomPadding;
|
|
216
|
+
column.speedHeight += this._bottomPadding / column.speed;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
// @override - BMCollectionViewLayout
|
|
223
|
+
contentSize: function () {
|
|
224
|
+
var height = 0;
|
|
225
|
+
|
|
226
|
+
for (var i = 0; i < this.cachedLayout.columns.length; i++) {
|
|
227
|
+
if (height < this.cachedLayout.columns[i].speedHeight) {
|
|
228
|
+
height = this.cachedLayout.columns[i].speedHeight;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return BMSizeMake(this.collectionView.frame.size.width, Math.max(height, this.collectionView.frame.size.height));
|
|
233
|
+
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
// @override - BMCollectionViewLayout
|
|
237
|
+
collectionViewWillStartUpdates: function () {
|
|
238
|
+
this.prepareLayout();
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
// @override - BMCollectionViewLayout
|
|
242
|
+
collectionViewDidStartUpdates: function () {
|
|
243
|
+
this.previousLayout = undefined;
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
// The masonry layout always invalidates the layout during scrolling to apply the speed to each column.
|
|
247
|
+
// @override - BMCollectionViewLayout
|
|
248
|
+
shouldInvalidateLayoutForBoundsChange: function (bounds) {
|
|
249
|
+
this.isChangingBounds = YES;
|
|
250
|
+
//this.collectionView.attributeCache = [];
|
|
251
|
+
return YES;
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
// @override - BMCollectionViewLayout
|
|
255
|
+
didInvalidateLayoutForBoundsChange: function () {
|
|
256
|
+
this.isChangingBounds = NO;
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
// @override - BMCollectionViewLayout
|
|
260
|
+
attributesForElementsInRect: function (rect) {
|
|
261
|
+
return this.cachedAttributesForElementsInRect(rect);
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Retrieves the cached attributes for all cells in the given rect.
|
|
266
|
+
* @param rect <BMRect> The rect.
|
|
267
|
+
* {
|
|
268
|
+
* @param usingCache <Object, nullable> Defaults to this layout's current cache. The cache object to use.
|
|
269
|
+
* }
|
|
270
|
+
*/
|
|
271
|
+
cachedAttributesForElementsInRect: function (rect, options) {
|
|
272
|
+
var cache = (options && options.usingCache) || this.cachedLayout;
|
|
273
|
+
var offset = this.collectionView.scrollOffset;
|
|
274
|
+
|
|
275
|
+
var rectTop = rect.origin.y;
|
|
276
|
+
var rectBottom = rect.bottom;
|
|
277
|
+
var resultingAttributes = [];
|
|
278
|
+
|
|
279
|
+
// Find the attributes in each column
|
|
280
|
+
var columns = cache.columns;
|
|
281
|
+
var numberOfColumns = columns.length;
|
|
282
|
+
|
|
283
|
+
for (var i = 0; i < numberOfColumns; i++) {
|
|
284
|
+
|
|
285
|
+
var column = columns[i];
|
|
286
|
+
|
|
287
|
+
// The speedTop is the unscaled top position at which to start retrieving cells.
|
|
288
|
+
var speedTop = offset.y * column.speed;
|
|
289
|
+
var speedBottom = speedTop + rect.size.height;
|
|
290
|
+
|
|
291
|
+
// The speedAdjustment is the amount by which to displace each attribute's Y origin.
|
|
292
|
+
var speedAdjustment = offset.y - speedTop;
|
|
293
|
+
|
|
294
|
+
// Find the first attribute
|
|
295
|
+
var numberOfAttributes = column.attributes.length;
|
|
296
|
+
var attributes = column.attributes;
|
|
297
|
+
var attributeIndex = 0;
|
|
298
|
+
for (; attributeIndex < numberOfAttributes; attributeIndex++) {
|
|
299
|
+
var attribute = attributes[attributeIndex];
|
|
300
|
+
|
|
301
|
+
if (attribute.frame.bottom + speedAdjustment > rectTop) break;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Add attributes until they go off-screen
|
|
305
|
+
while (true) {
|
|
306
|
+
|
|
307
|
+
if (attributeIndex == numberOfAttributes) break;
|
|
308
|
+
|
|
309
|
+
var attribute = attributes[attributeIndex];
|
|
310
|
+
|
|
311
|
+
if (attribute.frame.top + speedAdjustment > rectBottom) break;
|
|
312
|
+
|
|
313
|
+
attribute = attribute.copy();
|
|
314
|
+
attribute.frame.origin.y = (attribute.frame.origin.y + speedAdjustment) | 0;
|
|
315
|
+
|
|
316
|
+
resultingAttributes.push(attribute);
|
|
317
|
+
|
|
318
|
+
attributeIndex++;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return resultingAttributes;
|
|
324
|
+
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
// @override - BMCollectionViewLayout
|
|
328
|
+
attributesForCellAtIndexPath: function (indexPath) {
|
|
329
|
+
return this.cachedAttributesForCellAtIndexPath(indexPath);
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Retrieves the cached attributes for the cell at the given index path.
|
|
334
|
+
* @param indexPath <BMIndexPath> The cell's index path.
|
|
335
|
+
* {
|
|
336
|
+
* @param usingCache <Object, nullable> Defaults to this layout's current cache. The cache object to use.
|
|
337
|
+
* }
|
|
338
|
+
*/
|
|
339
|
+
cachedAttributesForCellAtIndexPath: function (indexPath, options) {
|
|
340
|
+
var offset = this.collectionView.scrollOffset;
|
|
341
|
+
|
|
342
|
+
var cache = (options && options.usingCache) || this.cachedLayout;
|
|
343
|
+
|
|
344
|
+
// Find the attributes in each column
|
|
345
|
+
var columns = cache.columns;
|
|
346
|
+
var numberOfColumns = columns.length;
|
|
347
|
+
|
|
348
|
+
for (var i = 0; i < numberOfColumns; i++) {
|
|
349
|
+
var column = columns[i];
|
|
350
|
+
|
|
351
|
+
// The speedTop is the unscaled top position at which to start retrieving cells.
|
|
352
|
+
var speedTop = offset.y * column.speed;
|
|
353
|
+
|
|
354
|
+
// The speedAdjustment is the amount by which to displace each attribute's Y origin.
|
|
355
|
+
var speedAdjustment = offset.y - speedTop;
|
|
356
|
+
|
|
357
|
+
// Find the attribute
|
|
358
|
+
var numberOfAttributes = column.attributes.length;
|
|
359
|
+
var attributes = column.attributes;
|
|
360
|
+
var attributeIndex = 0;
|
|
361
|
+
for (; attributeIndex < numberOfAttributes; attributeIndex++) {
|
|
362
|
+
var attribute = attributes[attributeIndex];
|
|
363
|
+
|
|
364
|
+
if (attribute.indexPath.section == indexPath.section && attribute.indexPath.row == indexPath.row) {
|
|
365
|
+
attribute = attribute.copy();
|
|
366
|
+
|
|
367
|
+
attribute.frame.origin.y = (attribute.frame.origin.y + speedAdjustment) | 0;
|
|
368
|
+
attribute.speed = column.speed;
|
|
369
|
+
|
|
370
|
+
return attribute;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
// NOTE: All initialAttributes... methods will simply return a copy of the regular attributes with an additional style added
|
|
380
|
+
|
|
381
|
+
// @override - BMCollectionViewLayout
|
|
382
|
+
initialAttributesForPresentedCellAtIndexPath: function (indexPath) {
|
|
383
|
+
// attributesForCellAtIndexPath always returns copies, so it's not needed to copy it again here
|
|
384
|
+
var attributes = this.attributesForCellAtIndexPath(indexPath);
|
|
385
|
+
|
|
386
|
+
if (this.collectionView.delegate && this.collectionView.delegate.collectionViewInitialAttributesForPresentedCellAtIndexPath) {
|
|
387
|
+
return this.collectionView.delegate.collectionViewInitialAttributesForPresentedCellAtIndexPath(this.collectionView, indexPath, {withTargetAttributes: attributes, layout: this});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
attributes.frame.origin.y += (this.collectionView.frame.size.height / 3) * attributes.speed;
|
|
391
|
+
|
|
392
|
+
attributes.style = {
|
|
393
|
+
opacity: 0,
|
|
394
|
+
translateZ: 0,
|
|
395
|
+
rotateZ: '15deg'
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
return attributes;
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
// @override - BMCollectionViewLayout
|
|
402
|
+
initialAttributesForAppearingCellAtIndexPath: function (indexPath) {
|
|
403
|
+
// attributesForCellAtIndexPath always returns copies, so it's not needed to copy it again here
|
|
404
|
+
var attributes = this.attributesForCellAtIndexPath(indexPath);
|
|
405
|
+
|
|
406
|
+
if (this.collectionView.delegate && this.collectionView.delegate.collectionViewInitialAttributesForAppearingCellAtIndexPath) {
|
|
407
|
+
return this.collectionView.delegate.collectionViewInitialAttributesForAppearingCellAtIndexPath(this.collectionView, indexPath, {withTargetAttributes: attributes, layout: this});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
attributes.frame.origin.y += (this.collectionView.frame.size.height / 3) * attributes.speed;
|
|
411
|
+
|
|
412
|
+
attributes.style = {
|
|
413
|
+
opacity: 0,
|
|
414
|
+
translateZ: 0,
|
|
415
|
+
rotateZ: '15deg'
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
return attributes;
|
|
419
|
+
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
// @override - BMCollectionViewLayout
|
|
423
|
+
initialAttributesForMovingCellFromIndexPath: function (indexPath, options) {
|
|
424
|
+
var attributes;
|
|
425
|
+
var self = this;
|
|
426
|
+
|
|
427
|
+
this.collectionView.usingOldDataSet(function () {
|
|
428
|
+
attributes = self.cachedAttributesForCellAtIndexPath(indexPath, {usingCache: self.previousLayout});
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
return attributes;
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
// NOTE: All finalAttributes... methods will simply return a copy of the regular attributes from the previous layout with an additional style added
|
|
435
|
+
|
|
436
|
+
// @override - BMCollectionViewLayout
|
|
437
|
+
finalAttributesForDisappearingCellAtIndexPath: function (indexPath) {
|
|
438
|
+
var attributes;
|
|
439
|
+
var self = this;
|
|
440
|
+
|
|
441
|
+
this.collectionView.usingOldDataSet(function () {
|
|
442
|
+
attributes = self.cachedAttributesForCellAtIndexPath(indexPath, {usingCache: self.previousLayout});
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
if (self.collectionView.delegate && self.collectionView.delegate.collectionViewFinalAttributesForDisappearingCellAtIndexPath) {
|
|
447
|
+
attributes = self.collectionView.delegate.collectionViewFinalAttributesForDisappearingCellAtIndexPath(self.collectionView, indexPath, {withTargetAttributes: attributes});
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
attributes.frame.origin.y += (self.collectionView.frame.size.height / 3) * attributes.speed;
|
|
451
|
+
|
|
452
|
+
attributes.style = {
|
|
453
|
+
opacity: 0,
|
|
454
|
+
translateZ: 0,
|
|
455
|
+
rotateZ: '15deg'
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
return attributes;
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
// @override - BMCollectionViewLayout
|
|
465
|
+
copy: function () {
|
|
466
|
+
var copy = new BMCollectionViewMasonryLayout();
|
|
467
|
+
|
|
468
|
+
copy.minimumColumnWidth = this.minimumColumnWidth;
|
|
469
|
+
copy.numberOfColumns = this.numberOfColumns;
|
|
470
|
+
copy.columnSpacing = this.columnSpacing;
|
|
471
|
+
copy.cellSpacing = this.cellSpacing;
|
|
472
|
+
|
|
473
|
+
copy.columnSpeeds = this.columnSpeeds && this.columnSpeeds.slice();
|
|
474
|
+
|
|
475
|
+
copy.topPadding = this.topPadding;
|
|
476
|
+
copy.bottom = this.bottomPadding;
|
|
477
|
+
|
|
478
|
+
return copy;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Constructs and returns a new masonry layout.
|
|
485
|
+
* @returns <BMCollectionViewMasonryLayout> A masonry layout.
|
|
486
|
+
*/
|
|
487
|
+
BMCollectionViewMasonryLayout.masonryLayout = function () {
|
|
488
|
+
return new BMCollectionViewMasonryLayout();
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// @endtype
|