Skip to content

Commit

Permalink
Add a default ProfileViewDelegate conformance to `ProfileViewContro…
Browse files Browse the repository at this point in the history
…ller (#561)
  • Loading branch information
pinarol authored Nov 19, 2024
2 parents eca6d9f + 8f0175f commit 8cdc67c
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Combine
import Gravatar
import SafariServices
import UIKit

/// A view controller which displays a Profile View.
Expand Down Expand Up @@ -32,6 +33,12 @@ public class ProfileViewController: UIViewController {
self.configuration = configuration
self.profileIdentifier = profileIdentifier
super.init(nibName: nil, bundle: nil)
if configuration.delegate == nil {
// Set delegate to `self` if no delegate was set.
var newConfig = configuration
newConfig.delegate = self
self.configuration = newConfig
}
}

override public func viewDidLoad() {
Expand Down Expand Up @@ -103,3 +110,22 @@ public class ProfileViewController: UIViewController {
view.backgroundColor = paletteType.palette.background.primary
}
}

extension ProfileViewController: ProfileViewDelegate {
public func profileView(_ view: BaseProfileView, didTapOnAvatarWithID avatarID: Gravatar.AvatarIdentifier?) {
// No op.
}

public func profileView(_ view: BaseProfileView, didTapOnProfileButtonWithStyle style: ProfileButtonStyle, profileURL: URL?) {
guard let profileURL else { return }
let safari = SFSafariViewController(url: profileURL)
present(safari, animated: true)
}

public func profileView(_ view: BaseProfileView, didTapOnAccountButtonWithModel accountModel: AccountModel) {
guard let accountURL = accountModel.accountURL else { return }
let safari = SFSafariViewController(url: accountURL)

present(safari, animated: true)
}
}

0 comments on commit 8cdc67c

Please sign in to comment.