From 06ef63bcaca84dd6d44d5fad4ca296d3a8701ad4 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Sat, 13 Jul 2024 22:34:19 +0800 Subject: [PATCH 1/6] feat: remove `Layout.Compositional.rak.epoxy` --- .../Layout/LayoutImplement/Layout+Epoxy.swift | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Epoxy.swift 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 From de57b8c141a7798446885ff8fc246616a3e550b3 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Sat, 13 Jul 2024 22:40:40 +0800 Subject: [PATCH 2/6] feat: Methods in `Layout.Compositional` extensions are changed to return Base instead of Self --- .../Layout/LayoutImplement/Layout+Custom.swift | 4 ++-- .../Layout/LayoutImplement/Layout+Flow.swift | 4 ++-- .../Layout/LayoutImplement/Layout+List.swift | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift index 1272cdd..9d25ddc 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift @@ -42,7 +42,7 @@ extension Extendable where Base: Layout.Compositional { supplementaryItems: [SupplementaryItem] = [], decoration: DecorationStyle? = .whiteBackground, edgeInsets: SectionEdgeInsets? = nil - ) -> Self { + ) -> Base { Base { _, environment in Layout.Section.rak.custom( layoutEnvironment: environment, @@ -51,7 +51,7 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration, edgeInsets: edgeInsets ) - }.rak + } } } diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift index 7f062b7..21647b4 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift @@ -52,7 +52,7 @@ extension Extendable where Base: Layout.Compositional { footer: SupplementaryItem.Style? = nil, decoration: DecorationStyle? = .whiteBackground, edgeInsets: SectionEdgeInsets? = nil - ) -> Self { + ) -> Base { Base { _, environment in Layout.Section.rak.flow( layoutEnvironment: environment, @@ -64,7 +64,7 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration, edgeInsets: edgeInsets ) - }.rak + } } } diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift index 73446e6..a4ed58e 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift @@ -58,7 +58,7 @@ extension Extendable where Base: Layout.Compositional { header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, decoration: DecorationStyle? = .whiteBackground - ) -> Self { + ) -> Base { Base { _, environment in Layout.Section.rak.list( layoutEnvironment: environment, @@ -67,7 +67,7 @@ extension Extendable where Base: Layout.Compositional { footer: footer, decoration: decoration ) - }.rak + } } public static func list( @@ -75,7 +75,7 @@ extension Extendable where Base: Layout.Compositional { footer: SupplementaryItem.Style? = nil, decoration: DecorationStyle? = .whiteBackground, edgeInsets: SectionEdgeInsets - ) -> Self { + ) -> Base { Base { _, environment in Layout.Section.rak.list( layoutEnvironment: environment, @@ -84,7 +84,7 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration, edgeInsets: edgeInsets ) - }.rak + } } } From b086be2c9ad4bd72da932876e8aa9db1b6bb47a1 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Sat, 13 Jul 2024 22:40:58 +0800 Subject: [PATCH 3/6] feat: Update --- .../Layout/LayoutImplement/Layout+General.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 - } } } } From fc4875062692f806292b1c0ff78dbb5cfce0f6e7 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Sat, 13 Jul 2024 22:43:39 +0800 Subject: [PATCH 4/6] feat: The default value of `decoration` changed from `.whiteBackground` to `nil` --- .../Layout/LayoutImplement/Layout+Custom.swift | 6 +++--- .../Layout/LayoutImplement/Layout+Flow.swift | 6 +++--- .../Layout/LayoutImplement/Layout+List.swift | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift index 9d25ddc..47aec56 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,7 +40,7 @@ extension Extendable where Base: Layout.Compositional { public static func custom( style: Layout.Style, supplementaryItems: [SupplementaryItem] = [], - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets? = nil ) -> Base { Base { _, environment in @@ -62,7 +62,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+Flow.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift index 21647b4..1340d54 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,7 +50,7 @@ extension Extendable where Base: Layout.Compositional { customGroup: Layout.CustomGroupFactory? = nil, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets? = nil ) -> Base { Base { _, environment in @@ -78,7 +78,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+List.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift index a4ed58e..d780ecc 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,7 +57,7 @@ extension Extendable where Base: Layout.Compositional { spacing: ListSpacing = .default, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground + decoration: DecorationStyle? = nil ) -> Base { Base { _, environment in Layout.Section.rak.list( @@ -73,7 +73,7 @@ extension Extendable where Base: Layout.Compositional { public static func list( header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = .whiteBackground, + decoration: DecorationStyle? = nil, edgeInsets: SectionEdgeInsets ) -> Base { Base { _, environment in @@ -112,7 +112,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 { From ac45fb15d31a9a362c49d9de9eebf080664e6881 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Sat, 13 Jul 2024 22:44:54 +0800 Subject: [PATCH 5/6] feat: Add `configuration` parameter to `Layout.Compositional` extension method --- .../Layout/LayoutImplement/Layout+Custom.swift | 8 ++++++-- .../Layout/LayoutImplement/Layout+Flow.swift | 8 ++++++-- .../Layout/LayoutImplement/Layout+List.swift | 16 ++++++++++++---- .../CollectionView/Layout/Model/Layout.swift | 6 +++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift index 47aec56..2c36b8d 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Custom.swift @@ -41,9 +41,10 @@ extension Extendable where Base: Layout.Compositional { style: Layout.Style, supplementaryItems: [SupplementaryItem] = [], decoration: DecorationStyle? = nil, - edgeInsets: SectionEdgeInsets? = nil + edgeInsets: SectionEdgeInsets? = nil, + configuration: Layout.CompositionalConfiguration? = nil ) -> Base { - Base { _, environment in + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.custom( layoutEnvironment: environment, style: style, @@ -52,6 +53,9 @@ extension Extendable where Base: Layout.Compositional { edgeInsets: edgeInsets ) } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } } diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift index 1340d54..975d5df 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+Flow.swift @@ -51,9 +51,10 @@ extension Extendable where Base: Layout.Compositional { header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, decoration: DecorationStyle? = nil, - edgeInsets: SectionEdgeInsets? = nil + edgeInsets: SectionEdgeInsets? = nil, + configuration: Layout.CompositionalConfiguration? = nil ) -> Base { - Base { _, environment in + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.flow( layoutEnvironment: environment, itemSize: itemSize, @@ -65,6 +66,9 @@ extension Extendable where Base: Layout.Compositional { edgeInsets: edgeInsets ) } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } } diff --git a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift index d780ecc..3f178e1 100644 --- a/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift +++ b/Sources/Epoxy/CollectionView/Layout/LayoutImplement/Layout+List.swift @@ -57,9 +57,10 @@ extension Extendable where Base: Layout.Compositional { spacing: ListSpacing = .default, header: SupplementaryItem.Style? = nil, footer: SupplementaryItem.Style? = nil, - decoration: DecorationStyle? = nil + decoration: DecorationStyle? = nil, + configuration: Layout.CompositionalConfiguration? = nil ) -> Base { - Base { _, environment in + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.list( layoutEnvironment: environment, spacing: spacing, @@ -68,15 +69,19 @@ extension Extendable where Base: Layout.Compositional { decoration: decoration ) } + + 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? = nil, - edgeInsets: SectionEdgeInsets + edgeInsets: SectionEdgeInsets, + configuration: Layout.CompositionalConfiguration? = nil ) -> Base { - Base { _, environment in + let sectionProvider: Layout.CompositionalSectionProvider = { _, environment in Layout.Section.rak.list( layoutEnvironment: environment, header: header, @@ -85,6 +90,9 @@ extension Extendable where Base: Layout.Compositional { edgeInsets: edgeInsets ) } + + guard let configuration else { return .init(sectionProvider: sectionProvider) } + return .init(sectionProvider: sectionProvider, configuration: configuration) } } 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 From df9703eda243c99a3708beb126f9387a4ace6c45 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Sat, 13 Jul 2024 22:46:57 +0800 Subject: [PATCH 6/6] feat: Update --- Sources/Epoxy/CollectionView/Tools/SectionEdgeInsets.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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