From a2389fa7ee89b9f58f1a55a3e4a7a46798feded7 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 9 Oct 2026 09:42:25 -0700 Subject: [PATCH] Add AccountSetupSheet which is shared by Local, CloudKit, and credentials sheets. --- iOS/Account/AccountSetupSheet.swift | 50 +++++++++++++++ iOS/Account/CloudKitAccountView.swift | 55 +++++++---------- iOS/Account/CredentialsAccountView.swift | 78 +++++++++--------------- iOS/Account/LocalAccountView.swift | 45 ++++++-------- 4 files changed, 119 insertions(+), 109 deletions(-) create mode 100644 iOS/Account/AccountSetupSheet.swift diff --git a/iOS/Account/AccountSetupSheet.swift b/iOS/Account/AccountSetupSheet.swift new file mode 100644 index 000000000..e86b84bd5 --- /dev/null +++ b/iOS/Account/AccountSetupSheet.swift @@ -0,0 +1,50 @@ +// +// AccountSetupSheet.swift +// NetNewsWire-iOS +// +// Created by Brent Simmons on 10/9/26. +// + +import SwiftUI +import Account + +/// The frame shared by the account setup sheets: a form titled with the account name and a Cancel button. +/// While `isWorking` is true, a progress indicator shows and the sheet can’t be canceled or swiped away. +struct AccountSetupSheet: View { + + let accountType: AccountType + let isWorking: Bool + let content: Content + + @Environment(\.dismiss) private var dismiss + + init(accountType: AccountType, isWorking: Bool = false, @ViewBuilder content: () -> Content) { + self.accountType = accountType + self.isWorking = isWorking + self.content = content() + } + + var body: some View { + NavigationStack { + Form { + content + } + .navigationTitle(Text(verbatim: accountType.displayName)) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) { + dismiss() + } + .disabled(isWorking) + } + ToolbarItem(placement: .topBarTrailing) { + if isWorking { + ProgressView() + } + } + } + .interactiveDismissDisabled(isWorking) + } + } +} diff --git a/iOS/Account/CloudKitAccountView.swift b/iOS/Account/CloudKitAccountView.swift index ba6979666..f437af5c1 100644 --- a/iOS/Account/CloudKitAccountView.swift +++ b/iOS/Account/CloudKitAccountView.swift @@ -19,43 +19,32 @@ struct CloudKitAccountView: View { @State private var isShowingHelp = false var body: some View { - NavigationStack { - Form { - Section { - Button(NSLocalizedString("Use iCloud", comment: "Use iCloud button")) { - addAccount() - } - .frame(maxWidth: .infinity) - } header: { - AccountIconHeader(accountType: .cloudKit) - } footer: { - AccountSheetFooter(text: NSLocalizedString("NetNewsWire will use your iCloud account to sync your subscriptions across your Mac and iOS devices.", comment: "iCloud"), linkTitle: CloudKitWebDocumentation.limitationsAndSolutionsText) { - isShowingHelp = true - } + AccountSetupSheet(accountType: .cloudKit) { + Section { + Button(NSLocalizedString("Use iCloud", comment: "Use iCloud button")) { + addAccount() + } + .frame(maxWidth: .infinity) + } header: { + AccountIconHeader(accountType: .cloudKit) + } footer: { + AccountSheetFooter(text: NSLocalizedString("NetNewsWire will use your iCloud account to sync your subscriptions across your Mac and iOS devices.", comment: "iCloud"), linkTitle: CloudKitWebDocumentation.limitationsAndSolutionsText) { + isShowingHelp = true } } - .navigationTitle(Text(verbatim: AccountType.cloudKit.displayName)) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .cancellationAction) { - Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) { - dismiss() - } - } + } + .alert(isPresented: isShowingiCloudDriveError, error: iCloudDriveError) { _ in + Button(NSLocalizedString("Open Settings", comment: "Open Settings button")) { + AddCloudKitAccountUtilities.openiCloudSettings() } - .alert(isPresented: isShowingiCloudDriveError, error: iCloudDriveError) { _ in - Button(NSLocalizedString("Open Settings", comment: "Open Settings button")) { - AddCloudKitAccountUtilities.openiCloudSettings() - } - Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) { - iCloudDriveError = nil - } - } message: { error in - Text(verbatim: error.recoverySuggestion ?? "") - } - .sheet(isPresented: $isShowingHelp) { - SafariView(url: CloudKitWebDocumentation.limitationsAndSolutionsURL) + Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) { + iCloudDriveError = nil } + } message: { error in + Text(verbatim: error.recoverySuggestion ?? "") + } + .sheet(isPresented: $isShowingHelp) { + SafariView(url: CloudKitWebDocumentation.limitationsAndSolutionsURL) } } diff --git a/iOS/Account/CredentialsAccountView.swift b/iOS/Account/CredentialsAccountView.swift index 7a117a2c1..8dd232aae 100644 --- a/iOS/Account/CredentialsAccountView.swift +++ b/iOS/Account/CredentialsAccountView.swift @@ -44,60 +44,42 @@ struct CredentialsAccountView: View { } var body: some View { - NavigationStack { - Form { - Section { - TextField(accountType.usernamePlaceholder, text: $username) - .textContentType(.username) - .keyboardType(.emailAddress) + AccountSetupSheet(accountType: accountType, isWorking: isValidating) { + Section { + TextField(accountType.usernamePlaceholder, text: $username) + .textContentType(.username) + .keyboardType(.emailAddress) + .textInputAutocapitalization(.never) + .autocorrectionDisabled() + passwordRow + if accountType.needsAPIURL { + TextField(NSLocalizedString("API URL: https://fresh.rss.net/api/greader.php", comment: "FreshRSS API Helper"), text: $apiURLString) + .textContentType(.URL) + .keyboardType(.URL) .textInputAutocapitalization(.never) .autocorrectionDisabled() - passwordRow - if accountType.needsAPIURL { - TextField(NSLocalizedString("API URL: https://fresh.rss.net/api/greader.php", comment: "FreshRSS API Helper"), text: $apiURLString) - .textContentType(.URL) - .keyboardType(.URL) - .textInputAutocapitalization(.never) - .autocorrectionDisabled() - } - } header: { - AccountIconHeader(accountType: accountType) } - Section { - Button(actionTitle) { - Task { - await submit() - } - } - .frame(maxWidth: .infinity) - .disabled(!canSubmit || isValidating) - } footer: { - AccountSheetFooter(text: accountType.footerText, linkTitle: accountType.signUpTitle) { - isShowingSignUp = true + } header: { + AccountIconHeader(accountType: accountType) + } + Section { + Button(actionTitle) { + Task { + await submit() } } + .frame(maxWidth: .infinity) + .disabled(!canSubmit || isValidating) + } footer: { + AccountSheetFooter(text: accountType.footerText, linkTitle: accountType.signUpTitle) { + isShowingSignUp = true + } } - .navigationTitle(Text(verbatim: accountType.displayName)) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .cancellationAction) { - Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) { - dismiss() - } - .disabled(isValidating) - } - ToolbarItem(placement: .topBarTrailing) { - if isValidating { - ProgressView() - } - } - } - .interactiveDismissDisabled(isValidating) - .errorAlert(message: $errorMessage) - .sheet(isPresented: $isShowingSignUp) { - if let signUpURL = accountType.signUpURL { - SafariView(url: signUpURL) - } + } + .errorAlert(message: $errorMessage) + .sheet(isPresented: $isShowingSignUp) { + if let signUpURL = accountType.signUpURL { + SafariView(url: signUpURL) } } } diff --git a/iOS/Account/LocalAccountView.swift b/iOS/Account/LocalAccountView.swift index 69c3651ea..e0977a1ef 100644 --- a/iOS/Account/LocalAccountView.swift +++ b/iOS/Account/LocalAccountView.swift @@ -18,37 +18,26 @@ struct LocalAccountView: View { @FocusState private var isNameFieldFocused: Bool var body: some View { - NavigationStack { - Form { - Section { - TextField(NSLocalizedString("Name", comment: "Name field placeholder"), text: $name) - .textInputAutocapitalization(.words) - .focused($isNameFieldFocused) - .onSubmit { - isNameFieldFocused = false - } - } header: { - AccountIconHeader(accountType: .onMyMac) - } - Section { - Button(NSLocalizedString("Add Account", comment: "Add Account")) { - addAccount() + AccountSetupSheet(accountType: .onMyMac) { + Section { + TextField(NSLocalizedString("Name", comment: "Name field placeholder"), text: $name) + .textInputAutocapitalization(.words) + .focused($isNameFieldFocused) + .onSubmit { + isNameFieldFocused = false } - .frame(maxWidth: .infinity) - } footer: { - Text(NSLocalizedString("Local accounts do not sync your feeds across devices.", comment: "Local")) - .multilineTextAlignment(.center) - .frame(maxWidth: .infinity) - } + } header: { + AccountIconHeader(accountType: .onMyMac) } - .navigationTitle(Text(verbatim: AccountType.onMyMac.displayName)) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .cancellationAction) { - Button(NSLocalizedString("Cancel", comment: "Cancel button"), role: .cancel) { - dismiss() - } + Section { + Button(NSLocalizedString("Add Account", comment: "Add Account")) { + addAccount() } + .frame(maxWidth: .infinity) + } footer: { + Text(NSLocalizedString("Local accounts do not sync your feeds across devices.", comment: "Local")) + .multilineTextAlignment(.center) + .frame(maxWidth: .infinity) } } }