Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make layout provider non optional #114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final class NamesSectionController: ListSectionController<
NamesSectionViewModelType,
String
> {
override var layoutProvider: SectionLayoutProvider? {
override var layoutProvider: SectionLayoutProvider {
let layoutSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .estimated(50)
Expand Down Expand Up @@ -36,7 +36,7 @@ final class NamesSectionController: ListSectionController<
layout.boundarySupplementaryItems = []
}
return .compositionalLayout(
.init(layoutSection: { _ in layout })
.init { _ in layout }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension ListCollectionViewAdapter {
@inlinable
public func flowDelegate(at indexPath: IndexPath) -> SectionFlowDelegate? {
if #available(iOS 13.0, *) {
return controller(at: indexPath)?.layoutProvider?.flowLayoutProvider
return controller(at: indexPath)?.layoutProvider.flowLayoutProvider
} else {
return controller(at: indexPath)?.flowDelegate
}
Expand All @@ -68,7 +68,7 @@ extension ListCollectionViewAdapter {
@inlinable
public func flowDelegate(at index: Int) -> SectionFlowDelegate? {
if #available(iOS 13.0, *) {
return controller(at: index)?.layoutProvider?.flowLayoutProvider
return controller(at: index)?.layoutProvider.flowLayoutProvider
} else {
return controller(at: index)?.flowDelegate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension SingleSectionCollectionViewAdapter {
@inlinable
public func flowDelegate(at indexPath: IndexPath) -> SectionFlowDelegate? {
if #available(iOS 13.0, *) {
return controller(at: indexPath)?.layoutProvider?.flowLayoutProvider
return controller(at: indexPath)?.layoutProvider.flowLayoutProvider
} else {
return controller(at: indexPath)?.flowDelegate
}
Expand All @@ -68,7 +68,7 @@ extension SingleSectionCollectionViewAdapter {
@inlinable
public func flowDelegate(at index: Int) -> SectionFlowDelegate? {
if #available(iOS 13.0, *) {
return controller(at: index)?.layoutProvider?.flowLayoutProvider
return controller(at: index)?.layoutProvider.flowLayoutProvider
} else {
return controller(at: index)?.flowDelegate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class BaseSectionController: SectionController,
open var dropDelegate: SectionDropDelegate? { self }

@available(iOS 13.0, *)
open var layoutProvider: SectionLayoutProvider? { .flowLayout(self) }
open var layoutProvider: SectionLayoutProvider { .flowLayout(self) }

open func didUpdate(model: Any) { }

Expand Down
13 changes: 5 additions & 8 deletions SectionKit/Sources/SectionController/SectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol SectionController: AnyObject {
var dropDelegate: SectionDropDelegate? { get }

@available(iOS 13.0, *)
var layoutProvider: SectionLayoutProvider? { get }
var layoutProvider: SectionLayoutProvider { get }

/// The model of this section controller changed.
func didUpdate(model: Any)
Expand All @@ -47,14 +47,11 @@ extension SectionController {

@available(iOS 11.0, *)
public var dropDelegate: SectionDropDelegate? { nil }

@available(iOS 13.0, *)
public var layoutProvider: SectionLayoutProvider? { nil }
}

@available(iOS 13.0, *)
public enum SectionLayoutProvider {
case flowLayout(FlowLayoutProvider)
case flowLayout(FlowLayoutProvider?)
Prajakta-Aher-TR marked this conversation as resolved.
Show resolved Hide resolved
case compositionalLayout(CompositionalLayoutProvider)
}

Expand All @@ -67,12 +64,12 @@ public struct CompositionalLayoutProvider {
/// - Parameters:
/// - layoutEnvironment: the environment value for the layout
/// - Returns: The layout for the section
var layoutSection: (_ layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection
var layoutSectionProvider: (_ layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection

public init(
layoutSection: @escaping (any NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection
layoutSectionProvider: @escaping (any NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection
) {
self.layoutSection = layoutSection
self.layoutSectionProvider = layoutSectionProvider
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ final public class SectionKitCompositionalLayout: UICollectionViewCompositionalL
return .empty
}
guard case .compositionalLayout(let provider) = sections[index].controller.layoutProvider else {
assertionFailure("Please set the layout provider with `CompositionalLayoutProvider`")
let sectionType = String(describing: type(of: sections[index].controller))
assertionFailure("Please set the layout provider with `CompositionalLayoutProvider` in \(sectionType)")
return .empty
}
return provider.layoutSection(environment)
return provider.layoutSectionProvider(environment)
}
sections = { [weak self] in
self?.sections?() ?? []
Expand Down
Loading
Loading