@FocusState doesn't work with UIHostingConfiguration

Hi! I'm experimenting with UIHostingConfiguration. I put a textfield in the cell's coniguration and would like to observe its state. I created a @FocusState variable and set the focused(_:). But I've noticed that @FocusState doesn't work in UIHostingConfiguration. Here' my code:

struct TaskView: View {

    

    @ObservedObject var task: Task

    @FocusState private var isFocused: Bool



    var body: some View {



        HStack(spacing: 10) {

            Image(systemName: (task.isCompleted == true) ? "checkmark.square.fill" : "square")

                .font(Font.system(size: 20, weight: .medium))

                .foregroundColor(.gray)

                .onTapGesture {

                    task.isCompleted = true

                }

            VStack(alignment: .leading, spacing: 3) {

                TextField("Task", text: $task.name)

                    .onSubmit {

                        try! (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext.save()

                    }

                    .focused($isFocused)

                    .submitLabel(.done)

                    .onChange(of: isFocused) { newValue in

                        print(newValue) //always returns false

                    }

                HStack(spacing: 2) {

                    Image(systemName: "moon.fill")

                        .resizable()

                        .frame(width: 10, height: 10)

                        .foregroundColor(.blue)

                    Text("Tomorrow")

                        .font(.footnote).bold()

                        .foregroundColor(.gray)

                }

            }

        }

    }
}
Answered by Frameworks Engineer in 731254022

This issue should be resolved as of iOS 16.1 beta 4 (build 20B5064c). Please give it a try, and definitely submit a new bug report if you're still seeing any issues on that version or later.

@FocusState should work with SwiftUI views inside UIHostingConfiguration. If you have a reproducible case where it is not working properly, can you please file a bug report with a small sample project attached so that we can investigate and see why it's not working as expected for you?

Accepted Answer

This issue should be resolved as of iOS 16.1 beta 4 (build 20B5064c). Please give it a try, and definitely submit a new bug report if you're still seeing any issues on that version or later.

@FocusState doesn't work with UIHostingConfiguration
 
 
Q