diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift index 1272cdd..2c36b8d 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift @@ -20,7 +20,7 @@ extension Extendable where Base: Layout.Section { layoutEnvironment environment: Layout.Environment, style: Layout.Style, supplementaryItems: [SupplementaryItem] = [], - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets? = nil ) -> Base { create( @@ -40,10 +40,11 @@ extension Extendable where Base: Layout.Compositional { public static func custom( style: Layout.Style, supplementaryItems: [SupplementaryItem] = [], - decoration: DecorationStyle? = .whiteBackground, - edgeInsets: SectionEdgeInsets? = nil - ) -> Self { - Base { _, environment in + decoration: DecorationStyle? = nil, + edgeInsets: SectionEdgeInsets? = nil, + configuration: Layout.CompositionalConfiguration? = nil + ) -> Base { + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.custom( layoutEnvironment: environment, style: style, @@ -51,7 +52,10 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration, edgeInsets: edgeInsets ) - }.rak + } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } } @@ -62,7 +66,7 @@ extension SectionProviderWrapper { public static func custom( style: Layout.Style, supplementaryItems: [SupplementaryItem] = [], - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets? = nil ) -> Self { .init { diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Epoxy.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Epoxy.swift deleted file mode 100644 index 150d954..0000000 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Epoxy.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// Layout+Epoxy.swift -// RakuyoKit -// -// Created by Rakuyo on 2024/4/9. -// Copyright © 2024 RakuyoKit. All rights reserved. -// - -#if !os(watchOS) && !os(tvOS) && !os(visionOS) -import UIKit - -import EpoxyCollectionView -import RAKCore - -extension Extendable where Base: Layout.Compositional { - public static var epoxy: Extendable { Base.epoxy.rak } -} -#endif diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift index 7f062b7..975d5df 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift @@ -23,7 +23,7 @@ extension Extendable where Base: Layout.Section { customGroup: Layout.CustomGroupFactory? = nil, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets? = nil ) -> Base { custom( @@ -50,10 +50,11 @@ extension Extendable where Base: Layout.Compositional { customGroup: Layout.CustomGroupFactory? = nil, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, - edgeInsets: SectionEdgeInsets? = nil - ) -> Self { - Base { _, environment in + decoration: DecorationStyle? = nil, + edgeInsets: SectionEdgeInsets? = nil, + configuration: Layout.CompositionalConfiguration? = nil + ) -> Base { + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.flow( layoutEnvironment: environment, itemSize: itemSize, @@ -64,7 +65,10 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration, edgeInsets: edgeInsets ) - }.rak + } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } } @@ -78,7 +82,7 @@ extension SectionProviderWrapper { customGroup: Layout.CustomGroupFactory? = nil, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets? = nil ) -> Self { .init { diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+General.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+General.swift index 1cd251b..2f13320 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+General.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+General.swift @@ -25,6 +25,7 @@ extension Extendable where Base: Layout.Section { return .init(group: group).then { section in section.contentInsets = edgeInsets.edgeInsets + section.decorationItems = createDecorationItems(by: decoration, edgeInsets: edgeInsets) section.boundarySupplementaryItems = supplementaryItems.map { createSupplementaryItem(with: $0) } @@ -32,11 +33,6 @@ extension Extendable where Base: Layout.Section { if case .flow(_, let behavior, _) = style { section.orthogonalScrollingBehavior = behavior } - - let decorationItems = createDecorationItems(by: decoration, edgeInsets: edgeInsets) - if decorationItems.isNotEmpty { - section.decorationItems = decorationItems - } } } } diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift index 73446e6..3f178e1 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift @@ -36,7 +36,7 @@ extension Extendable where Base: Layout.Section { layoutEnvironment environment: Layout.Environment, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets ) -> Base { custom( @@ -57,9 +57,10 @@ extension Extendable where Base: Layout.Compositional { spacing: ListSpacing = .default, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground - ) -> Self { - Base { _, environment in + decoration: DecorationStyle? = nil, + configuration: Layout.CompositionalConfiguration? = nil + ) -> Base { + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.list( layoutEnvironment: environment, spacing: spacing, @@ -67,16 +68,20 @@ extension Extendable where Base: Layout.Compositional { footer: footer, decoration: decoration ) - }.rak + } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } public static func list( header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, - edgeInsets: SectionEdgeInsets - ) -> Self { - Base { _, environment in + decoration: DecorationStyle? = nil, + edgeInsets: SectionEdgeInsets, + configuration: Layout.CompositionalConfiguration? = nil + ) -> Base { + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.list( layoutEnvironment: environment, header: header, @@ -84,7 +89,10 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration, edgeInsets: edgeInsets ) - }.rak + } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } } @@ -112,7 +120,7 @@ extension SectionProviderWrapper { public static func list( header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets ) -> Self { .init { diff --git a/Sources/Epoxy/CollectionView/Layout/Model/Layout.swift b/Sources/Epoxy/CollectionView/Layout/Model/Layout.swift index c2a522c..fda56a9 100644 --- a/Sources/Epoxy/CollectionView/Layout/Model/Layout.swift +++ b/Sources/Epoxy/CollectionView/Layout/Model/Layout.swift @@ -18,7 +18,11 @@ public enum Layout { public typealias Dimension = NSCollectionLayoutDimension public typealias Compositional = UICollectionViewCompositionalLayout - + + public typealias CompositionalConfiguration = UICollectionViewCompositionalLayoutConfiguration + + public typealias CompositionalSectionProvider = UICollectionViewCompositionalLayoutSectionProvider + public typealias Item = NSCollectionLayoutItem public typealias GroupCustomItem = NSCollectionLayoutGroupCustomItem diff --git a/Sources/Epoxy/CollectionView/Tools/SectionEdgeInsets.swift b/Sources/Epoxy/CollectionView/Tools/SectionEdgeInsets.swift index 7abd07e..1026c4c 100644 --- a/Sources/Epoxy/CollectionView/Tools/SectionEdgeInsets.swift +++ b/Sources/Epoxy/CollectionView/Tools/SectionEdgeInsets.swift @@ -40,7 +40,7 @@ public enum SectionEdgeInsets { /// Same spacing as `.insetGrouped` style `UITableView` /// /// (top: 0, leading: 20, bottom: 35, trailing: 20) - case groupCard(horizontal: CGFloat = 20, bottom: CGFloat = 35) + case groupCard(horizontal: CGFloat = 20, bottom: ListSpacing = .group) /// Fully customized using `EdgeInsets`. case custom(RAKCore.EdgeInsets) @@ -73,7 +73,7 @@ extension SectionEdgeInsets { .init(top: top, leading: leading, bottom: bottom, trailing: trailing) case .groupCard(let horizontal, let bottom): - .init(top: 0, leading: horizontal, bottom: bottom, trailing: horizontal) + .init(top: 0, leading: horizontal, bottom: bottom.spacing, trailing: horizontal) case .custom(let edge): edge.directionalEdgeInsets