From cd23384db34a384655f224274a18cd5a83f86a3b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 8 Jun 2020 10:01:58 -0400 Subject: [PATCH] Made the code more concise --- .../UICollectionViewLeftAlignedLayout.swift | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift index 37be12bf..717bbc55 100644 --- a/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift +++ b/MVMCoreUI/BaseClasses/UICollectionViewLeftAlignedLayout.swift @@ -5,30 +5,21 @@ // Created by Dhamodaram Nandi on 05/06/20. // Copyright © 2020 Verizon Wireless. All rights reserved. // +// Left aligns items and makes the minimumInteritemSpacing absolute. import Foundation class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout { override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - guard let attributes = super.layoutAttributesForElements(in: rect) else { - return nil - } + guard let attributes = super.layoutAttributesForElements(in: rect) else { return nil } var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]() - var leftMargin: CGFloat = 0.0; - let leftPadding: CGFloat = 0 - let interItemSpacing = minimumInteritemSpacing - var maxY: CGFloat = -1.0 for attribute in attributes { - if attribute.frame.origin.y >= maxY { - leftMargin = leftPadding + if let previousFrame = newAttributesForElementsInRect.last, + MVMCoreGetterUtility.cgfequal(previousFrame.frame.minY, attribute.frame.minY) { + attribute.frame.origin.x = previousFrame.frame.maxX + minimumInteritemSpacing } else { - var newLeftAlignedFrame = attribute.frame - newLeftAlignedFrame.origin.x = leftMargin - attribute.frame = newLeftAlignedFrame + attribute.frame.origin.x = 0 } - attribute.frame.origin.x = leftMargin - leftMargin += attribute.frame.width + interItemSpacing - maxY = max(attribute.frame.maxY, maxY) newAttributesForElementsInRect.append(attribute) } return newAttributesForElementsInRect