Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit d50be84

Browse files
committed
Make SiteCredentialsViewController dismissal configurable
1 parent 3d12cc9 commit d50be84

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ import WordPressKit
232232
///
233233
public class func showSiteCredentialLogin(from presenter: UIViewController, siteURL: String, onCompletion: @escaping (WordPressOrgCredentials) -> Void) {
234234
let controller = SiteCredentialsViewController.instantiate(from: .siteAddress) { coder in
235-
SiteCredentialsViewController(coder: coder, onCompletion: onCompletion)
235+
SiteCredentialsViewController(coder: coder, isDismissible: true, onCompletion: onCompletion)
236236
}
237237
guard let controller = controller else {
238238
DDLogError("Failed to navigate from GetStartedViewController to SiteCredentialsViewController")
@@ -242,6 +242,9 @@ import WordPressKit
242242
let loginFields = LoginFields()
243243
loginFields.siteAddress = siteURL
244244
controller.loginFields = loginFields
245+
controller.dismissBlock = { _ in
246+
controller.navigationController?.dismiss(animated: true)
247+
}
245248

246249
let navController = LoginNavigationController(rootViewController: controller)
247250
navController.modalPresentationStyle = .fullScreen

WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteCredentialsViewController.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ final class SiteCredentialsViewController: LoginViewController {
1616
private var errorMessage: String?
1717
private var shouldChangeVoiceOverFocus: Bool = false
1818

19+
private let isDismissible: Bool
1920
private let completionHandler: ((WordPressOrgCredentials) -> Void)?
2021

21-
init?(coder: NSCoder, onCompletion: @escaping (WordPressOrgCredentials) -> Void) {
22+
init?(coder: NSCoder, isDismissible: Bool, onCompletion: @escaping (WordPressOrgCredentials) -> Void) {
23+
self.isDismissible = isDismissible
2224
self.completionHandler = onCompletion
2325
super.init(coder: coder)
2426
}
2527

2628
required init?(coder: NSCoder) {
29+
self.isDismissible = false
2730
self.completionHandler = nil
2831
super.init(coder: coder)
2932
}
@@ -58,8 +61,8 @@ final class SiteCredentialsViewController: LoginViewController {
5861
loginFields.meta.userIsDotCom = false
5962

6063
navigationItem.title = WordPressAuthenticator.shared.displayStrings.logInTitle
61-
if completionHandler != nil {
62-
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .close, target: self, action: #selector(dismissView))
64+
if isDismissible {
65+
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(dismissView))
6366
}
6467
styleNavigationBar(forUnified: true)
6568

@@ -237,7 +240,7 @@ extension SiteCredentialsViewController: UITextFieldDelegate {
237240
private extension SiteCredentialsViewController {
238241

239242
@objc func dismissView() {
240-
navigationController?.dismiss(animated: true)
243+
dismissBlock?(true)
241244
}
242245
/// Registers all of the available TableViewCells.
243246
///

0 commit comments

Comments
 (0)