Retain profile name (disabled) after importing

Works around a crash in iPadOS 14 portrait when removing section
containing first responder (profile name TextField). It happened
when submitting profile name via keyboard rather than "Save".
This commit is contained in:
Davide De Rosa 2022-04-26 22:56:41 +02:00
parent 4a0245d757
commit 1c047b9ce2
1 changed files with 24 additions and 20 deletions

View File

@ -41,7 +41,11 @@ extension AddHostView {
@State private var viewModel = ViewModel() @State private var viewModel = ViewModel()
@State private var isEnteringCredentials = false @State private var isEnteringCredentials = false
private var isComplete: Bool {
!viewModel.processedProfile.isPlaceholder
}
init( init(
url: URL, url: URL,
deletingURLOnSuccess: Bool, deletingURLOnSuccess: Bool,
@ -57,11 +61,7 @@ extension AddHostView {
ZStack { ZStack {
hiddenAccountLink hiddenAccountLink
List { List {
if viewModel.processedProfile.isPlaceholder { mainView
processingView
} else {
completeView
}
}.themeAnimation(on: viewModel) }.themeAnimation(on: viewModel)
}.toolbar { }.toolbar {
themeCloseItem(isPresented: bindings.$isPresented) themeCloseItem(isPresented: bindings.$isPresented)
@ -82,7 +82,7 @@ extension AddHostView {
} }
@ViewBuilder @ViewBuilder
private var processingView: some View { private var mainView: some View {
AddProfileView.ProfileNameSection( AddProfileView.ProfileNameSection(
profileName: $viewModel.profileName, profileName: $viewModel.profileName,
errorMessage: viewModel.errorMessage errorMessage: viewModel.errorMessage
@ -90,16 +90,21 @@ extension AddHostView {
processProfile(replacingExisting: false) processProfile(replacingExisting: false)
}.onAppear { }.onAppear {
viewModel.presetName(withURL: url) viewModel.presetName(withURL: url)
} }.disabled(isComplete)
if viewModel.requiresPassphrase {
encryptionSection if !isComplete {
} if viewModel.requiresPassphrase {
let headers = profileManager.headers.sorted() encryptionSection
if !headers.isEmpty { }
AddProfileView.ExistingProfilesSection( let headers = profileManager.headers.sorted()
headers: headers, if !headers.isEmpty {
profileName: $viewModel.profileName AddProfileView.ExistingProfilesSection(
) headers: headers,
profileName: $viewModel.profileName
)
}
} else {
completeSection
} }
} }
@ -113,12 +118,11 @@ extension AddHostView {
} }
} }
private var completeView: some View { private var completeSection: some View {
Section( Section(
header: Text(L10n.AddProfile.Shared.title),
footer: themeErrorMessage(viewModel.errorMessage) footer: themeErrorMessage(viewModel.errorMessage)
) { ) {
Text(L10n.Global.Strings.name)
.withTrailingText(viewModel.processedProfile.header.name)
Text(Unlocalized.Network.url) Text(Unlocalized.Network.url)
.withTrailingText(url.lastPathComponent) .withTrailingText(url.lastPathComponent)
viewModel.processedProfile.vpnProtocols.first.map { viewModel.processedProfile.vpnProtocols.first.map {