public void PrepareCellForLayout(ItemsViewCell cell) { if (EstimatedItemSize == CGSize.Empty) { cell.ConstrainTo(ItemSize); } else { cell.ConstrainTo(ConstrainedDimension); } }
protected void DetermineCellSize() { if (GetPrototype == null) { return; } // We set the EstimatedItemSize here for two reasons: // 1. If we don't set it, iOS versions below 10 will crash // 2. If GetPrototype() cannot return a cell because the items source is empty, we need to have // an estimate set so that when a cell _does_ become available (i.e., when the items source // has at least one item), Autolayout will kick in for the first cell and size it correctly // If GetPrototype() _can_ return a cell, this estimate will be updated once that cell is measured if (EstimatedItemSize == CGSize.Empty) { EstimatedItemSize = new CGSize(1, 1); } ItemsViewCell prototype = null; if (CollectionView?.VisibleCells.Length > 0) { prototype = CollectionView.VisibleCells[0] as ItemsViewCell; } if (prototype == null) { prototype = GetPrototype() as ItemsViewCell; } if (prototype == null) { return; } // Constrain and measure the prototype cell prototype.ConstrainTo(ConstrainedDimension); var measure = prototype.Measure(); if (ItemSizingStrategy == ItemSizingStrategy.MeasureFirstItem) { // This is the size we'll give all of our cells from here on out ItemSize = measure; // Make sure autolayout is disabled EstimatedItemSize = CGSize.Empty; } else { // Autolayout is now enabled, and this is the size used to guess scrollbar size and progress EstimatedItemSize = measure; } }