From cdb56c065ae1df33254831b856810b3cbd1d9363 Mon Sep 17 00:00:00 2001 From: OhKanghoon Date: Mon, 5 Feb 2024 15:14:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20RefreshControl=20Configuration?= =?UTF-8?q?=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Adapter/CollectionViewAdapter.swift | 8 ++--- .../CollectionViewAdapterConfiguration.swift | 32 ++++++++++++++----- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift b/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift index 157a549..04c3f27 100644 --- a/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift +++ b/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift @@ -31,9 +31,7 @@ final public class CollectionViewAdapter: NSObject { private var list: List? private lazy var pullToRefreshControl = UIRefreshControl().then { - if let refreshControlTintColor = configuration.refreshControlTintColor { - $0.tintColor = refreshControlTintColor - } + $0.tintColor = configuration.refreshControl.tintColor $0.addTarget( self, action: #selector(pullToRefresh), @@ -44,7 +42,7 @@ final public class CollectionViewAdapter: NSObject { // MARK: - Initializer public init( - configuration: CollectionViewAdapterConfiguration = .init(), + configuration: CollectionViewAdapterConfiguration, collectionView: UICollectionView, layoutAdapter: CollectionViewLayoutAdaptable, prefetchingPlugins: [CollectionViewPrefetchingPlugin] = [] @@ -63,7 +61,7 @@ final public class CollectionViewAdapter: NSObject { collectionView.prefetchDataSource = self } - if configuration.pullToRefreshEnabled { + if configuration.refreshControl.isEnabled { collectionView.refreshControl = pullToRefreshControl } } diff --git a/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift b/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift index 2e6ec86..3ca1507 100644 --- a/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift +++ b/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift @@ -5,19 +5,35 @@ import UIKit public struct CollectionViewAdapterConfiguration { - public let pullToRefreshEnabled: Bool + public let refreshControl: RefreshControl public let batchUpdateInterruptCount: Int - public let refreshControlTintColor: UIColor? - public init( - pullToRefreshEnabled: Bool = false, - batchUpdateInterruptCount: Int = 100, - refreshControlTintColor: UIColor? = nil + refreshControl: RefreshControl = .disabled(), + batchUpdateInterruptCount: Int = 100 ) { - self.pullToRefreshEnabled = pullToRefreshEnabled + self.refreshControl = refreshControl self.batchUpdateInterruptCount = batchUpdateInterruptCount - self.refreshControlTintColor = refreshControlTintColor + } +} + + +// MARK: - RefreshControl + +extension CollectionViewAdapterConfiguration { + + public struct RefreshControl { + + public let isEnabled: Bool + public let tintColor: UIColor + + public static func enabled(tintColor: UIColor) -> RefreshControl { + .init(isEnabled: true, tintColor: tintColor) + } + + public static func disabled() -> RefreshControl { + .init(isEnabled: false, tintColor: .clear) + } } } From 2d1c530792e8d14c56f4b76f489b117a1e92239d Mon Sep 17 00:00:00 2001 From: OhKanghoon Date: Mon, 5 Feb 2024 15:25:19 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20Configuration=20=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Adapter/CollectionViewAdapterConfiguration.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift b/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift index 3ca1507..f79b6d2 100644 --- a/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift +++ b/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift @@ -6,7 +6,15 @@ import UIKit public struct CollectionViewAdapterConfiguration { + /// CollectionView 의 RefreshControl 구성 + /// + /// 기본값은 `.disabled()` 입니다. public let refreshControl: RefreshControl + + /// changeSet 이 `batchUpdateInterruptCount` 수를 넘기면 + /// `UICollectionView` 가 animated updates 가 아닌 reloadData 로 동작합니다. + /// + /// 기본값은 `100` 입니다. public let batchUpdateInterruptCount: Int public init( @@ -25,7 +33,10 @@ extension CollectionViewAdapterConfiguration { public struct RefreshControl { + /// RefreshControl 적용 여부 public let isEnabled: Bool + + /// RefreshControl 의 tintColor public let tintColor: UIColor public static func enabled(tintColor: UIColor) -> RefreshControl {