public override UICollectionViewLayoutInvalidationContext GetInvalidationContext(UICollectionViewLayoutAttributes preferredAttributes, UICollectionViewLayoutAttributes originalAttributes) { if (preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Header && preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Footer) { return(base.GetInvalidationContext(preferredAttributes, originalAttributes)); } // Ensure that if this invalidation was triggered by header/footer changes, the header/footer are being invalidated UICollectionViewFlowLayoutInvalidationContext invalidationContext = new UICollectionViewFlowLayoutInvalidationContext(); var indexPath = preferredAttributes.IndexPath; 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); // On iOS 10 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 }
public override UICollectionViewLayoutInvalidationContext GetInvalidationContext(UICollectionViewLayoutAttributes preferredAttributes, UICollectionViewLayoutAttributes originalAttributes) { if (preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Header && preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Footer) { if (Forms.IsiOS12OrNewer) { return(base.GetInvalidationContext(preferredAttributes, originalAttributes)); } try { // We only have to do this on older iOS versions; sometimes when removing a cell that's right at the edge // of the viewport we'll run into a race condition where the invalidation context will have the removed // indexpath. And then things crash. So var defaultContext = base.GetInvalidationContext(preferredAttributes, originalAttributes); return(defaultContext); } catch (MonoTouchException ex) when(ex.Name == "NSRangeException") { Forms.MauiContext?.CreateLogger <ItemsViewLayout>()?.LogWarning(ex, "NSRangeExceptiond"); } UICollectionViewFlowLayoutInvalidationContext context = new UICollectionViewFlowLayoutInvalidationContext(); return(context); } // Ensure that if this invalidation was triggered by header/footer changes, the header/footer are being invalidated UICollectionViewFlowLayoutInvalidationContext invalidationContext = new UICollectionViewFlowLayoutInvalidationContext(); var indexPath = preferredAttributes.IndexPath; 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); }
public override UICollectionViewLayoutInvalidationContext GetInvalidationContext(UICollectionViewLayoutAttributes preferredAttributes, UICollectionViewLayoutAttributes originalAttributes) { if (preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Header && preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Footer) { return(base.GetInvalidationContext(preferredAttributes, originalAttributes)); } // Ensure that if this invalidation was triggered by header/footer changes, the header/footer are being invalidated UICollectionViewFlowLayoutInvalidationContext invalidationContext = new UICollectionViewFlowLayoutInvalidationContext(); var indexPath = preferredAttributes.IndexPath; 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); }