Я пытаюсь сделать свой textField (NSViewRepresentable
wrapped NSTextField
) первым респондентом, когда он появляется. Я проверил много ответов в этой ветке , но они либо не работают:
func updateNSView(_ nsView: MyField, context: Context) {
if some_condition {
print(nsViews.becomeFirstResponder()) // returns false
negate_condition()
}
...
}
, либо он вылетает с журналами (=== AttributeGraph: cycle detected through attribute 43 ===)
:
func updateNSView(_ nsViews: MyField, context: Context) {
if some_condition {
Window.thisWindow?.makeFirstResponder(nsViews)
negate_condition()
}
...
}
Что Я пытаюсь достичь:
@State var fieldActive: Bool
body: some View {
MyField(...).onAppear { /*makeFirstResponder if fieldActive == true*/ }
}
Может кто-нибудь, пожалуйста, помогите мне в этом? Большое спасибо!