diff --git a/KarrotListKit.podspec b/KarrotListKit.podspec index ac7942f..84f3032 100644 --- a/KarrotListKit.podspec +++ b/KarrotListKit.podspec @@ -12,5 +12,4 @@ Pod::Spec.new do |spec| spec.source_files = 'Sources/**/*.{swift,h,m}' spec.dependency 'DifferenceKit', '~> 1.0' - spec.dependency 'Then', '~> 3.0' end diff --git a/Package.resolved b/Package.resolved index 9946467..ddad5ed 100644 --- a/Package.resolved +++ b/Package.resolved @@ -9,15 +9,6 @@ "revision": "073b9671ce2b9b5b96398611427a1f929927e428", "version": "1.3.0" } - }, - { - "package": "Then", - "repositoryURL": "https://github.com/devxoul/Then.git", - "state": { - "branch": null, - "revision": "d41ef523faef0f911369f79c0b96815d9dbb6d7a", - "version": "3.0.0" - } } ] }, diff --git a/Package.swift b/Package.swift index b48a413..308bbef 100644 --- a/Package.swift +++ b/Package.swift @@ -17,17 +17,12 @@ let package = Package( url: "https://github.com/ra1028/DifferenceKit.git", .upToNextMajor(from: "1.0.0") ), - .package( - url: "https://github.com/devxoul/Then.git", - .upToNextMajor(from: "3.0.0") - ), ], targets: [ .target( name: "KarrotListKit", dependencies: [ "DifferenceKit", - "Then", ] ), .testTarget( diff --git a/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift b/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift index 5e5b4f2..71dc692 100644 --- a/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift +++ b/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift @@ -45,14 +45,16 @@ final public class CollectionViewAdapter: NSObject { var list: List? - private lazy var pullToRefreshControl = UIRefreshControl().then { - $0.tintColor = configuration.refreshControl.tintColor - $0.addTarget( + private lazy var pullToRefreshControl: UIRefreshControl = { + let refreshControl = UIRefreshControl() + refreshControl.tintColor = configuration.refreshControl.tintColor + refreshControl.addTarget( self, action: #selector(pullToRefresh), for: .valueChanged ) - } + return refreshControl + }() // MARK: - Initializer diff --git a/Sources/KarrotListKit/Layout/HorizontalLayout.swift b/Sources/KarrotListKit/Layout/HorizontalLayout.swift index bfa23e9..d3025d4 100644 --- a/Sources/KarrotListKit/Layout/HorizontalLayout.swift +++ b/Sources/KarrotListKit/Layout/HorizontalLayout.swift @@ -38,34 +38,37 @@ public struct HorizontalLayout: CompositionalLayoutSectionFactory { heightDimension: .estimated(context.environment.container.contentSize.height) ), subitems: layoutCellItems(cells: context.section.cells, sizeStorage: context.sizeStorage) - ).then { - $0.interItemSpacing = .fixed(spacing) + ) + group.interItemSpacing = .fixed(spacing) + + + let section = NSCollectionLayoutSection(group: group) + if let sectionInsets { + section.contentInsets = sectionInsets } - return NSCollectionLayoutSection(group: group).then { - if let sectionInsets = sectionInsets { - $0.contentInsets = sectionInsets - } - - if let visibleItemsInvalidationHandler { - $0.visibleItemsInvalidationHandler = visibleItemsInvalidationHandler - } - - $0.orthogonalScrollingBehavior = scrollingBehavior - - $0.boundarySupplementaryItems = [ - layoutHeaderItem(section: context.section, sizeStorage: context.sizeStorage)?.then { - if let headerPinToVisibleBounds { - $0.pinToVisibleBounds = headerPinToVisibleBounds - } - }, - layoutFooterItem(section: context.section, sizeStorage: context.sizeStorage)?.then { - if let footerPinToVisibleBounds { - $0.pinToVisibleBounds = footerPinToVisibleBounds - } - }, - ].compactMap { $0 } + if let visibleItemsInvalidationHandler { + section.visibleItemsInvalidationHandler = visibleItemsInvalidationHandler + } + + section.orthogonalScrollingBehavior = scrollingBehavior + + let headerItem = layoutHeaderItem(section: context.section, sizeStorage: context.sizeStorage) + if let headerPinToVisibleBounds { + headerItem?.pinToVisibleBounds = headerPinToVisibleBounds } + + let footerItem = layoutFooterItem(section: context.section, sizeStorage: context.sizeStorage) + if let footerPinToVisibleBounds { + footerItem?.pinToVisibleBounds = footerPinToVisibleBounds + } + + section.boundarySupplementaryItems = [ + headerItem, + footerItem, + ].compactMap { $0 } + + return section } } diff --git a/Sources/KarrotListKit/Layout/VerticalGridLayout.swift b/Sources/KarrotListKit/Layout/VerticalGridLayout.swift index 8cc3454..975e19c 100644 --- a/Sources/KarrotListKit/Layout/VerticalGridLayout.swift +++ b/Sources/KarrotListKit/Layout/VerticalGridLayout.swift @@ -45,7 +45,7 @@ public struct VerticalGridLayout: CompositionalLayoutSectionFactory { verticalGroupHeight += horizontalGroupHeight.dimension - return NSCollectionLayoutGroup.horizontal( + let layoutGroup = NSCollectionLayoutGroup.horizontal( layoutSize: .init( widthDimension: .fractionalWidth(1.0), heightDimension: horizontalGroupHeight @@ -57,9 +57,10 @@ public struct VerticalGridLayout: CompositionalLayoutSectionFactory { ) ), count: numberOfItemsInRow - ).then { - $0.interItemSpacing = .fixed(itemSpacing) - } + ) + layoutGroup.interItemSpacing = .fixed(itemSpacing) + + return layoutGroup } let group = NSCollectionLayoutGroup.vertical( @@ -68,32 +69,34 @@ public struct VerticalGridLayout: CompositionalLayoutSectionFactory { heightDimension: .estimated(verticalGroupHeight) ), subitems: horizontalGroups - ).then { - $0.interItemSpacing = .fixed(lineSpacing) + ) + group.interItemSpacing = .fixed(lineSpacing) + + let section = NSCollectionLayoutSection(group: group) + if let sectionInsets { + section.contentInsets = sectionInsets + } + + if let visibleItemsInvalidationHandler { + section.visibleItemsInvalidationHandler = visibleItemsInvalidationHandler } - return NSCollectionLayoutSection(group: group).then { - if let sectionInsets = sectionInsets { - $0.contentInsets = sectionInsets - } - - if let visibleItemsInvalidationHandler { - $0.visibleItemsInvalidationHandler = visibleItemsInvalidationHandler - } - - $0.boundarySupplementaryItems = [ - layoutHeaderItem(section: context.section, sizeStorage: context.sizeStorage)?.then { - if let headerPinToVisibleBounds { - $0.pinToVisibleBounds = headerPinToVisibleBounds - } - }, - layoutFooterItem(section: context.section, sizeStorage: context.sizeStorage)?.then { - if let footerPinToVisibleBounds { - $0.pinToVisibleBounds = footerPinToVisibleBounds - } - }, - ].compactMap { $0 } + let headerItem = layoutHeaderItem(section: context.section, sizeStorage: context.sizeStorage) + if let headerPinToVisibleBounds { + headerItem?.pinToVisibleBounds = headerPinToVisibleBounds } + + let footerItem = layoutFooterItem(section: context.section, sizeStorage: context.sizeStorage) + if let footerPinToVisibleBounds { + footerItem?.pinToVisibleBounds = footerPinToVisibleBounds + } + + section.boundarySupplementaryItems = [ + headerItem, + footerItem, + ].compactMap { $0 } + + return section } } diff --git a/Sources/KarrotListKit/Layout/VerticalLayout.swift b/Sources/KarrotListKit/Layout/VerticalLayout.swift index 083ba24..394924f 100644 --- a/Sources/KarrotListKit/Layout/VerticalLayout.swift +++ b/Sources/KarrotListKit/Layout/VerticalLayout.swift @@ -31,32 +31,34 @@ public struct VerticalLayout: CompositionalLayoutSectionFactory { heightDimension: .estimated(context.environment.container.contentSize.height) ), subitems: layoutCellItems(cells: context.section.cells, sizeStorage: context.sizeStorage) - ).then { - $0.interItemSpacing = .fixed(spacing) + ) + group.interItemSpacing = .fixed(spacing) + + let section = NSCollectionLayoutSection(group: group) + if let sectionInsets { + section.contentInsets = sectionInsets } - return NSCollectionLayoutSection(group: group).then { - if let sectionInsets = sectionInsets { - $0.contentInsets = sectionInsets - } + if let visibleItemsInvalidationHandler { + section.visibleItemsInvalidationHandler = visibleItemsInvalidationHandler + } - if let visibleItemsInvalidationHandler { - $0.visibleItemsInvalidationHandler = visibleItemsInvalidationHandler - } + let headerItem = layoutHeaderItem(section: context.section, sizeStorage: context.sizeStorage) + if let headerPinToVisibleBounds { + headerItem?.pinToVisibleBounds = headerPinToVisibleBounds + } - $0.boundarySupplementaryItems = [ - layoutHeaderItem(section: context.section, sizeStorage: context.sizeStorage)?.then { - if let headerPinToVisibleBounds { - $0.pinToVisibleBounds = headerPinToVisibleBounds - } - }, - layoutFooterItem(section: context.section, sizeStorage: context.sizeStorage)?.then { - if let footerPinToVisibleBounds { - $0.pinToVisibleBounds = footerPinToVisibleBounds - } - }, - ].compactMap { $0 } + let footerItem = layoutFooterItem(section: context.section, sizeStorage: context.sizeStorage) + if let footerPinToVisibleBounds { + footerItem?.pinToVisibleBounds = footerPinToVisibleBounds } + + section.boundarySupplementaryItems = [ + headerItem, + footerItem, + ].compactMap { $0 } + + return section } } diff --git a/Sources/KarrotListKit/Section.swift b/Sources/KarrotListKit/Section.swift index 9df63c1..82a347a 100644 --- a/Sources/KarrotListKit/Section.swift +++ b/Sources/KarrotListKit/Section.swift @@ -5,7 +5,6 @@ import UIKit import DifferenceKit -import Then /// The `Section` that representing a UICollectionView Section. /// @@ -14,7 +13,7 @@ import Then /// /// - Note: The layout depends on NSCollectionLayoutSection and /// you must set the layout through the withSectionLayout modifier. -public struct Section: Identifiable, ListingViewEventHandler, Then { +public struct Section: Identifiable, ListingViewEventHandler { /// The identifier for `Section` public let id: AnyHashable diff --git a/Sources/KarrotListKit/View/UICollectionComponentReusableView.swift b/Sources/KarrotListKit/View/UICollectionComponentReusableView.swift index f5c884e..d6a8369 100644 --- a/Sources/KarrotListKit/View/UICollectionComponentReusableView.swift +++ b/Sources/KarrotListKit/View/UICollectionComponentReusableView.swift @@ -44,8 +44,8 @@ final class UICollectionComponentReusableView: UICollectionReusableView, Compone onSizeChanged?(size) } - return attributes.with { - $0.frame.size = size - } + attributes.frame.size = size + + return attributes } } diff --git a/Sources/KarrotListKit/View/UICollectionViewComponentCell.swift b/Sources/KarrotListKit/View/UICollectionViewComponentCell.swift index 8c79be4..10840da 100644 --- a/Sources/KarrotListKit/View/UICollectionViewComponentCell.swift +++ b/Sources/KarrotListKit/View/UICollectionViewComponentCell.swift @@ -58,8 +58,8 @@ public final class UICollectionViewComponentCell: UICollectionViewCell, Componen onSizeChanged?(size) } - return attributes.with { - $0.frame.size = size - } + attributes.frame.size = size + + return attributes } } diff --git a/Tests/KarrotListKitTests/CollectionViewAdapterTests.swift b/Tests/KarrotListKitTests/CollectionViewAdapterTests.swift index a6a5610..bfb5476 100644 --- a/Tests/KarrotListKitTests/CollectionViewAdapterTests.swift +++ b/Tests/KarrotListKitTests/CollectionViewAdapterTests.swift @@ -234,20 +234,18 @@ extension CollectionViewAdapterTests { @MainActor func test_given_applied_list_when_apply_then_update() async { // given - let expectation = XCTestExpectation().then { - $0.expectedFulfillmentCount = 1 - } - let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()).then { - $0.performBatchUpdatesHandler = { updates, completion in - updates?() - completion?(true) - } + let expectation = XCTestExpectation() + expectation.expectedFulfillmentCount = 1 + + let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) + collectionView.performBatchUpdatesHandler = { updates, completion in + updates?() + completion?(true) } - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID()) { - Cell(id: UUID(), component: DummyComponent()) - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID()) { + Cell(id: UUID(), component: DummyComponent()) } } @@ -285,17 +283,17 @@ extension CollectionViewAdapterTests { @MainActor func test_when_multiple_async_apply_then_safe_update() async { // given - let expectation = XCTestExpectation().then { - $0.expectedFulfillmentCount = 1 - } - let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()).then { - $0.performBatchUpdatesHandler = { updates, completion in - updates?() - DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { - completion?(true) - } + let expectation = XCTestExpectation() + expectation.expectedFulfillmentCount = 1 + + let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) + collectionView.performBatchUpdatesHandler = { updates, completion in + updates?() + DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { + completion?(true) } } + let sut = sut(collectionView: collectionView) // when @@ -428,17 +426,15 @@ extension CollectionViewAdapterTests { var eventContext: DidSelectEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID()) { - Cell(id: UUID(), component: component) - .didSelect { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID()) { + Cell(id: UUID(), component: component) + .didSelect { context in + eventContext = context + } } } - _ = sut // when collectionView @@ -457,17 +453,15 @@ extension CollectionViewAdapterTests { var eventContext: WillDisplayEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID()) { - Cell(id: UUID(), component: component) - .willDisplay { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID()) { + Cell(id: UUID(), component: component) + .willDisplay { context in + eventContext = context + } } } - _ = sut // when collectionView @@ -489,17 +483,15 @@ extension CollectionViewAdapterTests { var eventContext: DidEndDisplayingEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID()) { - Cell(id: UUID(), component: component) - .didEndDisplay { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID()) { + Cell(id: UUID(), component: component) + .didEndDisplay { context in + eventContext = context + } } } - _ = sut // when collectionView @@ -521,16 +513,14 @@ extension CollectionViewAdapterTests { var eventContext: WillDisplayEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID(), cells: []) - .withHeader(component) - .willDisplayHeader { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID(), cells: []) + .withHeader(component) + .willDisplayHeader { context in + eventContext = context + } } - _ = sut // when collectionView @@ -553,16 +543,14 @@ extension CollectionViewAdapterTests { var eventContext: WillDisplayEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID(), cells: []) - .withFooter(component) - .willDisplayFooter { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID(), cells: []) + .withFooter(component) + .willDisplayFooter { context in + eventContext = context + } } - _ = sut // when collectionView @@ -585,16 +573,14 @@ extension CollectionViewAdapterTests { var eventContext: DidEndDisplayingEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID(), cells: []) - .withHeader(component) - .didEndDisplayHeader { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID(), cells: []) + .withHeader(component) + .didEndDisplayHeader { context in + eventContext = context + } } - _ = sut // when collectionView @@ -617,16 +603,14 @@ extension CollectionViewAdapterTests { var eventContext: DidEndDisplayingEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) let component = DummyComponent() - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID(), cells: []) - .withFooter(component) - .didEndDisplayFooter { context in - eventContext = context - } - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID(), cells: []) + .withFooter(component) + .didEndDisplayFooter { context in + eventContext = context + } } - _ = sut // when collectionView @@ -653,14 +637,12 @@ extension CollectionViewAdapterTests { // given var eventContext: DidScrollEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.list = List( - sections: [] - ).didScroll { context in - eventContext = context - } + let sut = sut(collectionView: collectionView) + sut.list = List( + sections: [] + ).didScroll { context in + eventContext = context } - _ = sut // when collectionView @@ -677,14 +659,12 @@ extension CollectionViewAdapterTests { // given var eventContext: WillBeginDraggingEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.list = List( - sections: [] - ).willBeginDragging { context in - eventContext = context - } + let sut = sut(collectionView: collectionView) + sut.list = List( + sections: [] + ).willBeginDragging { context in + eventContext = context } - _ = sut // when collectionView @@ -701,14 +681,12 @@ extension CollectionViewAdapterTests { // given var eventContext: WillEndDraggingEvent.EventContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.list = List( - sections: [] - ).willEndDragging { context in - eventContext = context - } + let sut = sut(collectionView: collectionView) + sut.list = List( + sections: [] + ).willEndDragging { context in + eventContext = context } - _ = sut // when let velocity = CGPoint(x: 0, y: 100) @@ -734,14 +712,12 @@ extension CollectionViewAdapterTests { let sut = sut( configuration: .init(refreshControl: .enabled(tintColor: .clear)), collectionView: collectionView - ).then { - $0.list = List( - sections: [] - ).onRefresh { context in - eventContext = context - } + ) + sut.list = List( + sections: [] + ).onRefresh { context in + eventContext = context } - _ = sut // when collectionView @@ -778,18 +754,17 @@ extension CollectionViewAdapterTests { let sut = sut( collectionView: collectionView, prefetchingPlugins: [prefetchingPlugin] - ).then { - // given: applied list - $0.apply( - List { - Section(id: UUID()) { - Cell( - id: UUID(), component: DummyComponent() - ) - } + ) + // given: applied list + sut.apply( + List { + Section(id: UUID()) { + Cell( + id: UUID(), component: DummyComponent() + ) } - ) - } + } + ) // when collectionView @@ -818,18 +793,18 @@ extension CollectionViewAdapterTests { let sut = sut( collectionView: collectionView, prefetchingPlugins: [prefetchingPlugin] - ).then { - // given: applied list - $0.apply( - List { - Section(id: UUID()) { - Cell( - id: UUID(), component: DummyComponent() - ) - } + ) + // given: applied list + sut.apply( + List { + Section(id: UUID()) { + Cell( + id: UUID(), component: DummyComponent() + ) } - ) - } + } + ) + // given: creating prefetchingOperation collectionView .prefetchDataSource? @@ -862,16 +837,16 @@ extension CollectionViewAdapterTests { let sut = sut( collectionView: collectionView, prefetchingPlugins: [prefetchingPlugin] - ).then { - // given: applied list - $0.apply(List { - Section(id: UUID()) { - Cell( - id: UUID(), component: DummyComponent() - ) - } - }) - } + ) + // given: applied list + sut.apply(List { + Section(id: UUID()) { + Cell( + id: UUID(), component: DummyComponent() + ) + } + }) + // given: creating prefetchingOperation collectionView .prefetchDataSource? @@ -903,16 +878,14 @@ extension CollectionViewAdapterTests { // given let cellCount = 100 let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.list = List { - Section(id: UUID()) { - (0 ..< cellCount).map { - Cell(id: "\($0)", component: DummyComponent()) - } + let sut = sut(collectionView: collectionView) + sut.list = List { + Section(id: UUID()) { + (0 ..< cellCount).map { + Cell(id: "\($0)", component: DummyComponent()) } } } - _ = sut // when let numberOfItems = collectionView @@ -930,14 +903,12 @@ extension CollectionViewAdapterTests { // given let sectionCount = 100 let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.list = List { - (0 ..< 100).map { - Section(id: "\($0)", cells: []) - } + let sut = sut(collectionView: collectionView) + sut.list = List { + (0 ..< 100).map { + Section(id: "\($0)", cells: []) } } - _ = sut // when let numberOfSections = collectionView @@ -952,16 +923,14 @@ extension CollectionViewAdapterTests { // given let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) let component = ComponentSpy() - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: UUID()) { - [Cell(id: UUID(), component: component)] - } + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: UUID()) { + [Cell(id: UUID(), component: component)] } - ) - } - _ = sut + } + ) // when _ = collectionView @@ -979,15 +948,13 @@ extension CollectionViewAdapterTests { // given let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) let component = ComponentSpy() - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: UUID(), cells: []) - .withHeader(component) - } - ) - } - _ = sut + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: UUID(), cells: []) + .withHeader(component) + } + ) // when _ = collectionView @@ -1006,15 +973,13 @@ extension CollectionViewAdapterTests { // given let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) let component = ComponentSpy() - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: UUID(), cells: []) - .withFooter(component) - } - ) - } - _ = sut + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: UUID(), cells: []) + .withFooter(component) + } + ) // when _ = collectionView @@ -1040,18 +1005,17 @@ extension CollectionViewAdapterTests { let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) var component = ComponentStub() component.viewModelStub = .init() - component.contentStub = ViewStub().then { - $0.sizeThatFitsStub = CGSize(width: 44.0, height: 44.0) - } - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: UUID()) { - Cell(id: cellID, component: component) - } + let viewStub = ViewStub() + viewStub.sizeThatFitsStub = CGSize(width: 44.0, height: 44.0) + component.contentStub = viewStub + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: UUID()) { + Cell(id: cellID, component: component) } - ) - } + } + ) let cell = collectionView .dataSource? @@ -1078,17 +1042,16 @@ extension CollectionViewAdapterTests { let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) var component = ComponentStub() component.viewModelStub = .init() - component.contentStub = ViewStub().then { - $0.sizeThatFitsStub = CGSize(width: 44.0, height: 44.0) - } - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: sectionID, cells: []) - .withHeader(component) - } - ) - } + let viewStub = ViewStub() + viewStub.sizeThatFitsStub = CGSize(width: 44.0, height: 44.0) + component.contentStub = viewStub + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: sectionID, cells: []) + .withHeader(component) + } + ) let header = collectionView .dataSource? @@ -1116,17 +1079,16 @@ extension CollectionViewAdapterTests { let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) var component = ComponentStub() component.viewModelStub = .init() - component.contentStub = ViewStub().then { - $0.sizeThatFitsStub = CGSize(width: 44.0, height: 44.0) - } - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: sectionID, cells: []) - .withFooter(component) - } - ) - } + let viewStub = ViewStub() + viewStub.sizeThatFitsStub = CGSize(width: 44.0, height: 44.0) + component.contentStub = viewStub + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: sectionID, cells: []) + .withFooter(component) + } + ) let header = collectionView .dataSource? .collectionView?( @@ -1157,10 +1119,9 @@ extension CollectionViewAdapterTests { let numberOfCells = 100 let threshold = 10 var nextBatchContext: NextBatchContext! - let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()).then { - $0.indexPathsForVisibleItemsHandler = { - [IndexPath(item: numberOfCells - threshold - 1, section: 0)] - } + let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) + collectionView.indexPathsForVisibleItemsHandler = { + [IndexPath(item: numberOfCells - threshold - 1, section: 0)] } let sut = sut(collectionView: collectionView) @@ -1191,10 +1152,9 @@ extension CollectionViewAdapterTests { let numberOfCells = 100 let threshold = 10 var nextBatchContext: NextBatchContext! - let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()).then { - $0.indexPathsForVisibleItemsHandler = { - [IndexPath(item: numberOfCells - threshold, section: 0)] - } + let collectionView = CollectionViewMock(layoutAdapter: CollectionViewLayoutAdapter()) + collectionView.indexPathsForVisibleItemsHandler = { + [IndexPath(item: numberOfCells - threshold, section: 0)] } let sut = sut(collectionView: collectionView) @@ -1226,25 +1186,23 @@ extension CollectionViewAdapterTests { let threshold = 10 var nextBatchContext: NextBatchContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: UUID()) { - (0 ..< numberOfCells).map { _ in - Cell(id: UUID(), component: DummyComponent()) - } + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: UUID()) { + (0 ..< numberOfCells).map { _ in + Cell(id: UUID(), component: DummyComponent()) } - .withNextBatchTrigger(NextBatchTrigger( - threshold: threshold, - context: .init(), - handler: { context in - nextBatchContext = context - } - )) } - ) - } - _ = sut + .withNextBatchTrigger(NextBatchTrigger( + threshold: threshold, + context: .init(), + handler: { context in + nextBatchContext = context + } + )) + } + ) // when collectionView @@ -1267,25 +1225,23 @@ extension CollectionViewAdapterTests { let threshold = 10 var nextBatchContext: NextBatchContext! let collectionView = UICollectionView(layoutAdapter: CollectionViewLayoutAdapter()) - let sut = sut(collectionView: collectionView).then { - $0.apply( - List { - Section(id: UUID()) { - (0 ..< numberOfCells).map { _ in - Cell(id: UUID(), component: DummyComponent()) - } + let sut = sut(collectionView: collectionView) + sut.apply( + List { + Section(id: UUID()) { + (0 ..< numberOfCells).map { _ in + Cell(id: UUID(), component: DummyComponent()) } - .withNextBatchTrigger(NextBatchTrigger( - threshold: threshold, - context: .init(), - handler: { context in - nextBatchContext = context - } - )) } - ) - } - _ = sut + .withNextBatchTrigger(NextBatchTrigger( + threshold: threshold, + context: .init(), + handler: { context in + nextBatchContext = context + } + )) + } + ) // when collectionView