public override void InvalidateLayout(UICollectionViewLayoutInvalidationContext context) { base.InvalidateLayout(context); if (CollectionView != null) { var currentCollectionViewSize = CollectionView.Bounds.Size; if (!currentCollectionViewSize.Equals(lastCollectionViewSize)) { ConfigureInset(); lastCollectionViewSize = currentCollectionViewSize; } } }
public override UICollectionViewLayoutInvalidationContext GetInvalidationContext(UICollectionViewLayoutAttributes preferredAttributes, UICollectionViewLayoutAttributes originalAttributes) { if (Forms.IsiOS11OrNewer) { return(base.GetInvalidationContext(preferredAttributes, originalAttributes)); } var indexPath = preferredAttributes.IndexPath; try { UICollectionViewLayoutInvalidationContext invalidationContext = base.GetInvalidationContext(preferredAttributes, originalAttributes); // Ensure that if this invalidation was triggered by header/footer changes, the header/footer // are being invalidated if (preferredAttributes.RepresentedElementKind == UICollectionElementKindSectionKey.Header) { invalidationContext.InvalidateSupplementaryElements(UICollectionElementKindSectionKey.Header, new[] { indexPath }); } else if (preferredAttributes.RepresentedElementKind == UICollectionElementKindSectionKey.Footer) { invalidationContext.InvalidateSupplementaryElements(UICollectionElementKindSectionKey.Footer, new[] { indexPath }); } return(invalidationContext); } catch (MonoTouchException) { // This happens on iOS 10 if we have any empty groups in our ItemsSource. Catching here and // returning a UICollectionViewFlowLayoutInvalidationContext means that the application does not // crash, though any group headers/footers will initially draw in the wrong location. It's possible to // work around this problem by forcing a full layout update after the headers/footers have been // drawn in the wrong places } return(new UICollectionViewFlowLayoutInvalidationContext()); }