Skip to content

Commit

Permalink
refactor protocol position for delegates
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 13, 2020
1 parent c3e239e commit 92ea79e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions GHFollowers/Components/Labels/GFBodyLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class GFBodyLabel: UILabel {
private func configure () {
textColor = .secondaryLabel
font = UIFont.preferredFont(forTextStyle: .body)
// For dynamic type text
adjustsFontForContentSizeCategory = true
adjustsFontSizeToFitWidth = true
minimumScaleFactor = 0.75
lineBreakMode = .byWordWrapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class GFUserInfoheaderVC: UIViewController {
bioLabel.topAnchor.constraint(equalTo: avatarImageView.bottomAnchor, constant: textImagePadding),
bioLabel.leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor),
bioLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor),
bioLabel.heightAnchor.constraint(equalToConstant: 60)
bioLabel.heightAnchor.constraint(equalToConstant: 90)
])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

import UIKit

// setup the protocol for the delegate
// use :class to be able to set a weak link in memory
protocol ItemInfoVCDelegate: class {
func didTapGithubProfile(for user: User)
func didTapGetFollowers(for user: User)
}


class GFItemInfoVC: UIViewController {

let stackView = UIStackView()
Expand All @@ -19,7 +27,7 @@ class GFItemInfoVC: UIViewController {

// delegate variables need to be weak
// to avoid memory leaks
weak var delegate: UserInfoVCDelegate!
weak var delegate: ItemInfoVCDelegate!


// create a custom initializer
Expand Down
8 changes: 1 addition & 7 deletions GHFollowers/Screens/FollowerListVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import UIKit



protocol FollowerListVCDelegate: class {
func didRequestFollowers(for username: String)
}



class FollowerListVC: GFDataLoadingVC {

// enums are hashable by default
Expand Down Expand Up @@ -317,7 +311,7 @@ extension FollowerListVC: UISearchResultsUpdating {


// MARK: Delegate
extension FollowerListVC: FollowerListVCDelegate {
extension FollowerListVC: UserInfoVCDelegate {
func didRequestFollowers(for username: String) {
// get followers for new user
self.username = username
Expand Down
11 changes: 4 additions & 7 deletions GHFollowers/Screens/UserInfoVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

import UIKit

// setup the protocol for the delegate
// use :class to be able to set a weak link in memory
protocol UserInfoVCDelegate: class {
func didTapGithubProfile(for user: User)
func didTapGetFollowers(for user: User)
func didRequestFollowers(for username: String)
}


Expand All @@ -27,7 +24,7 @@ class UserInfoVC: UIViewController {
// username gets passed here from FollowerListVC from function -- extension FollowerListVC: UICollectionViewDelegate --
var username: String!

weak var delegate: FollowerListVCDelegate!
weak var delegate: UserInfoVCDelegate!

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -104,7 +101,7 @@ class UserInfoVC: UIViewController {

NSLayoutConstraint.activate([
headerView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
headerView.heightAnchor.constraint(equalToConstant: 180),
headerView.heightAnchor.constraint(equalToConstant: 210),

itemViewOne.topAnchor.constraint(equalTo: headerView.bottomAnchor, constant: padding),
itemViewOne.heightAnchor.constraint(equalToConstant: 140),
Expand Down Expand Up @@ -133,7 +130,7 @@ class UserInfoVC: UIViewController {
// we set the ItemInfoVC as the delegate

// Conform to the protocol
extension UserInfoVC: UserInfoVCDelegate {
extension UserInfoVC: ItemInfoVCDelegate {
// this function is called in the GFRepoItemVC
func didTapGithubProfile(for user: User) {
// show safari view controller
Expand Down

0 comments on commit 92ea79e

Please sign in to comment.