Skip to content

Commit

Permalink
fix load more followers pagination bug
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 13, 2020
1 parent 5a48815 commit a51ea50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Binary file not shown.
5 changes: 4 additions & 1 deletion GHFollowers/Screens/FollowerListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class FollowerListVC: GFDataLoadingVC {
var page = 1
var hasMoreFollowers = true
var isSearching = false
var isLoadingFollowers = false

// takes 2 generic paraeters
// both of them need to conform to hashable
Expand Down Expand Up @@ -188,13 +189,15 @@ class FollowerListVC: GFDataLoadingVC {

// show activity indicator before the network call --- EXTENSIONS FILE ---
showLoadingView()
isLoadingFollowers = true

NetworkManager.shared.getFollowers(for: username, page: page) { [weak self] result in
// instead of adding self?. to all values below use guard for the self
guard let self = self else { return }

// call to dismiss the loading indicator --- EXTENSIONS FILE ---
self.dismissLoadingView()
self.isLoadingFollowers = false

switch result {
case .success(let followers):
Expand Down Expand Up @@ -254,7 +257,7 @@ extension FollowerListVC: UICollectionViewDelegate {
if offsetY > contentHeight - scrollViewHeight {

// if no more followers return
guard hasMoreFollowers else { return }
guard hasMoreFollowers, !isLoadingFollowers else { return }

page += 1
getFollowers(username: username, page: page)
Expand Down

0 comments on commit a51ea50

Please sign in to comment.