Skip to content

Commit

Permalink
merge the section controller with section layout provider and depreca…
Browse files Browse the repository at this point in the history
…ted the old functions
  • Loading branch information
CalvinChangCC committed May 22, 2024
1 parent dc80cf6 commit f5492f3
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 385 deletions.
84 changes: 20 additions & 64 deletions SectionKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ extension ListCollectionViewAdapter {
extension ListCollectionViewAdapter {
@inlinable
public func flowDelegate(at indexPath: IndexPath) -> SectionFlowDelegate? {
(controller(at: indexPath) as? FlowLayoutSectionController)?.flowDelegate
if #available(iOS 13.0, *) {
controller(at: indexPath)?.layoutProvider?.flowLayoutProvider
} else {
controller(at: indexPath)?.flowDelegate
}
}

@inlinable
public func flowDelegate(at index: Int) -> SectionFlowDelegate? {
(controller(at: index) as? FlowLayoutSectionController)?.flowDelegate
if #available(iOS 13.0, *) {
controller(at: index)?.layoutProvider?.flowLayoutProvider
} else {
controller(at: index)?.flowDelegate
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ extension SingleSectionCollectionViewAdapter {
extension SingleSectionCollectionViewAdapter {
@inlinable
public func flowDelegate(at indexPath: IndexPath) -> SectionFlowDelegate? {
(controller(at: indexPath) as? FlowLayoutSectionController)?.flowDelegate
if #available(iOS 13.0, *) {
controller(at: indexPath)?.layoutProvider?.flowLayoutProvider
} else {
controller(at: indexPath)?.flowDelegate
}
}

@inlinable
public func flowDelegate(at index: Int) -> SectionFlowDelegate? {
(controller(at: index) as? FlowLayoutSectionController)?.flowDelegate
if #available(iOS 13.0, *) {
controller(at: index)?.layoutProvider?.flowLayoutProvider
} else {
controller(at: index)?.flowDelegate
}
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open class BaseSectionController: SectionController,
SectionDataSource,
SectionDataSourcePrefetchingDelegate,
SectionDelegate,
SectionFlowDelegate,
SectionDragDelegate,
SectionDropDelegate {
// MARK: - Init
Expand All @@ -31,6 +32,9 @@ open class BaseSectionController: SectionController,
@available(iOS 11.0, *)
open var dropDelegate: SectionDropDelegate? { self }

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

open func didUpdate(model: Any) { }

// MARK: - SectionDataSource
Expand Down Expand Up @@ -221,6 +225,81 @@ open class BaseSectionController: SectionController,
nil
}

// MARK: - SectionFlowDelegate

@available(
iOS,
introduced: 6.0,
deprecated: 13.0,
message: "Please use the layoutProvider with the flowLayout type"
)
open func sizeForItem(
at indexPath: SectionIndexPath,
using layout: UICollectionViewLayout,
in context: CollectionViewContext
) -> CGSize {
layout.flowLayout?.itemSize ?? FlowLayoutConstants.defaultItemSize
}

@available(
iOS,
introduced: 6.0,
deprecated: 13.0,
message: "Please use the layoutProvider with the flowLayout type"
)
open func inset(using layout: UICollectionViewLayout, in context: CollectionViewContext) -> UIEdgeInsets {
layout.flowLayout?.sectionInset ?? FlowLayoutConstants.defaultInset
}

@available(
iOS,
introduced: 6.0,
deprecated: 13.0,
message: "Please use the layoutProvider with the flowLayout type"
)
open func minimumLineSpacing(using layout: UICollectionViewLayout, in context: CollectionViewContext) -> CGFloat {
layout.flowLayout?.minimumLineSpacing ?? FlowLayoutConstants.defaultMinimumLineSpacing
}

@available(
iOS,
introduced: 6.0,
deprecated: 13.0,
message: "Please use the layoutProvider with the flowLayout type"
)
open func minimumInteritemSpacing(
using layout: UICollectionViewLayout,
in context: CollectionViewContext
) -> CGFloat {
layout.flowLayout?.minimumInteritemSpacing ?? FlowLayoutConstants.defaultMinimumInteritemSpacing
}

@available(
iOS,
introduced: 6.0,
deprecated: 13.0,
message: "Please use the layoutProvider with the flowLayout type"
)
open func referenceSizeForHeader(
using layout: UICollectionViewLayout,
in context: CollectionViewContext
) -> CGSize {
layout.flowLayout?.headerReferenceSize ?? FlowLayoutConstants.defaultHeaderSize
}

@available(
iOS,
introduced: 6.0,
deprecated: 13.0,
message: "Please use the layoutProvider with the flowLayout type"
)
open func referenceSizeForFooter(
using layout: UICollectionViewLayout,
in context: CollectionViewContext
) -> CGSize {
layout.flowLayout?.footerReferenceSize ?? FlowLayoutConstants.defaultFooterSize
}

// MARK: - SectionDropDelegate

@available(iOS 11.0, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import Foundation
*/
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@MainActor
open class FoundationDiffingListFlowLayoutSectionController<
open class FoundationDiffingListSectionController<
Model,
Item: Hashable
>: ListFlowLaoutSectionController<Model, Item> {
>: ListSectionController<Model, Item> {
override open func calculateUpdate(
from oldData: [Item],
to newData: [Item]
Expand All @@ -32,12 +32,3 @@ open class FoundationDiffingListFlowLayoutSectionController<
)
}
}

@available(
*,
deprecated,
renamed: "FoundationDiffingListFlowLayoutSectionController",
message: "It has been renamed to FoundationDiffingListFlowLayoutSectionController"
)
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public typealias FoundationDiffingListSectionController = FoundationDiffingListFlowLayoutSectionController
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import UIKit
of a model to be displayed and the list of items (almost) never changes or should not perform animated updates.
*/
@MainActor
@available(iOS 13.0, *)
open class ListCompositionalLayoutSectionController<Model, Item>: BaseCompositionalLayoutSectionController {
open class ListSectionController<Model, Item>: BaseSectionController {
/**
Initialise an instance of `ListSectionController`.

Expand Down Expand Up @@ -72,7 +71,7 @@ open class ListCompositionalLayoutSectionController<Model, Item>: BaseCompositio

/**
The list of items currently displayed in the `UICollectionView`.

Only set this property if `UICollectionView` insertions and deletions are handled, otherwise use `items` instead.
*/
open var collectionViewItems: [Item] = []
Expand All @@ -93,11 +92,11 @@ open class ListCompositionalLayoutSectionController<Model, Item>: BaseCompositio

/**
Calculate the `UICollectionView` events using the difference from the old to the new data.

- Parameter oldData: The old data currently displayed in the section.

- Parameter newData: The new data that should be displayed in the section.

- Returns: The update that should be performed on the section.
*/
open func calculateUpdate(
Expand Down
Loading

0 comments on commit f5492f3

Please sign in to comment.