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..f79b6d2 100644 --- a/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift +++ b/Sources/KarrotListKit/Adapter/CollectionViewAdapterConfiguration.swift @@ -5,19 +5,46 @@ import UIKit public struct CollectionViewAdapterConfiguration { - public let pullToRefreshEnabled: Bool - public let batchUpdateInterruptCount: Int + /// CollectionView 의 RefreshControl 구성 + /// + /// 기본값은 `.disabled()` 입니다. + public let refreshControl: RefreshControl - public let refreshControlTintColor: UIColor? + /// changeSet 이 `batchUpdateInterruptCount` 수를 넘기면 + /// `UICollectionView` 가 animated updates 가 아닌 reloadData 로 동작합니다. + /// + /// 기본값은 `100` 입니다. + public let batchUpdateInterruptCount: Int 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 { + + /// RefreshControl 적용 여부 + public let isEnabled: Bool + + /// RefreshControl 의 tintColor + 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) + } } }