Xcode 15 Breaks Usage Of TextField.focused()

My usage of TextField.focused() works fine in Xcode 14.3.1 but is broken as of Xcode 15. I first noticed it in the second beta and it's still broken as of the 4th beta.

Feedback / OpenRadar # FB12432084

import SwiftUI

struct ContentView: View {
    @State private var text = ""
    
    @FocusState var isFocused: Bool
    var body: some View {
        ScrollView {
            TextField("Test", text: $text)
                .textFieldStyle(.roundedBorder)
                .focused($isFocused)
            Text("Text Field Is Focused: \(isFocused.description)")
        }
    }
}
Post not yet marked as solved Up vote post of dav_es Down vote post of dav_es
905 views

Replies

Apologies, this would be more appropriately titled, iOS 17 Breaks Usage Of TextField.focused()

hi

I have the same issue. have you been able to resolve this issue? Since the focusState is broken, I'm not able to hide they keyboard anymore.

 .onTapGesture {
            if (isFocused == true) {
                isFocused = false
            }
        }

Hi @baugestalt, no I haven't. I'm hoping that it's fixed for the iOS 17 release build.

Thank you very much! This appears to be fixed as of iOS 17.0 (21A5317a Beta 7).

Either this was never fixed, or there was a regression, as I am still seeing this issue (FocusState not working correctly in ScrollView) on iOS 17.1

Even better, it's causing crashes in my app because the textfield is not unfocused before being disabled :) Love SwiftUI, hate these inconsistencies and bugs.

I am also having the same issue but on IPadOS 17.1.1

Occurring only once updated to IPadOS 17, IPadOS 16 continues to not have an issue.