Skip to content

Commit d19393d

Browse files
committed
fix(collectionview): ios fixes for autoReloadItemOnLayout
1 parent ef61912 commit d19393d

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/collectionview/index.ios.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -601,23 +601,19 @@ export class CollectionView extends CollectionViewBase {
601601
getItemTemplateContent(index, templateType) {
602602
return this.getViewForViewType(ListViewViewTypes.ItemView, templateType);
603603
}
604-
public _prepareCell(cell: CollectionViewCell, indexPath: NSIndexPath, templateType: string, addToMap = true) {
604+
public _prepareCell(cell: CollectionViewCell, indexPath: NSIndexPath, templateType: string, notForCellSizeComp = true) {
605605
let cellSize: [number, number];
606606
try {
607607
this._preparingCell = true;
608608
let view = cell.view;
609609
const index = indexPath.row;
610-
let needsLayout = false;
611610
if (!view) {
612-
needsLayout = true;
613611
view = this.getItemTemplateContent(index, templateType);
614612
}
615-
const oldBindingContext = view && view.bindingContext;
616613
const bindingContext = this._prepareItem(view, index);
617-
needsLayout = needsLayout || oldBindingContext !== bindingContext;
618614

619615
if (Trace.isEnabled()) {
620-
CLog(CLogTypes.log, '_prepareCell', index, !!cell.view, !!view, cell.view !== view, needsLayout);
616+
CLog(CLogTypes.log, '_prepareCell', index, templateType, !!cell.view, !!view, cell.view !== view, notForCellSizeComp);
621617
}
622618
const args = this.notifyForItemAtIndex(this, cell, view, CollectionViewBase.itemLoadingEvent, indexPath, bindingContext);
623619
view = args.view;
@@ -636,33 +632,34 @@ export class CollectionView extends CollectionViewBase {
636632
cell.owner = new WeakRef(view);
637633
}
638634

639-
if (addToMap) {
635+
if (notForCellSizeComp) {
640636
this._map.set(cell, view);
641637
}
642638

643639
if (view && !view.parent) {
644640
this._addView(view);
645641
const innerView = NSCellView.new() as NSCellView;
646642
innerView.view = new WeakRef(view);
647-
if(this.autoReloadItemOnLayout) {
643+
if(!notForCellSizeComp || this.autoReloadItemOnLayout) {
648644
// for a cell to update correctly on cell layout change we need
649645
// to do it ourself instead of "propagating it"
650646
view['performLayout'] = () => {
651-
const indexes = NSMutableArray.new<NSIndexPath>();
652-
indexes.addObject(indexPath);
653-
const nativeViewProtected = this.nativeViewProtected;
654-
UIView.performWithoutAnimation(() => {
655-
nativeViewProtected.performBatchUpdatesCompletion(() => {
656-
nativeViewProtected.reloadItemsAtIndexPaths(indexes);
657-
}, null);
658-
});
647+
if (notForCellSizeComp) {
648+
this.measureCell(cell, view, indexPath);
649+
this.layoutCell(indexPath.row, cell, view);
650+
this.nativeViewProtected.collectionViewLayout.invalidateLayout()
651+
}
659652
};
653+
} else {
654+
console.log('prepared for template')
660655
}
661656
innerView.addSubview(view.nativeViewProtected);
662657
cell.contentView.addSubview(innerView);
663658
}
664659
cellSize = this.measureCell(cell, view, indexPath);
665-
view.notify({ eventName: CollectionViewBase.bindedEvent });
660+
if (notForCellSizeComp) {
661+
view.notify({ eventName: CollectionViewBase.bindedEvent });
662+
}
666663

667664
if (Trace.isEnabled()) {
668665
CLog(CLogTypes.log, '_prepareCell done', index, cellSize);

0 commit comments

Comments
 (0)