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,830 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {YES, NO, BMExtend, BMNumberByInterpolatingNumbersWithFraction} from '../Core/BMCoreUI'
|
|
4
|
+
import {BMSizeMake} from '../Core/BMSize'
|
|
5
|
+
import {BMRectMake} from '../Core/BMRect'
|
|
6
|
+
|
|
7
|
+
// @type BMCollectionViewLayout
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The collection view layout is an object that the collection view uses to determine where each element should appear on screen.
|
|
11
|
+
* Additionally, layout object can define supplementary views which help to enrich the display of the elements in the data set;
|
|
12
|
+
* however, supplementary views themselves are not directly part of the data set, though they may be derived from the contents of the data set.
|
|
13
|
+
*
|
|
14
|
+
* The <code>BMCollectionViewLayout</code> is an abstract type and cannot be used directly. It is meant to serve as a base type for concrete implementations.
|
|
15
|
+
* Concrete layout implementations are required to implement at least 3 of this type's abstract methods:
|
|
16
|
+
* <ul><li><b><code>attributesForCellAtIndexPath</code></b>: used to retrieve the attributes for a single cell</li>
|
|
17
|
+
* <li><b><code>attributesForElementsInRect</code></b>: used to retrieve the attributes of all cells and supplementary views in a given rect</li>
|
|
18
|
+
* <li><b><code>contentSize</code></b>: used to obtain the size of all the content in the collection view</li></ul>
|
|
19
|
+
*
|
|
20
|
+
* Addtionally, layouts that define supplementary views, must additionally implement the following method:
|
|
21
|
+
* <ul><li><b><code>attributesForSupplementaryViewWithIdentifier</code></b>: used to retrieve the attributes for a single supplementary view</li></ul>
|
|
22
|
+
*
|
|
23
|
+
* By default, the collection view defines 4 concrete layout types:
|
|
24
|
+
* <ul><li>BMCollectionViewFlowLayout</li>
|
|
25
|
+
* <li>BMCollectionViewMasonryLayout</li>
|
|
26
|
+
* <li>BMCollectionViewStackLayout</li>
|
|
27
|
+
* <li>BMCollectionViewTileLayout</li></ul>
|
|
28
|
+
*
|
|
29
|
+
* Creating a subtype of the <code>BMCollectionViewLayout</code> type can be achieved in several ways:
|
|
30
|
+
* <ol>
|
|
31
|
+
* <li> Create a type whose prototype inherits the <code>BMCollectionViewLayout</code> prototype, e.g.:
|
|
32
|
+
* <pre>
|
|
33
|
+
* MyCollectionViewLayout.prototype = Object.create(BMCollectionViewLayout.prototype, {
|
|
34
|
+
* // MyCollectionViewLayout prototype methods and properties here
|
|
35
|
+
* });
|
|
36
|
+
* </pre>
|
|
37
|
+
* </li>
|
|
38
|
+
* <li> Create a type whose prototype copies the properties of <code>BMCollectionViewLayout</code>'s prototype, e.g.:
|
|
39
|
+
* <pre>
|
|
40
|
+
* BMExtend(MyCollectionViewLayout.prototype, BMCollectionViewLayout.prototype, {
|
|
41
|
+
* // MyCollectionViewLayout prototype methods and properties here
|
|
42
|
+
* });
|
|
43
|
+
* </pre>
|
|
44
|
+
* </li>
|
|
45
|
+
* </ol>
|
|
46
|
+
*
|
|
47
|
+
* All layout objects should inherit from the `BMCollectionViewLayout` prototype.
|
|
48
|
+
*
|
|
49
|
+
* When called, a layout object triggers layout for its associated collection view.
|
|
50
|
+
*/
|
|
51
|
+
export function BMCollectionViewLayout() { // <constructor>
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
BMCollectionViewLayout.prototype = {
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The collection view that derives its layout information from this object.
|
|
59
|
+
*/
|
|
60
|
+
_collectionView: undefined, // <BMCollectionView>
|
|
61
|
+
|
|
62
|
+
get collectionView() { return this._collectionView; },
|
|
63
|
+
|
|
64
|
+
set collectionView(view) {
|
|
65
|
+
this._collectionView = view;
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Will be invoked by the collection view to retrieve the layout attributes for the cell at the specified index path.
|
|
70
|
+
* This method must return a valid BMCollectionViewLayoutAttributes object, which will be used to determine the position of the cell in the collection view.
|
|
71
|
+
* @param indexPath <BMIndexPath> The cell's index path.
|
|
72
|
+
* @return <BMCollectionViewLayoutAttributes> The cell attributes.
|
|
73
|
+
*/
|
|
74
|
+
/*required*/ attributesForCellAtIndexPath: function (indexPath) { throw new Error('attributesForCellAtIndexPath() must be implemented by layout objects.'); },
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Will be invoked by the collection view to retrieve the layout attributes for all cells and supplementary views that intersect the given rect.
|
|
78
|
+
* This method must return an array of valid BMCollectionViewLayoutAttributes objects, which will be used to determine the position of the cells and supplementary views in the collection view.
|
|
79
|
+
* The collection view will use the indexPath attribute of the BMCollectionViewLayoutAttributes objects to match the attributes to the cells and type property to determine whether each
|
|
80
|
+
* BMCollectionViewLayoutAttributes object applies to an item in the data set or to a supplementary view.
|
|
81
|
+
* @param rect <BMRect> The rect containing the cells.
|
|
82
|
+
* @return <[BMCollectionViewLayoutAttributes]> An array of cell attributes.
|
|
83
|
+
*/
|
|
84
|
+
/*required*/ attributesForElementsInRect: function (rect) { throw new Error('attributesForCellsInRect() must be implemented by layout objects.'); },
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Will be invoked by the collection view to determine the size of the collection view's contents.
|
|
88
|
+
* This method must return a valid BMSize object that represents the collection view's size.
|
|
89
|
+
* @return <BMSize> The size.
|
|
90
|
+
*/
|
|
91
|
+
/*required*/ contentSize: function() { throw new Error('contentSize() must be implemented by layout objects.'); },
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Will be invoked by the collection view to determine the layout attributes for a particular supplementary view.
|
|
95
|
+
* This method must be implemented if the layout object defines supplementary views.
|
|
96
|
+
* This method will also invoked during an update; during that time this method may return undefined, which indicates that
|
|
97
|
+
* the requested supplementary should no longer exist; otherwise this method must return valid cell attributes.
|
|
98
|
+
* @param identifier <String> The supplementary view's identifier which identifies the type of view.
|
|
99
|
+
* {
|
|
100
|
+
* @param atIndexPath <BMIndexPath> The view's index path.
|
|
101
|
+
* }
|
|
102
|
+
* @return <BMCollectionViewLayoutAttributes> The supplementary view attributes.
|
|
103
|
+
*/
|
|
104
|
+
attributesForSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
105
|
+
throw new Error('attributesForSupplementaryViewWithIdentifier(_, {atIndexPath}) must be implemented by layout objects that define supplementary views.');
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Will be invoked by the collection the first time it presents its contents or whenever the layout is invalidated.
|
|
110
|
+
* Layout objects can use this method to perform any necessary calculations before the layout will be displayed.
|
|
111
|
+
*/
|
|
112
|
+
prepareLayout: function () {},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* For layout objects that support invalidation contexts, this property should be overriden to return the correct type to use
|
|
116
|
+
* when creating new invalidation contexts.
|
|
117
|
+
* This property should return the constructor function for the invalidation context type.
|
|
118
|
+
*/
|
|
119
|
+
get invalidationContextType() { // <Function>
|
|
120
|
+
return BMCollectionViewLayoutInvalidationContext;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Should be overriden by layout objects that support copying and return `YES` to let collection view know
|
|
125
|
+
* that it can perform animated layout changes in certain cases.
|
|
126
|
+
* Layout objects that return `YES` from this getter must also implement the `copy()` method.
|
|
127
|
+
*
|
|
128
|
+
* The default implementation returns NO.
|
|
129
|
+
*/
|
|
130
|
+
get supportsCopying() { // <Boolean>
|
|
131
|
+
return NO;
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* This method should be invoked when a series of properties are about to be changed on this layout object to prevent
|
|
136
|
+
* unnecessary layout invalidations. After this method is invoked, layout invalidations are temporarily suspended while
|
|
137
|
+
* the properties are being updated.
|
|
138
|
+
*
|
|
139
|
+
* `applyUpdates()` must be invoked to commit the changes and re-enable layout invalidations.
|
|
140
|
+
* If this layout object does not support copying, this method will throw an error.
|
|
141
|
+
*/
|
|
142
|
+
beginUpdates() {
|
|
143
|
+
this._copy = this.copy();
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* This method must be invoked after `beginUpdates()` has been invoked to apply the changes to property and trigger a layout invalidation.
|
|
148
|
+
* If this method is invoked within an animation context, those changes will be animated.
|
|
149
|
+
*/
|
|
150
|
+
applyUpdates() {
|
|
151
|
+
if (this._collectionView) this._collectionView.invalidateLayout();
|
|
152
|
+
this._copy = undefined;
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
/****************************************** UPDATES ***********************************************/
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Will be invoked by the collection before it updates to a new data set.
|
|
159
|
+
* Until collectionViewDidStartUpdates() is invoked, it is recommended that the layout object should be able to produce both the
|
|
160
|
+
* current and the old layout attributes as the collection view may request both of them to be able to animate these changes.
|
|
161
|
+
* @param updates <[BMCollectionViewUpdate], nullable> An array of update objects describing how each item was changed; this array will either contain
|
|
162
|
+
* an update object for each changed element. For bulk updates, this parameter will be undefined.
|
|
163
|
+
* Instead, the old data set will be accessible from callbacks passed to the collectionView.usingOldDataSet() method.
|
|
164
|
+
*/
|
|
165
|
+
collectionViewWillStartUpdates: function (updates) {},
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Will be invoked by the collection view as a final step during updates.
|
|
169
|
+
* This method is called from within an animation block, so this method may be used to perform additional animations.
|
|
170
|
+
*/
|
|
171
|
+
collectionViewDidStartUpdates: function () {},
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Will be invoked by the collection view during an update to determine where the collection view should scroll to when applying the update.
|
|
175
|
+
* This method can be overriden by layout objects to control the scroll offset after the update, for example to keep the first element visible after the update.
|
|
176
|
+
* The default implementation returns the supplied offset point.
|
|
177
|
+
* @param offset <BMPoint> The current scroll offset.
|
|
178
|
+
* @return <BMPoint> The preferred scroll offset.
|
|
179
|
+
*/
|
|
180
|
+
preferredScrollOffsetWithOffset: function (offset) {
|
|
181
|
+
return offset;
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Will be invoked by the collection view during a layout change to determine where the collection view should scroll to when applying this layout.
|
|
186
|
+
* This method can be overriden by layout objects to control the scroll offset after the update, for example to keep the first element visible after the update.
|
|
187
|
+
* The default implementation returns the supplied offset point.
|
|
188
|
+
* @param fromLayout <BMCollectionViewLayout> The previous layout.
|
|
189
|
+
* {
|
|
190
|
+
* @param withOffset <BMPoint> The current scroll offset.
|
|
191
|
+
* }
|
|
192
|
+
* @return <BMPoint> The preferred scroll offset.
|
|
193
|
+
*/
|
|
194
|
+
preferredScrollOffsetForTransitionFromLayout: function (fromLayout, args) {
|
|
195
|
+
return this.preferredScrollOffsetWithOffset(args.withOffset);
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Will be invoked by the collection view to determine the initial attributes for a cell whose position has changed.
|
|
200
|
+
* It should be implemented by layout objects to supply the old position of a moving cell.
|
|
201
|
+
* This function recieves both the old and the new index paths as parameters.
|
|
202
|
+
* The two index paths may be identical, which implies that this cell moved because cells in other sections have been removed or added
|
|
203
|
+
* and this cell moves as a result.
|
|
204
|
+
* The default implementation will simply return the attributes for the new index path with the opacity set to 0.
|
|
205
|
+
* @param indexPath <BMIndexPath> The old index path.
|
|
206
|
+
* {
|
|
207
|
+
* @param toIndexPath <BMIndexPath> The new index path.
|
|
208
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
209
|
+
* }
|
|
210
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
211
|
+
*/
|
|
212
|
+
initialAttributesForMovingCellFromIndexPath: function (indexPath, options) {
|
|
213
|
+
var attributes = options.withTargetAttributes.copy(); //this.attributesForCellAtIndexPath(options.toIndexPath);
|
|
214
|
+
attributes.style = {opacity: 0};
|
|
215
|
+
return attributes;
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Will be invoked by the collection view to determine the initial attributes for a supplementary view whose position has changed.
|
|
220
|
+
* It should be implemented by layout objects to supply the old position of a moving supplementary view.
|
|
221
|
+
* This function only receives the new index path as a parameter. Since the layout object itself controls the index paths of
|
|
222
|
+
* supplementary views, it should determine on its own how the supplementary view was changed.
|
|
223
|
+
* The default implementation will simply return the attributes for the new index path with the opacity set to 0.
|
|
224
|
+
* @param identifier <String> The supplementary view's reuse identifier.
|
|
225
|
+
* {
|
|
226
|
+
* @param atIndexPath <BMIndexPath> The index path.
|
|
227
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
228
|
+
* }
|
|
229
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
230
|
+
*/
|
|
231
|
+
initialAttributesForMovingSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
232
|
+
var attributes = options.withTargetAttributes.copy(); //this.attributesForSupplementaryViewWithIdentifier(identifier, {atIndexPath: options.atIndexPath});
|
|
233
|
+
attributes.style = {opacity: 0};
|
|
234
|
+
return attributes;
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Will be invoked by the collection view to determine the initial attributes for a cell that was added to the collection.
|
|
239
|
+
* It may be implemented by layout objects to customize the appearance of newly added cells.
|
|
240
|
+
* The default implementation will return the default layout attributes with the scale and opacity set to 0.
|
|
241
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
242
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
243
|
+
* {
|
|
244
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
245
|
+
* }
|
|
246
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
247
|
+
*/
|
|
248
|
+
initialAttributesForAppearingCellAtIndexPath: function (indexPath, args) {
|
|
249
|
+
var attributes = args.withTargetAttributes.copy(); //this.attributesForCellAtIndexPath(indexPath);
|
|
250
|
+
attributes.style = {
|
|
251
|
+
scaleX: 0,
|
|
252
|
+
scaleY: 0,
|
|
253
|
+
opacity: 0
|
|
254
|
+
};
|
|
255
|
+
return attributes;
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Will be invoked by the collection view to determine the initial attributes for a supplementary view that was added to the collection.
|
|
260
|
+
* It may be implemented by layout objects to customize the appearance of newly added supplementary views.
|
|
261
|
+
* The default implementation will return the default layout attributes with the scale and opacity set to 0.
|
|
262
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
263
|
+
* @param identifier <String> The supplementary view's identifier.
|
|
264
|
+
* {
|
|
265
|
+
* @param atIndexPath <BMIndexPath> The index path.
|
|
266
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
267
|
+
* }
|
|
268
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
269
|
+
*/
|
|
270
|
+
initialAttributesForAppearingSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
271
|
+
var attributes = options.withTargetAttributes.copy();//this.attributesForSupplementaryViewWithIdentifier(identifier, {atIndexPath: options.atIndexPath});
|
|
272
|
+
attributes.style = {
|
|
273
|
+
scaleX: 0,
|
|
274
|
+
scaleY: 0,
|
|
275
|
+
opacity: 0
|
|
276
|
+
};
|
|
277
|
+
return attributes;
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Will be invoked by the collection view to determine the initial attributes for a cell that was previously hidden but has become visible.
|
|
282
|
+
* It may be implemented by layout objects to customize the appearance of cells that become visible.
|
|
283
|
+
* The default implementation will return the result of invoking initialAttributesForAppearingCellAtIndexPath().
|
|
284
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
285
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
286
|
+
* {
|
|
287
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
288
|
+
* }
|
|
289
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
290
|
+
*/
|
|
291
|
+
initialAttributesForRevealingCellAtIndexPath: function (indexPath, args) {
|
|
292
|
+
return this.initialAttributesForAppearingCellAtIndexPath(indexPath, args);
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Will be invoked by the collection view to determine the initial attributes for a supplementary view that was previously hidden but has become visible.
|
|
297
|
+
* It may be implemented by layout objects to customize the appearance of supplementary views that become visible.
|
|
298
|
+
* The default implementation will return the result of invoking initialAttributesForAppearingSupplementaryViewWithIdentifier().
|
|
299
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
300
|
+
* @param identifier <String> The supplementary view's identifier.
|
|
301
|
+
* {
|
|
302
|
+
* @param atIndexPath <BMIndexPath> The index path.
|
|
303
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
304
|
+
* }
|
|
305
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
306
|
+
*/
|
|
307
|
+
initialAttributesForRevealingSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
308
|
+
return this.initialAttributesForAppearingSupplementaryViewWithIdentifier(identifier, options);
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Will be invoked by the collection view to determine the initial attributes for a cell that is presented for the first time.
|
|
313
|
+
* It may be implemented by layout objects to customize the appearance of the introduction animation.
|
|
314
|
+
* The default implementation will return the default layout attributes with the scale and opacity set to 0.
|
|
315
|
+
* This method will only be invoked once for each visible cell after the collection first receives data.
|
|
316
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
317
|
+
* {
|
|
318
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
319
|
+
* }
|
|
320
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
321
|
+
*/
|
|
322
|
+
initialAttributesForPresentedCellAtIndexPath: function (indexPath, args) {
|
|
323
|
+
var attributes = args.withTargetAttributes.copy();//this.attributesForCellAtIndexPath(indexPath);
|
|
324
|
+
attributes.style = {
|
|
325
|
+
scaleX: 0,
|
|
326
|
+
scaleY: 0,
|
|
327
|
+
opacity: 0
|
|
328
|
+
};
|
|
329
|
+
return attributes;
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Will be invoked by the collection view to determine the initial attributes for a supplementary view that is presented for the first time.
|
|
334
|
+
* It may be implemented by layout objects to customize the appearance of the introduction animation.
|
|
335
|
+
* The default implementation will return the default layout attributes with the scale and opacity set to 0.
|
|
336
|
+
* This method will only be invoked once for each visible supplementary view after the collection first receives data.
|
|
337
|
+
* @param identifier <String> The supplementary view's identifier.
|
|
338
|
+
* {
|
|
339
|
+
* @param atIndexPath <BMIndexPath> The index path.
|
|
340
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
341
|
+
* }
|
|
342
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
343
|
+
*/
|
|
344
|
+
initialAttributesForPresentedSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
345
|
+
var attributes = options.withTargetAttributes.copy(); //this.attributesForSupplementaryViewWithIdentifier(identifier, {atIndexPath: options.atIndexPath});
|
|
346
|
+
attributes.style = {
|
|
347
|
+
scaleX: 0,
|
|
348
|
+
scaleY: 0,
|
|
349
|
+
opacity: 0
|
|
350
|
+
};
|
|
351
|
+
return attributes;
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Will be invoked by the collection view to determine which supplementary views should be added to the collection during an update.
|
|
356
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
357
|
+
* The default implementation returns an empty array.
|
|
358
|
+
* @return <[BMCollectionViewLayoutAttributes]> An array of cell attributes that contain the supplementary view index paths and their identifiers,
|
|
359
|
+
* or an empty array if no supplementary views should be added.
|
|
360
|
+
* The cell attributes returned by this method are not required to have valid frames.
|
|
361
|
+
*/
|
|
362
|
+
supplementaryViewsToInsert: function () {
|
|
363
|
+
return [];
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Will be invoked by the collection view to determine the final attributes for a cell that was removed from the collection.
|
|
368
|
+
* It may be implemented by layout objects to customize the appearance of removed cells.
|
|
369
|
+
* The default implementation will return the default layout attributes with the scale and opacity set to 0.
|
|
370
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
371
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
372
|
+
* {
|
|
373
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
374
|
+
* }
|
|
375
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
376
|
+
*/
|
|
377
|
+
finalAttributesForDisappearingCellAtIndexPath: function (indexPath, args) {
|
|
378
|
+
var attributes = args.withTargetAttributes.copy(); //this.attributesForCellAtIndexPath(indexPath);
|
|
379
|
+
attributes.style = {
|
|
380
|
+
scaleX: 0,
|
|
381
|
+
scaleY: 0,
|
|
382
|
+
opacity: 0
|
|
383
|
+
};
|
|
384
|
+
return attributes;
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Will be invoked by the collection view to determine the final attributes for a supplementary view that was removed from the collection.
|
|
389
|
+
* It may be implemented by layout objects to customize the appearance of removed supplementary views.
|
|
390
|
+
* The default implementation will return the default layout attributes with the scale and opacity set to 0.
|
|
391
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
392
|
+
* @param identifier <String> The supplementary view's identifier.
|
|
393
|
+
* {
|
|
394
|
+
* @param atIndexPath <BMIndexPath> The index path.
|
|
395
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
396
|
+
* }
|
|
397
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
398
|
+
*/
|
|
399
|
+
finalAttributesForDisappearingSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
400
|
+
var attributes = options.withTargetAttributes.copy(); //this.attributesForSupplementaryViewWithIdentifier(identifier, {atIndexPath: options.atIndexPath});
|
|
401
|
+
attributes.style = {
|
|
402
|
+
scaleX: 0,
|
|
403
|
+
scaleY: 0,
|
|
404
|
+
opacity: 0
|
|
405
|
+
};
|
|
406
|
+
return attributes;
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Will be invoked by the collection view to determine the final attributes for a cell that has become hidden.
|
|
411
|
+
* It may be implemented by layout objects to customize the appearance of hidden cells.
|
|
412
|
+
* The default implementation will return the result of invoking finalAttributesForDisappearingCellAtIndexPath().
|
|
413
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
414
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
415
|
+
* {
|
|
416
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
417
|
+
* }
|
|
418
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
419
|
+
*/
|
|
420
|
+
finalAttributesForHidingCellAtIndexPath: function (indexPath, args) {
|
|
421
|
+
return this.finalAttributesForDisappearingCellAtIndexPath(indexPath, args);
|
|
422
|
+
},
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Will be invoked by the collection view to determine the final attributes for a supplementary view that has become hidden.
|
|
426
|
+
* It may be implemented by layout objects to customize the appearance of hidden supplementary views.
|
|
427
|
+
* The default implementation will return the result of invoking finalAttributesForDisappearingSupplementaryViewWithIdentifier().
|
|
428
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
429
|
+
* @param identifier <String> The supplementary view's identifier.
|
|
430
|
+
* {
|
|
431
|
+
* @param atIndexPath <BMIndexPath> The index path.
|
|
432
|
+
* @param withTargetAttributes <BMCollectionViewLayoutAttributes> The cell's current attributes.
|
|
433
|
+
* }
|
|
434
|
+
* @return <BMCollectionViewLayoutAttributes> The attributes.
|
|
435
|
+
*/
|
|
436
|
+
finalAttributesForHidingSupplementaryViewWithIdentifier: function (identifier, options) {
|
|
437
|
+
return this.finalAttributesForDisappearingSupplementaryViewWithIdentifier(identifier, options);
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Will be invoked by the collection view to determine which supplementary views should be deleted from the collection during an update.
|
|
442
|
+
* This method will be invoked after collectionViewWillStartUpdates() and before collectionViewDidStartUpdates().
|
|
443
|
+
* The default implementation returns an empty array.
|
|
444
|
+
* @return <[BMCollectionViewLayoutAttributes]> An array of cell attributes that contain the supplementary view index paths and their identifiers,
|
|
445
|
+
* or an empty array if no supplementary views should be removed.
|
|
446
|
+
* The cell attributes returned by this method are not required to have valid frames.
|
|
447
|
+
*/
|
|
448
|
+
supplementaryViewsToDelete: function () {
|
|
449
|
+
return [];
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Invalidates the layout and causes it to be recalculated.
|
|
454
|
+
* This will invoke invalidateLayout() on the collection view.
|
|
455
|
+
* If this layout object is not associated with any collection view, invoking this method will have no effect.
|
|
456
|
+
*/
|
|
457
|
+
invalidateLayout: function () {
|
|
458
|
+
// If a batch update is in progress, suppress this invalidation
|
|
459
|
+
if (this._copy) return;
|
|
460
|
+
|
|
461
|
+
if (this._collectionView) this._collectionView.invalidateLayout();
|
|
462
|
+
},
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Invalidates the content size and causes it to be reapplied.
|
|
466
|
+
* This will invoke invalidateContentSize() on the collection view.
|
|
467
|
+
* If this layout object is not associated with any collection view, invoking this method will have no effect.
|
|
468
|
+
*/
|
|
469
|
+
invalidateContentSize: function () {
|
|
470
|
+
// If a batch update is in progress, suppress this invalidation
|
|
471
|
+
if (this._copy) return;
|
|
472
|
+
|
|
473
|
+
if (this._collectionView) this._collectionView.invalidateContentSize();
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Invalidates the parts of the layout that have changed and need to be recalculated.
|
|
478
|
+
* This will invoke invalidateLayoutWithContext() on the collection view.
|
|
479
|
+
* If this layout object is not associated with any collection view, invoking this method will have no effect.
|
|
480
|
+
*/
|
|
481
|
+
invalidateLayoutWithContext: function (context, args) {
|
|
482
|
+
if (this._collectionView) this._collectionView.invalidateLayoutWithContext(context, args);
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Will be invoked by the collection view whenever the frame changes, for example when the window is resized.
|
|
487
|
+
* Layout objects should return YES from this method if the new frame requires a new layout.
|
|
488
|
+
* The default implementation returns YES in all cases.
|
|
489
|
+
* @param frame <BMRect> The new frame.
|
|
490
|
+
* {
|
|
491
|
+
* @param fromFrame <BMRect, nullable> The previous frame, if one existed.
|
|
492
|
+
* }
|
|
493
|
+
* @return <Boolean> True if the new frame requires a new layout, false otherwise.
|
|
494
|
+
*/
|
|
495
|
+
shouldInvalidateLayoutForFrameChange: function (frame, args) {
|
|
496
|
+
return YES;
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Will be invoked by the collection view whenever the bounds change, for example when the user is scrolling.
|
|
501
|
+
* Layout objects should return YES from this method if the new bounds require a new layout.
|
|
502
|
+
* The default implementation returns NO in all cases.
|
|
503
|
+
* @param bounds <BMRect> The new bounds.
|
|
504
|
+
* @return <Boolean> True if the new frame requires a new layout, false otherwise.
|
|
505
|
+
*/
|
|
506
|
+
shouldInvalidateLayoutForBoundsChange: function (bounds) {
|
|
507
|
+
return NO;
|
|
508
|
+
},
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Will be invoked by the collection view whenever the layout has finished invalidating after a bounds change.
|
|
512
|
+
* Layout objects can implement this method to perform any final changes after a bounds change invalidation.
|
|
513
|
+
* The default implementation does nothing.
|
|
514
|
+
*/
|
|
515
|
+
didInvalidateLayoutForBoundsChange: function () {
|
|
516
|
+
|
|
517
|
+
},
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Invoked by the collection to determine the rect that it should scroll to in order to focus on
|
|
521
|
+
* the cell at the given index path.
|
|
522
|
+
* By default, this method retrieves the attributes for the cell at the given index path, then returns
|
|
523
|
+
* the frame property of those attributes.
|
|
524
|
+
* Layout subtypes may override this method to provide custom bounding boxes. For example, when
|
|
525
|
+
* cell positions change depending on the current scroll position, subtypes may override this method
|
|
526
|
+
* to return the correct position that the collection view should scroll to in order to reveal the given index path.
|
|
527
|
+
* If the attributes cannot be determined, the method will return a rect that causes the collection view to scroll back to the top.
|
|
528
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
529
|
+
* @return <BMRect> A rect.
|
|
530
|
+
*/
|
|
531
|
+
rectWithScrollingPositionOfCellAtIndexPath: function (indexPath) {
|
|
532
|
+
var attributes = this.attributesForCellAtIndexPath(indexPath);
|
|
533
|
+
|
|
534
|
+
if (attributes) return attributes.frame;
|
|
535
|
+
|
|
536
|
+
return BMRectMake();
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Invoked by the collection to determine the rect that it should scroll to in order to focus on
|
|
541
|
+
* the supplementary view of the given type at the given index path.
|
|
542
|
+
* By default, this method retrieves the attributes for the supplementary view at the given index path, then returns
|
|
543
|
+
* the frame property of those attributes.
|
|
544
|
+
* Layout subtypes may override this method to provide custom bounding boxes. For example, when
|
|
545
|
+
* cell positions change depending on the current scroll position, subtypes may override this method
|
|
546
|
+
* to return the correct position that the collection view should scroll to in order to reveal the given index path.
|
|
547
|
+
* If the attributes cannot be determined, the method will return a rect that causes the collection view to scroll back to the top.
|
|
548
|
+
* @param indexPath <BMIndexPath> The index path.
|
|
549
|
+
* @return <BMRect> A rect.
|
|
550
|
+
*/
|
|
551
|
+
rectWithScrollingPositionOfSupplementaryViewWithIdentifier: function (identifier, args) {
|
|
552
|
+
var attributes = this.attributesForSupplementaryViewWithIdentifier(identifier, args);
|
|
553
|
+
|
|
554
|
+
if (attributes) return attributes.frame;
|
|
555
|
+
|
|
556
|
+
return BMRectMake();
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* May be set to `YES` by layout objects in order to snap the scroll position to certain breakpoints.
|
|
561
|
+
* When layout objects return `YES` from this method, the collection view will invoke the
|
|
562
|
+
* `snappingScrollOffsetForScrollOffset(_, {withVerticalDirection, horizontalDirection})` method to determine what point it should snap its scroll to.
|
|
563
|
+
*/
|
|
564
|
+
get snapsScrollPosition() { // <Boolean>
|
|
565
|
+
return NO;
|
|
566
|
+
},
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Invoked by the collection view when this layout supports snapping scroll positions to determine the snapping scroll offset
|
|
570
|
+
* for the given scroll offset.
|
|
571
|
+
* Layout object must return a valid scroll offset from this method.
|
|
572
|
+
* @param offset <BMPoint> The current scroll offset.
|
|
573
|
+
* {
|
|
574
|
+
* @param withVerticalDirection <BMScrollingDirectionVertical> The terminal vertical scrolling direction.
|
|
575
|
+
* @param horizontalDirection <BMScrollingDirectionHorizontal> The terminal horizontal scrolling direction.
|
|
576
|
+
* }
|
|
577
|
+
* @return <BMPoint> The scroll offset to which the collection view should snap.
|
|
578
|
+
*/
|
|
579
|
+
snappingScrollOffsetForScrollOffset: function (offset, args) {
|
|
580
|
+
return offset;
|
|
581
|
+
},
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Invoked by collection view when a dragging operation is about to begin and the index paths of the items
|
|
585
|
+
* is about to shift. Layout subclasses may override this method to prepare for this change.
|
|
586
|
+
*
|
|
587
|
+
* If the user drops the item in an invalid position, collection view will invoke the `dragOperationWillRollback()` method
|
|
588
|
+
* and immediately follow with an animated data update to move the item back.
|
|
589
|
+
*
|
|
590
|
+
* When the operation completes, collection view will invoke the `dragOperationDidFinish()` method and finalize updating
|
|
591
|
+
* the item's new position in the data set.
|
|
592
|
+
*
|
|
593
|
+
* The default implementation does nothing.
|
|
594
|
+
*/
|
|
595
|
+
prepareForDragOperation() {
|
|
596
|
+
|
|
597
|
+
},
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Invoked by collection view when a drag and drop operation finishes in a point where there is no index path
|
|
601
|
+
* and the operation should be rolled back.
|
|
602
|
+
* Subclasses should override this method to undo any changes they may have made when preparing for that drag
|
|
603
|
+
* operation.
|
|
604
|
+
* The default implementation does nothing.
|
|
605
|
+
*/
|
|
606
|
+
dragOperationWillRollback() {
|
|
607
|
+
|
|
608
|
+
},
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Invoked by collection view when a drag and drop operation finishes in a point where there is an index path
|
|
612
|
+
* and the dragged item is about to be moved to the new index path.
|
|
613
|
+
* Subclasses should override this method to prepare for the changes.
|
|
614
|
+
* The default implementation does nothing.
|
|
615
|
+
*/
|
|
616
|
+
dragOperationDidFinish() {
|
|
617
|
+
|
|
618
|
+
},
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Invoked by collection view when measuring a cell to obtain additional constraints to apply to the cell during the measurement.
|
|
622
|
+
* Layout subclasses can override this method and return an array of constraints that they would like the cell to use, for example
|
|
623
|
+
* to specify maximum or minimum sizes.
|
|
624
|
+
* The constraints returned by this method should not be marked as active; collection view will activate these constraints as needed.
|
|
625
|
+
* The default implementation returns an empty array.
|
|
626
|
+
* @param cell <BMCollectionViewCell> The cell that is being measured.
|
|
627
|
+
* {
|
|
628
|
+
* @param atIndexPath <BMIndexPath> The index path of the measured cell.
|
|
629
|
+
* }
|
|
630
|
+
* @return <[BMLayoutConstraint]> An array of layout constraints.
|
|
631
|
+
*/
|
|
632
|
+
constraintsForMeasuringCell(cell, {atIndexPath}) {
|
|
633
|
+
return [];
|
|
634
|
+
},
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Should be implemented by layout objects that support copying.
|
|
638
|
+
* @return <BMCollectionViewLayout> A copy of this layout object. The copy should not be bound to any collection view.
|
|
639
|
+
*/
|
|
640
|
+
copy: function () {
|
|
641
|
+
throw new Error('Layout objects that support copying should implement the copy() method.');
|
|
642
|
+
},
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Should be overriden by layout objects that support sateful copying and return `YES` to let collection view know
|
|
646
|
+
* that it can perform animated layout changes using a stateful copy.
|
|
647
|
+
* Layout objects that return `YES` from this getter must also implement the `statefulCopy()` method.
|
|
648
|
+
*
|
|
649
|
+
* The default implementation returns `NO`.
|
|
650
|
+
*/
|
|
651
|
+
get supportsStatefulCopying() {
|
|
652
|
+
return NO;
|
|
653
|
+
},
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Should be implemented by layout objects that support stateful copying.
|
|
657
|
+
* Unlike a regular copy, a stateful copy is expected to also retain the internal state of the layout.
|
|
658
|
+
* When this method is implemented by a layout subclass, it should also override its `supportsStatefulCopying` property
|
|
659
|
+
* to return `YES`.
|
|
660
|
+
*
|
|
661
|
+
* Stateful copies, when implemented, are used by collection view during animated layout changes to
|
|
662
|
+
* avoid having to prepare the layout on the copy layout. When a stateful copy is created, collection view will
|
|
663
|
+
* assume that it can directly use the layout copy to request attributes without any additional preparation.
|
|
664
|
+
*
|
|
665
|
+
* When creating a stateful copy, the state should not be shared between the new copy and the original layout object.
|
|
666
|
+
*
|
|
667
|
+
* The default implementation returns the result of copying this layout.
|
|
668
|
+
* @return <BMCollectionViewLayout> A stateful copy of this layout.
|
|
669
|
+
*/
|
|
670
|
+
statefulCopy() {
|
|
671
|
+
return this.copy();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// @endtype
|
|
677
|
+
|
|
678
|
+
// @type BMCollectionViewLayoutInvalidationContext
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* An invalidation context is an object that describes which parts of the layout should be changed during an invalidation.
|
|
682
|
+
* Layout objects that support invalidation contexts can use these objects to optimize their invalidation process and
|
|
683
|
+
* only update the parts of the layout that have actually changed.
|
|
684
|
+
*
|
|
685
|
+
* To use invalidation contexts, create a subtype of the base invalidation context type and define the properties that
|
|
686
|
+
* represent the parts of the layout that can be updated independently. Then, when the layout should be invalidated, create an invalidation context and invoke the
|
|
687
|
+
* invalidateLayoutWithContext method on the collection view, passing in the newly created invalidation context.
|
|
688
|
+
*
|
|
689
|
+
* Invalidation context subtypes must invoke the base initializer at some point during initialization.
|
|
690
|
+
*
|
|
691
|
+
* The collection view itself will create its own invalidation contexts as part of certain changes. Layout objects that support invalidation
|
|
692
|
+
* contexts should override the <code>invalidationContextType</code> property to return the correct type. The collection view will use that type when creating
|
|
693
|
+
* new invalidation contexts.
|
|
694
|
+
*
|
|
695
|
+
* During a layout update, the current invalidation context can be retrieved through the collection view's <code>invalidationContext</code> property.
|
|
696
|
+
*/
|
|
697
|
+
function BMCollectionViewLayoutInvalidationContext() {} // <constructor>
|
|
698
|
+
|
|
699
|
+
BMCollectionViewLayoutInvalidationContext.prototype = {
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Indicates whether the entire layout should be invalidated or not.
|
|
703
|
+
*/
|
|
704
|
+
invalidateEverything: NO, // <Boolean>
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Indicates whether or not the data set counts have changed.
|
|
708
|
+
*/
|
|
709
|
+
invalidateDataSetCounts: NO, // <Boolean>
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* If set to a size, this represents the amounts by which the content size should change.
|
|
713
|
+
* When this attribute is supplied, the collection view will not query the layout for the new content size.
|
|
714
|
+
*/
|
|
715
|
+
contentSizeAdjustment: undefined, // <BMSize>
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* An array of index paths that represent the cells that were invalidated.
|
|
719
|
+
*/
|
|
720
|
+
invalidatedCellIndexPaths: undefined, // <[BMIndexPath], nullable>
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* A dictionary whose keys represent the identifiers and values the index paths of supplementary views that were invalidated.
|
|
724
|
+
*/
|
|
725
|
+
invalidatedSupplementaryViewIndexPaths: undefined, // <Object<String, [BMIndexPath]>, nullable>
|
|
726
|
+
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
// @endtype
|
|
730
|
+
|
|
731
|
+
// @type BMCollectionViewTransitionLayout extends BMCollectionViewLayout
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* A specialized layout object that manages the transition between two different layout objects.
|
|
735
|
+
* A transition layout is temporarily installed on a collection view when its setLayout() method is invoked with the animated parameter set to YES.
|
|
736
|
+
* The transition layout should not be created and used directly. A collection view will automatically create, manage and destroy a transition layout
|
|
737
|
+
* as part of an animated layout change.
|
|
738
|
+
* @param attributes <[_BMCollectionViewTransitionCellAttributes]> The transition cell attributes.
|
|
739
|
+
* @param initialSize <BMSize> The content size supplied by the source layout.
|
|
740
|
+
* @param targetSize <BMSize> The content size supplied by the target layout.
|
|
741
|
+
* @param targetLayout <BMCollectionViewLayout> The layout to which this transition layout transitions.
|
|
742
|
+
*/
|
|
743
|
+
export var _BMCollectionViewTransitionLayout = function (attributes, initialSize, targetSize, targetLayout) { // <constructor>
|
|
744
|
+
this.transitionAttributes = attributes;
|
|
745
|
+
|
|
746
|
+
this.initialSize = initialSize;
|
|
747
|
+
this.targetSize = targetSize;
|
|
748
|
+
this.targetLayout = targetLayout;
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
_BMCollectionViewTransitionLayout.prototype = BMExtend({}, BMCollectionViewLayout.prototype, {
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Controls how close to completion the transition is.
|
|
755
|
+
*/
|
|
756
|
+
_fraction: 0, // <Number>
|
|
757
|
+
get fraction() { return this._fraction; },
|
|
758
|
+
set fraction(fraction) {
|
|
759
|
+
// If this is no longer attached to a collection view, don't perform any changes
|
|
760
|
+
if (!this.collectionView) return;
|
|
761
|
+
|
|
762
|
+
this._fraction = fraction;
|
|
763
|
+
|
|
764
|
+
var attributesLength = this.transitionAttributes.length;
|
|
765
|
+
for (var i = 0; i < attributesLength; i++) {
|
|
766
|
+
this.transitionAttributes[i].fraction = fraction;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
//this.collectionView.invalidateLayoutForBoundsChange();
|
|
770
|
+
},
|
|
771
|
+
|
|
772
|
+
// @override - BMCollectionViewLayout
|
|
773
|
+
attributesForElementsInRect: function (rect) {
|
|
774
|
+
return this.transitionAttributes;
|
|
775
|
+
},
|
|
776
|
+
|
|
777
|
+
// @override - BMCollectionViewLayout
|
|
778
|
+
contentSize: function () {
|
|
779
|
+
return BMSizeMake(
|
|
780
|
+
BMNumberByInterpolatingNumbersWithFraction(this.initialSize.width, this.targetSize.width, this._fraction),
|
|
781
|
+
BMNumberByInterpolatingNumbersWithFraction(this.initialSize.height, this.targetSize.height, this._fraction)
|
|
782
|
+
);
|
|
783
|
+
},
|
|
784
|
+
|
|
785
|
+
// @override - BMCollectionViewLayout
|
|
786
|
+
attributesForCellAtIndexPath: function (indexPath, args) {
|
|
787
|
+
// First try to return the transition attributes, if they are available
|
|
788
|
+
for (let attribute of this.transitionAttributes) {
|
|
789
|
+
if (attribute.indexPath.isEqualToIndexPath(indexPath, {usingComparator: this.collectionView.identityComparator})) {
|
|
790
|
+
return attribute;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return this.targetLayout.attributesForCellAtIndexPath(indexPath, args);
|
|
794
|
+
},
|
|
795
|
+
|
|
796
|
+
// @override - BMCollectionViewLayout
|
|
797
|
+
attributesForSupplementaryViewWithIdentifier: function (identifier, args) {
|
|
798
|
+
return this.targetLayout.attributesForSupplementaryViewWithIdentifier(identifier, args);
|
|
799
|
+
},
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Invoked by the collection view at the end of a layout transition.
|
|
803
|
+
* Causes the transition layout to apply the final attributes to all animated cells.
|
|
804
|
+
*/
|
|
805
|
+
_applyFinalAttributes: function () {
|
|
806
|
+
|
|
807
|
+
var attributesLength = this.transitionAttributes.length;
|
|
808
|
+
for (var i = 0; i < attributesLength; i++) {
|
|
809
|
+
this.transitionAttributes[i]._applyFinalAttributes();
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
},
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Invoked by the collection view at the beginning of a layout transition.
|
|
816
|
+
* Causes the transition layout to run an animated layout pass on all animated cells.
|
|
817
|
+
*/
|
|
818
|
+
_layout() {
|
|
819
|
+
|
|
820
|
+
var attributesLength = this.transitionAttributes.length;
|
|
821
|
+
for (var i = 0; i < attributesLength; i++) {
|
|
822
|
+
this.transitionAttributes[i]._layout();
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
this.collectionView._cellLayoutQueue.dequeue();
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
// @endtype
|