diff --git a/Fyreplace/Views/Screens/LoginScreen.swift b/Fyreplace/Views/Screens/LoginScreen.swift index 611ec7e..88dce6b 100644 --- a/Fyreplace/Views/Screens/LoginScreen.swift +++ b/Fyreplace/Views/Screens/LoginScreen.swift @@ -6,9 +6,6 @@ struct LoginScreen: View { @SceneStorage("LoginScreen.identifier") private var identifier = "" - @Namespace - private var mainNamespace - @FocusState private var focused: Bool @@ -37,12 +34,11 @@ struct LoginScreen: View { .onSubmit(submit) .accessibilityIdentifier("identifier") .matchedGeometryEffect(id: "first-field", in: namespace) - #if os(macOS) - .prefersDefaultFocus(in: mainNamespace) - #else + #if !os(macOS) .labelsHidden() #endif } + .onAppear { focused = identifier.isEmpty } #if !os(macOS) submitButton diff --git a/Fyreplace/Views/Screens/RegisterScreen.swift b/Fyreplace/Views/Screens/RegisterScreen.swift index 596154b..e01b65a 100644 --- a/Fyreplace/Views/Screens/RegisterScreen.swift +++ b/Fyreplace/Views/Screens/RegisterScreen.swift @@ -10,7 +10,7 @@ struct RegisterScreen: View { private var email = "" @FocusState - private var focusedField: FocusedField? + private var focused: FocusedField? private var isUsernameValid: Bool { 3 ... 50 ~= username.count } private var isEmailValid: Bool { 3 ... 254 ~= email.count && email.contains("@") } @@ -40,20 +40,27 @@ struct RegisterScreen: View { TextField("Register.Username", text: $username, prompt: usernamePrompt) .textContentType(.username) .autocorrectionDisabled() - .focused($focusedField, equals: .username) + .focused($focused, equals: .username) .submitLabel(.next) - .onSubmit { focusedField = .email } + .onSubmit { focused = .email } .accessibilityIdentifier("username") .matchedGeometryEffect(id: "first-field", in: namespace) TextField("Register.Email", text: $email, prompt: emailPrompt) .textContentType(.email) .autocorrectionDisabled() - .focused($focusedField, equals: .email) + .focused($focused, equals: .email) .submitLabel(.done) .onSubmit(submit) .accessibilityIdentifier("email") } + .onAppear { + if username.isEmpty { + focused = .username + } else if email.isEmpty { + focused = .email + } + } #if !os(macOS) submitButton @@ -64,7 +71,7 @@ struct RegisterScreen: View { private func submit() { guard canSubmit else { return } - focusedField = nil + focused = nil } }