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

@ -42,6 +42,10 @@ extension AddHostView {
@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,7 +90,9 @@ extension AddHostView {
processProfile(replacingExisting: false) processProfile(replacingExisting: false)
}.onAppear { }.onAppear {
viewModel.presetName(withURL: url) viewModel.presetName(withURL: url)
} }.disabled(isComplete)
if !isComplete {
if viewModel.requiresPassphrase { if viewModel.requiresPassphrase {
encryptionSection encryptionSection
} }
@ -101,6 +103,9 @@ extension AddHostView {
profileName: $viewModel.profileName profileName: $viewModel.profileName
) )
} }
} else {
completeSection
}
} }
private var encryptionSection: some View { private var encryptionSection: some View {
@ -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 {