Resolve some focus issues (#802)

- [x] tvOS: When profile selector appears, if it's closed without
selecting any profile, it instantly reopens
- [x] Set initial focus in OpenVPN credentials
This commit is contained in:
Davide 2024-11-03 08:17:19 +01:00 committed by GitHub
parent 8aff3bedbc
commit 15959d2422
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 6 deletions

View File

@ -31,8 +31,6 @@ import SwiftUI
struct ActiveProfileView: View {
let profile: Profile?
let firstProfileId: Profile.ID?
@ObservedObject
var tunnel: ExtendedTunnel
@ -95,9 +93,6 @@ private extension ActiveProfileView {
var switchProfileButton: some View {
Button {
if let focus = tunnel.currentProfile?.id ?? firstProfileId {
focusedField = .profile(focus)
}
isSwitching.toggle()
} label: {
Text(Strings.Global.select)

View File

@ -131,7 +131,6 @@ private extension ProfileView {
var activeView: some View {
ActiveProfileView(
profile: currentProfile,
firstProfileId: profileManager.headers.first?.id,
tunnel: tunnel,
isSwitching: $isSwitching,
focusedField: $focusedField,

View File

@ -29,6 +29,13 @@ import PassepartoutKit
import SwiftUI
public struct OpenVPNCredentialsView: View {
private enum Field: Hashable {
case username
case password
case otp
}
@EnvironmentObject
private var iapManager: IAPManager
@ -47,6 +54,9 @@ public struct OpenVPNCredentialsView: View {
@State
private var paywallReason: PaywallReason?
@FocusState
private var focusedField: Field?
public init(
isInteractive: Binding<Bool>,
credentials: Binding<OpenVPN.Credentials?>,
@ -66,6 +76,15 @@ public struct OpenVPNCredentialsView: View {
.onLoad {
builder = credentials?.builder() ?? OpenVPN.Credentials.Builder()
builder.otp = nil
if isAuthenticating {
switch builder.otpMethod {
case .none:
focusedField = .username
default:
focusedField = .otp
}
}
}
.onChange(of: builder) {
var copy = $0
@ -137,8 +156,11 @@ private extension OpenVPNCredentialsView {
if !isAuthenticating || builder.otpMethod == .none {
ThemeTextField(Strings.Global.username, text: $builder.username, placeholder: Strings.Placeholders.username)
.textContentType(.username)
.focused($focusedField, equals: .username)
ThemeSecureField(title: Strings.Global.password, text: $builder.password, placeholder: Strings.Placeholders.secret)
.textContentType(.password)
.focused($focusedField, equals: .password)
}
if isEligibleForInteractiveLogin, isAuthenticating, builder.otpMethod != .none {
ThemeSecureField(
@ -147,6 +169,7 @@ private extension OpenVPNCredentialsView {
placeholder: Strings.Placeholders.secret
)
.textContentType(.oneTimeCode)
.focused($focusedField, equals: .otp)
}
}
.themeSection(footer: inputFooter)