diff --git a/iOS/Account/Account+CredentialsView.swift b/iOS/Account/Account+CredentialsView.swift new file mode 100644 index 000000000..ef8ed0a86 --- /dev/null +++ b/iOS/Account/Account+CredentialsView.swift @@ -0,0 +1,25 @@ +// +// Account+CredentialsView.swift +// NetNewsWire-iOS +// +// Created by Brent Simmons on 11/25/26. +// + +import SwiftUI +import Account + +extension Account { + + var hasCredentialsView: Bool { + type == .miniflux || CredentialsAccountView.accountTypes.contains(type) + } + + /// The view for updating this account’s credentials. + @ViewBuilder func credentialsView() -> some View { + if type == .miniflux { + MinifluxAccountView(account: self, didAddAccount: nil) + } else { + CredentialsAccountView(accountType: type, account: self, didAddAccount: nil) + } + } +} diff --git a/iOS/Inspector/AccountInspectorView.swift b/iOS/Inspector/AccountInspectorView.swift index bafdfa98a..590e56f71 100644 --- a/iOS/Inspector/AccountInspectorView.swift +++ b/iOS/Inspector/AccountInspectorView.swift @@ -94,7 +94,7 @@ struct AccountInspectorView: View { AccountManager.shared.syncArticleContentForUnreadArticles = syncContentOfUnreadArticles } .sheet(isPresented: $isShowingCredentials) { - credentialsView + account.credentialsView() } .sheet(isPresented: $isShowingLimitationsAndSolutions) { SafariView(url: CloudKitWebDocumentation.limitationsAndSolutionsURL) @@ -120,15 +120,7 @@ private extension AccountInspectorView { } var showsCredentials: Bool { - !isDefaultAccount && (account.type == .miniflux || CredentialsAccountView.accountTypes.contains(account.type)) - } - - @ViewBuilder var credentialsView: some View { - if account.type == .miniflux { - MinifluxAccountView(account: account, didAddAccount: nil) - } else { - CredentialsAccountView(accountType: account.type, account: account, didAddAccount: nil) - } + !isDefaultAccount && account.hasCredentialsView } var showsSyncContent: Bool { diff --git a/iOS/UIKit Extensions/UIViewController+Extras.swift b/iOS/UIKit Extensions/UIViewController+Extras.swift index 829f7f33d..80d70ffc7 100644 --- a/iOS/UIKit Extensions/UIViewController+Extras.swift +++ b/iOS/UIKit Extensions/UIViewController+Extras.swift @@ -16,17 +16,6 @@ extension UIViewController { /// Size of form sheets on iPad. static let formSheetSize = CGSize(width: 460, height: 400) - /// The sheet for updating an account's credentials, or nil if its type has none. - static func credentialsViewController(for account: Account) -> UIViewController? { - if account.type == .miniflux { - return UIHostingController(rootView: MinifluxAccountView(account: account, didAddAccount: nil)) - } - guard CredentialsAccountView.accountTypes.contains(account.type) else { - return nil - } - return UIHostingController(rootView: CredentialsAccountView(accountType: account.type, account: account, didAddAccount: nil)) - } - func presentError(_ error: Error, dismiss: (() -> Void)? = nil) { if let accountError = error as? AccountError, accountError.isCredentialsError { presentAccountError(accountError, dismiss: dismiss) @@ -46,11 +35,13 @@ private extension UIViewController { let title = NSLocalizedString("Account Error", comment: "Account Error") let alertController = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert) - if let account = AccountError.account(from: error), let hostingController = UIViewController.credentialsViewController(for: account) { + if let account = AccountError.account(from: error), account.hasCredentialsView { let credentialsTitle = NSLocalizedString("Update Credentials", comment: "Update Credentials") let credentialsAction = UIAlertAction(title: credentialsTitle, style: .default) { [weak self] _ in dismiss?() + // Built here, not when the alert is shown, since CredentialsAccountView reads the Keychain in its init. + let hostingController = UIHostingController(rootView: account.credentialsView()) hostingController.modalPresentationStyle = .formSheet hostingController.preferredContentSize = UIViewController.formSheetSize self?.present(hostingController, animated: true)