diff --git a/Listable/Sources/HeaderFooter/HeaderFooter.swift b/Listable/Sources/HeaderFooter/HeaderFooter.swift index 6f05dc4be..d05706c3f 100644 --- a/Listable/Sources/HeaderFooter/HeaderFooter.swift +++ b/Listable/Sources/HeaderFooter/HeaderFooter.swift @@ -106,9 +106,10 @@ extension HeaderFooter : SignpostLoggable public struct HeaderFooterLayout : Equatable { public var width : CustomWidth - - public init(width : CustomWidth = .default) - { + + public init( + width : CustomWidth = .default + ) { self.width = width } } diff --git a/Listable/Sources/Item/Item.swift b/Listable/Sources/Item/Item.swift index 365094627..6fd5f9107 100644 --- a/Listable/Sources/Item/Item.swift +++ b/Listable/Sources/Item/Item.swift @@ -311,8 +311,7 @@ public struct ItemLayout : Equatable itemSpacing : CGFloat? = nil, itemToSectionFooterSpacing : CGFloat? = nil, width : CustomWidth = .default - ) - { + ) { self.itemSpacing = itemSpacing self.itemSpacing = itemSpacing self.width = width diff --git a/Listable/Sources/Layout/CollectionViewLayout.swift b/Listable/Sources/Layout/CollectionViewLayout.swift index 715b8a45e..0d779cb33 100644 --- a/Listable/Sources/Layout/CollectionViewLayout.swift +++ b/Listable/Sources/Layout/CollectionViewLayout.swift @@ -330,7 +330,7 @@ final class CollectionViewLayout : UICollectionViewLayout direction: self.layout.direction, showsScrollIndicators: self.appearance.showsScrollIndicators ) - + self.performLayout() } @@ -347,6 +347,8 @@ final class CollectionViewLayout : UICollectionViewLayout self.layout.updateLayout(in: view) + self.layout.setZIndexes() + self.layout.updateOverscrollFooterPosition(in: view) self.layout.adjustPositionsForLayoutUnderflow(in: view) diff --git a/Listable/Sources/Layout/ListLayout/ListLayout.swift b/Listable/Sources/Layout/ListLayout/ListLayout.swift index defb8d760..633077d68 100644 --- a/Listable/Sources/Layout/ListLayout/ListLayout.swift +++ b/Listable/Sources/Layout/ListLayout/ListLayout.swift @@ -58,6 +58,19 @@ public protocol AnyListLayout : AnyObject delegate : CollectionViewLayoutDelegate, in collectionView : UICollectionView ) + + func setZIndexes() +} + + +public extension AnyListLayout +{ + func setZIndexes() + { + self.content.all.forEachWithIndex { index, _, item in + item.zIndex = index + } + } } diff --git a/Listable/Sources/Layout/ListLayout/ListLayoutContent.swift b/Listable/Sources/Layout/ListLayout/ListLayoutContent.swift index 4a5002e27..a60bdaf69 100644 --- a/Listable/Sources/Layout/ListLayout/ListLayoutContent.swift +++ b/Listable/Sources/Layout/ListLayout/ListLayoutContent.swift @@ -226,8 +226,11 @@ public final class ListLayoutContent protocol ListLayoutContentItem : AnyObject { var size : CGSize { get set } + var x : CGFloat { get set } var y : CGFloat { get set } + + var zIndex : Int { get set } } @@ -320,6 +323,8 @@ public extension ListLayoutContent var y : CGFloat = .zero var pinnedY : CGFloat? = nil + var zIndex : Int = 0 + var defaultFrame : CGRect { CGRect( origin: CGPoint(x: self.x, y: self.y), @@ -354,7 +359,7 @@ public extension ListLayoutContent let attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: self.kind.rawValue, with: indexPath) attributes.frame = self.visibleFrame - attributes.zIndex = self.kind.zIndex + attributes.zIndex = self.zIndex return attributes } @@ -376,6 +381,8 @@ public extension ListLayoutContent var x : CGFloat = .zero var y : CGFloat = .zero + var zIndex : Int = 0 + var frame : CGRect { CGRect( origin: CGPoint(x: self.x, y: self.y), @@ -404,7 +411,7 @@ public extension ListLayoutContent let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath) attributes.frame = self.frame - attributes.zIndex = 0 + attributes.zIndex = self.zIndex return attributes } diff --git a/Listable/Sources/Layout/SupplementaryKind.swift b/Listable/Sources/Layout/SupplementaryKind.swift index b48b3baf0..47891a056 100644 --- a/Listable/Sources/Layout/SupplementaryKind.swift +++ b/Listable/Sources/Layout/SupplementaryKind.swift @@ -8,7 +8,7 @@ import Foundation -enum SupplementaryKind : String, CaseIterable +public enum SupplementaryKind : String, CaseIterable { case listHeader = "Listable.ListHeader" case listFooter = "Listable.ListFooter" @@ -17,18 +17,6 @@ enum SupplementaryKind : String, CaseIterable case sectionFooter = "Listable.SectionFooter" case overscrollFooter = "Listable.OverscrollFooter" - - var zIndex : Int { - switch self { - case .listHeader: return 1 - case .listFooter: return 1 - - case .sectionHeader: return 2 - case .sectionFooter: return 1 - - case .overscrollFooter: return 1 - } - } func indexPath(in section : Int) -> IndexPath { diff --git a/Listable/Tests/Layout/ListLayout/ListLayoutContentTests.swift b/Listable/Tests/Layout/ListLayout/ListLayoutContentTests.swift index 5e3f909f2..12572b725 100644 --- a/Listable/Tests/Layout/ListLayout/ListLayoutContentTests.swift +++ b/Listable/Tests/Layout/ListLayout/ListLayoutContentTests.swift @@ -256,3 +256,4 @@ fileprivate func AssertListLayoutContentItemEqual( XCTAssertTrue(lhs === rhs, "") } } +