This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class VerticalCollectionViewLayout: UICollectionViewFlowLayout { | |
unowned fileprivate let collectionViewData: CollectionData | |
fileprivate var cachedItemAttributes = [IndexPath:UICollectionViewLayoutAttributes]() | |
fileprivate var globalOffset = CGPoint() | |
var contentSize = CGSize() | |
public init(collectionViewData: CollectionData) { | |
self.collectionViewData = collectionViewData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//--- SectionDescriptor | |
// new propertie | |
private(set) var verticalSpaces = [Int: VerticalSpace]() | |
@discardableResult public func reloadSection(_ builderClosure: @escaping BuilderClosure) -> SectionDescriptor { | |
let builder = Builder(sectionDescriptor: self) | |
builderClosure(builder) | |
verticalSpaces = builder.verticalSpaces | |
return reloadSection { cells in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---- VerticalSpace.swift | |
public typealias VerticalSpace = CGFloat | |
public extension CGFloat { | |
public static var zero: VerticalSpace = 0 | |
public static var small: VerticalSpace = 5 | |
public static var medium: VerticalSpace = 10 | |
public static var big: VerticalSpace = 20 | |
public static var huge: VerticalSpace = 40 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public typealias BuilderClosure = (Builder) -> Void | |
@discardableResult public func reloadSection(_ builderClosure: @escaping BuilderClosure) -> SectionDescriptor { | |
let builder = Builder(sectionDescriptor: self) | |
builderClosure(builder) | |
return reloadSection { cells in | |
cells = builder.cells | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Collor | |
public class Builder { | |
private(set) unowned var sectionDescriptor: CollectionSectionDescribable | |
public private(set) var cells = [CollectionCellDescribable]() | |
public init(sectionDescriptor: CollectionSectionDescribable) { | |
self.sectionDescriptor = sectionDescriptor | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Collor | |
final class SampleCollectionData: CollorAPI.CollectionData { | |
override func reloadData() { | |
super.reloadData() | |
addSection().reloadSection { cells in | |
// add cells here | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Collor | |
open class CollectionData: Collor.CollectionData { | |
open override func reloadData() { | |
super.reloadData() | |
} | |
public func addSection() -> SectionDescriptor { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SectionDescriptor: CollectionSectionDescribable { | |
private var lineSpacing = VerticalSpace.zero | |
private var horizontalInset: CGFloat = Inset.sectionDefault | |
public func lineSpacing(_ value: VerticalSpace) -> SectionDescriptor { | |
lineSpacing = value | |
return self | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) { | |
super.prepare(forCollectionViewUpdates: updateItems) | |
decorationViewHandler.prepare(forCollectionViewUpdates: updateItems) | |
} | |
override func indexPathsToInsertForDecorationView(ofKind elementKind: String) -> [IndexPath] { | |
return decorationViewHandler.inserted(for: elementKind) | |
} | |
override func indexPathsToDeleteForDecorationView(ofKind elementKind: String) -> [IndexPath] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let decorationAttributes = decorationViewHandler.attributes(in:rect) |