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)
}
}
}
}
}