@GestureState and TCA

What's the recommendation in regards to tracking @GestureState? As far as I know it's faster than @State and sets your property back to initial value after gesture is ended (inactive). In general I'm a little bit confused about the correct use of SwiftUI @ property wrappers in context of TCA. Is it fine to use them in the view State struct? Is it encouraged?

You can use things like @State and @GestureState in your views if you want to track some truly ephemeral state that is internal and private to that view’s implementation but I would always consider trying to model that state within my store as a first approach.

With regards to gestures specifically, you can use your store to track persistent gesture state rather than @State.

@GestureState is a special case as it is truly ephemeral because it does get reset when the gesture ends. Use it to track some internal state while your gesture is running.

If your gesture needs to trigger some permanent state change, use the .onChanged and .onEnded modifiers to send actions to a view store.

1 Like

It would be cool if there was a "drop-in"-ish replacement for GestureState that could be included on view states in a store. That would allow for greater testability but still maintain the convenience of the GestureState API.

I might do some experimenting with this later... unless there's already some work being done in this area...? :sweat_smile: