Skip to content

Commit f5d9aa7

Browse files
committed
fix(ios): working itemOverlap
1 parent 458b9da commit f5d9aa7

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/collectionview/index.ios.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CoreTypes,
66
EventData,
77
KeyedTemplate,
8+
Length,
89
Observable,
910
Property,
1011
ProxyViewContainer,
@@ -988,12 +989,10 @@ export class CollectionView extends CollectionViewBase {
988989
}
989990
if (this.itemOverlap) {
990991
// should we force clipsToBounds? not doing so allows more complex layouts like overlapping
991-
cell.clipsToBounds = false;
992992
// we set zPosition to allow overlap. Should we make it an option?
993993
cell.layer.zPosition = indexPath.row;
994-
} else {
995-
cell.clipsToBounds = true;
996994
}
995+
cell.clipsToBounds = true;
997996
const firstRender = !cell.view;
998997
if (Trace.isEnabled()) {
999998
CLog(CLogTypes.log, 'collectionViewCellForItemAtIndexPath', indexPath.row, templateType, !!cell.view, cell);
@@ -1197,6 +1196,32 @@ class UICollectionViewFlowLayoutImpl extends UICollectionViewFlowLayout {
11971196
}
11981197
return super.invalidationContextForInteractivelyMovingItemsWithTargetPositionPreviousIndexPathsPreviousPosition(targetIndexPaths, targetPosition, previousIndexPaths, previousPosition);
11991198
}
1199+
layoutAttributesForElementsInRect(rect: CGRect) {
1200+
const attributesArray = super.layoutAttributesForElementsInRect(rect);
1201+
const owner = this._owner?.get();
1202+
if (owner?.itemOverlap) {
1203+
const itemOverlap = owner.itemOverlap;
1204+
for (let index = 0; index < attributesArray.count; index++) {
1205+
const attributes = attributesArray.objectAtIndex(index);
1206+
if (attributes.representedElementCategory === UICollectionElementCategory.Cell) {
1207+
const xPosition =
1208+
attributes.center.x + Utils.layout.toDeviceIndependentPixels(Length.toDevicePixels(itemOverlap[1], 0) + Length.toDevicePixels(itemOverlap[2], 0)) * attributes.indexPath.row;
1209+
const yPosition =
1210+
attributes.center.y + Utils.layout.toDeviceIndependentPixels(Length.toDevicePixels(itemOverlap[0], 0) + Length.toDevicePixels(itemOverlap[2], 0)) * attributes.indexPath.row;
1211+
attributes.center = CGPointMake(xPosition, yPosition);
1212+
}
1213+
}
1214+
}
1215+
1216+
return attributesArray;
1217+
}
1218+
shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) {
1219+
const owner = this._owner?.get();
1220+
if (owner?.itemOverlap) {
1221+
return true;
1222+
}
1223+
return super.shouldInvalidateLayoutForBoundsChange(newBounds);
1224+
}
12001225
}
12011226
@NativeClass
12021227
class CollectionViewDataSource extends NSObject implements UICollectionViewDataSource {

0 commit comments

Comments
 (0)