Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set firstResponder in onAppear #7

Closed
Amzd opened this issue Jan 21, 2021 · 0 comments
Closed

Set firstResponder in onAppear #7

Amzd opened this issue Jan 21, 2021 · 0 comments

Comments

@Amzd
Copy link
Owner

Amzd commented Jan 21, 2021

SwiftUI's onAppear is called before ViewRepresentables are added to the generated view hierarchy so it is impossible to know anything about the responders at this point.

The fix is to delay your call by a single loop:

.onAppear {
    DispatchQueue.main.async {
        chain.firstResponder = "MyList"
    }
}

If you do not like this syntax just add this extension and call it instead of onAppear

extension View {
    func onAppearAfterIntrospect(perform block: @escaping () -> Void) {
        self.onAppear {
            DispatchQueue.main.async(execute: block)
        }
    }
}
@Amzd Amzd pinned this issue Jan 21, 2021
@Amzd Amzd closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant