Skip to content

Commit

Permalink
Merge pull request #8 from daangn/feature/ray/refresh-control-interface
Browse files Browse the repository at this point in the history
NO-JIRA RefreshControl Configuration 인터페이스를 변경해요
  • Loading branch information
OhKanghoon authored Feb 5, 2024
2 parents 2036570 + 2d1c530 commit 4ccb20f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
8 changes: 3 additions & 5 deletions Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -44,7 +42,7 @@ final public class CollectionViewAdapter: NSObject {
// MARK: - Initializer

public init(
configuration: CollectionViewAdapterConfiguration = .init(),
configuration: CollectionViewAdapterConfiguration,
collectionView: UICollectionView,
layoutAdapter: CollectionViewLayoutAdaptable,
prefetchingPlugins: [CollectionViewPrefetchingPlugin] = []
Expand All @@ -63,7 +61,7 @@ final public class CollectionViewAdapter: NSObject {
collectionView.prefetchDataSource = self
}

if configuration.pullToRefreshEnabled {
if configuration.refreshControl.isEnabled {
collectionView.refreshControl = pullToRefreshControl
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 4ccb20f

Please sign in to comment.