Add and use shared hasCredentialsView and ViewBuilder for getting the correct credentials view.

This commit is contained in:
Brent Simmons committed 2026-11-25 10:28:21 -08:00
1 parent 118640e4bc
commit e9c32b5f7c
3 files changed
+30 -22

No files matched your search

+25
View File
@@ -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)
}
}
}
+2 -10
View File
@@ -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 {
@@ -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)