Skip to content

TCA and new SwiftUI focus APIs from WWDC21 #610

Answered by mbrandonw
gohanlon asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @gohanlon, thanks for starting this discussion!

We've played with this API a bit and the solution we've come up with is essentially what you have. Listen for changes in each of @FocusState and TCA state in order to replay that change to the other. One small difference is that you can use another .onChange for viewStore.focusedField rather than subscribing to the publisher in .onAppear.

And this is actually apart of a bigger pattern that affects not only TCA but even vanilla SwiftUI. If you wanted to capture focus state inside an ObservableObject view model (in order to make it testable) you would need to do the same pattern of replaying changes to connect the VM world to the view world.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gohanlon
Comment options

Answer selected by gohanlon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants