Skip to content

Instantly share code, notes, and snippets.

@Abhishek9634
Last active July 23, 2020 19:18
Show Gist options
  • Save Abhishek9634/6371ee3106f6ad074d6026e5f071c9e2 to your computer and use it in GitHub Desktop.
Save Abhishek9634/6371ee3106f6ad074d6026e5f071c9e2 to your computer and use it in GitHub Desktop.
public func delay(_ delay: Double, closure: @escaping () -> Void) {
let deadline = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(
deadline: deadline,
execute: closure
)
}
class ViewController: UIViewController {
..
...
....
private lazy var paginationManager: HorizontalPaginationManager = {
let manager = HorizontalPaginationManager(scrollView: self.collectionView)
manager.delegate = self
return manager
}()
private var isDragging: Bool {
return self.collectionView.isDragging
}
override func viewDidLoad() {
super.viewDidLoad()
self.setupCollectionView()
self.setupPagination()
self.fetchItems()
}
.....
...
}
extension ViewController: HorizontalPaginationManagerDelegate {
private func setupPagination() {
self.paginationManager.refreshViewColor = .clear
self.paginationManager.loaderColor = .white
}
private func fetchItems() {
self.paginationManager.initialLoad()
}
func refreshAll(completion: @escaping (Bool) -> Void) {
delay(2.0) {
self.items = [1, 2, 3, 4, 5]
self.collectionView.reloadData()
completion(true)
}
}
func loadMore(completion: @escaping (Bool) -> Void) {
delay(2.0) {
self.items.append(contentsOf: [6, 7, 8, 9, 10])
self.collectionView.reloadData()
completion(true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment