Skip to content

Commit

Permalink
userInfo modal, navigationBar
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Mar 29, 2020
1 parent c895c85 commit 80450ed
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
4 changes: 4 additions & 0 deletions GHFollowers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
7DA45F71242BC5C100AB426F /* GFAvatarImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA45F70242BC5C100AB426F /* GFAvatarImageView.swift */; };
7DA45F73242E332000AB426F /* UIHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA45F72242E332000AB426F /* UIHelper.swift */; };
7DA45F7A242FB95700AB426F /* GFEmptyStateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA45F79242FB95700AB426F /* GFEmptyStateView.swift */; };
7DA45F7C2430E3C900AB426F /* UserInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA45F7B2430E3C900AB426F /* UserInfoVC.swift */; };
7DFAC88A242A86D200F5780C /* GFAlertContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -55,6 +56,7 @@
7DA45F70242BC5C100AB426F /* GFAvatarImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFAvatarImageView.swift; sourceTree = "<group>"; };
7DA45F72242E332000AB426F /* UIHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIHelper.swift; sourceTree = "<group>"; };
7DA45F79242FB95700AB426F /* GFEmptyStateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFEmptyStateView.swift; sourceTree = "<group>"; };
7DA45F7B2430E3C900AB426F /* UserInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfoVC.swift; sourceTree = "<group>"; };
7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFAlertContainerView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -107,6 +109,7 @@
7D98BB3B24290771006C53E9 /* SearchVC.swift */,
7D98BB3D242907BB006C53E9 /* FavoriteListVC.swift */,
7D98BB43242A29B4006C53E9 /* FollowerListVC.swift */,
7DA45F7B2430E3C900AB426F /* UserInfoVC.swift */,
);
path = Screens;
sourceTree = "<group>";
Expand Down Expand Up @@ -300,6 +303,7 @@
7DA45F6F242BC47D00AB426F /* FollowerCell.swift in Sources */,
7DA45F71242BC5C100AB426F /* GFAvatarImageView.swift in Sources */,
7D98BB48242A5507006C53E9 /* GFBodyLabel.swift in Sources */,
7DA45F7C2430E3C900AB426F /* UserInfoVC.swift in Sources */,
7DA45F64242B73E600AB426F /* Follower.swift in Sources */,
7D98BB46242A52B7006C53E9 /* GFTitleLabel.swift in Sources */,
7D98BB4C242A7327006C53E9 /* UIViewController+EXT.swift in Sources */,
Expand Down
Binary file not shown.
36 changes: 30 additions & 6 deletions GHFollowers/Screens/FollowerListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FollowerListVC: UIViewController {

var page = 1
var hasMoreFollowers = true
var isSearching = false

// takes 2 generic paraeters
// both of them need to conform to hashable
Expand Down Expand Up @@ -93,7 +94,9 @@ class FollowerListVC: UIViewController {
// the items array that needs to check for changes
snapshot.appendItems(followers)
// applay the snapshots to the dataSource
dataSource.apply(snapshot, animatingDifferences: true)
DispatchQueue.main.async {
self.dataSource.apply(snapshot, animatingDifferences: true)
}
}


Expand Down Expand Up @@ -189,10 +192,25 @@ extension FollowerListVC: UICollectionViewDelegate {
page += 1
getFollowers(username: username, page: page)
}



}


// get the exact tapped item from the collection
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// get the right array to use first
let activeArray = isSearching ? filteredFollowers : followers
//get the index of the tapped item
let follower = activeArray[indexPath.item]

// Navigate to modal
let userInfoVC = UserInfoVC()
// pass the username to the modal to use at the user api call
userInfoVC.username = follower.login
// we put the modal inside a NavController so we could have the navigation buttons in the modal
let navController = UINavigationController(rootViewController: userInfoVC)
present(navController, animated: true)
}

}


Expand All @@ -202,9 +220,11 @@ extension FollowerListVC: UISearchResultsUpdating, UISearchBarDelegate {
// this informs the VC every time the search results are changed
func updateSearchResults(for searchController: UISearchController) {


guard let filter = searchController.searchBar.text, !filter.isEmpty else {return}

//set the switch on
isSearching = true

// get each item of the followers array
// check if contains the text from the searchBar
// append the return to the filteredFollowers array
Expand All @@ -216,9 +236,13 @@ extension FollowerListVC: UISearchResultsUpdating, UISearchBarDelegate {
updateData(on: filteredFollowers)
}


// when cancel button is tapped update the collection View using the original follwers array
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
updateData(on: followers)
//set the switch on
isSearching = false

updateData(on: followers)
}


Expand Down
32 changes: 32 additions & 0 deletions GHFollowers/Screens/UserInfoVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// UserInfoVC.swift
// GHFollowers
//
// Created by Vasileios Gkreen on 29/03/2020.
// Copyright © 2020 Vasileios Gkreen. All rights reserved.
//

import UIKit

class UserInfoVC: UIViewController {

// username gets passed here from FollowerListVC from function -- extension FollowerListVC: UICollectionViewDelegate --
var username: String!

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .systemBackground
// create done button for navigation
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissVC))
// add button to navigation bar
navigationItem.rightBarButtonItem = doneButton
print(username!)
}

@objc func dismissVC() {
dismiss(animated: true)
}


}

0 comments on commit 80450ed

Please sign in to comment.