Skip to content

Commit

Permalink
Order ZIndex by global index
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed Aug 11, 2020
1 parent ed6a8ba commit fc59087
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
7 changes: 4 additions & 3 deletions Listable/Sources/HeaderFooter/HeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 1 addition & 2 deletions Listable/Sources/Item/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Listable/Sources/Layout/CollectionViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ final class CollectionViewLayout : UICollectionViewLayout
direction: self.layout.direction,
showsScrollIndicators: self.appearance.showsScrollIndicators
)

self.performLayout()
}

Expand All @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions Listable/Sources/Layout/ListLayout/ListLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}


Expand Down
11 changes: 9 additions & 2 deletions Listable/Sources/Layout/ListLayout/ListLayoutContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}


Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
}
Expand All @@ -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),
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 1 addition & 13 deletions Listable/Sources/Layout/SupplementaryKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation


enum SupplementaryKind : String, CaseIterable
public enum SupplementaryKind : String, CaseIterable
{
case listHeader = "Listable.ListHeader"
case listFooter = "Listable.ListFooter"
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,4 @@ fileprivate func AssertListLayoutContentItemEqual(
XCTAssertTrue(lhs === rhs, "")
}
}

0 comments on commit fc59087

Please sign in to comment.