[tvOS] Change password to be a SecureField and autosubmit on password comple… (#1090)
Some checks are pending
Build 🔨 / Build 🔨 (Swiftfin tvOS) (push) Waiting to run
Build 🔨 / Build 🔨 (Swiftfin) (push) Waiting to run

* Change password to be a SecureField and autosubmit on password completion

* Fix SelectUser Button

* Respond to comments and remove unnecessary changes

* Make FocusField a private enum
This commit is contained in:
Peter McNeil 2024-10-06 09:24:28 +01:00 committed by GitHub
parent ddd651ea3f
commit 5d59d57871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 16 deletions

2
.gitignore vendored
View File

@ -98,3 +98,5 @@ iOSInjectionProject/
ehthumbs.db ehthumbs.db
Thumbs.db Thumbs.db
Shared/Generated/Strings.swift Shared/Generated/Strings.swift
.idea

View File

@ -44,7 +44,6 @@ class SelectUserViewModel: ViewModel, Eventful, Stateful {
var events: AnyPublisher<Event, Never> { var events: AnyPublisher<Event, Never> {
eventSubject eventSubject
.receive(on: RunLoop.main)
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }

View File

@ -17,6 +17,11 @@ import SwiftUI
struct UserSignInView: View { struct UserSignInView: View {
private enum FocusField: Hashable {
case username
case password
}
@Default(.accentColor) @Default(.accentColor)
private var accentColor private var accentColor
@ -24,7 +29,7 @@ struct UserSignInView: View {
private var router: UserSignInCoordinator.Router private var router: UserSignInCoordinator.Router
@FocusState @FocusState
private var focusedTextField: Int? private var focusedTextField: FocusField?
@State @State
private var duplicateUser: UserState? = nil private var duplicateUser: UserState? = nil
@ -52,17 +57,16 @@ struct UserSignInView: View {
TextField(L10n.username, text: $username) TextField(L10n.username, text: $username)
.autocorrectionDisabled() .autocorrectionDisabled()
.textInputAutocapitalization(.never) .textInputAutocapitalization(.never)
.focused($focusedTextField, equals: 0) .focused($focusedTextField, equals: .username)
.onSubmit {
focusedTextField = 1
}
TextField(L10n.password, text: $password) { SecureField(L10n.password, text: $password)
focusedTextField = nil .focused($focusedTextField, equals: .password)
} .onSubmit {
.autocorrectionDisabled() guard username.isNotEmpty else {
.textInputAutocapitalization(.never) return
.focused($focusedTextField, equals: 1) }
viewModel.send(.signIn(username: username, password: password, policy: .none))
}
} header: { } header: {
Text(L10n.signInToServer(viewModel.server.name)) Text(L10n.signInToServer(viewModel.server.name))
} }
@ -74,8 +78,6 @@ struct UserSignInView: View {
.foregroundStyle(.red, .red.opacity(0.2)) .foregroundStyle(.red, .red.opacity(0.2))
} else { } else {
Button(L10n.signIn) { Button(L10n.signIn) {
focusedTextField = nil
viewModel.send(.signIn(username: username, password: password, policy: .none)) viewModel.send(.signIn(username: username, password: password, policy: .none))
} }
.disabled(username.isEmpty) .disabled(username.isEmpty)
@ -123,7 +125,7 @@ struct UserSignInView: View {
) { ) {
username = user.name ?? "" username = user.name ?? ""
password = "" password = ""
focusedTextField = 1 focusedTextField = .password
} }
} }
} }
@ -177,7 +179,7 @@ struct UserSignInView: View {
} }
} }
.onFirstAppear { .onFirstAppear {
focusedTextField = 0 focusedTextField = .username
viewModel.send(.getPublicData) viewModel.send(.getPublicData)
} }
.alert( .alert(