We are struggling with SwiftUI navigation in combination with TCA and I am wondering is someone else did encounter similar issue.
The problem is that when we set parameters isPresented
or isActive
on .sheet
or NavigationLink
to false
to dismiss it, then all content seems to be replaced with empty view before the animation starts (see attached gif).
In the code we store state (boolean value) indicating if child view is presented in parent view. When button to go back on child view is tapped, then we catch this action in parent view and change the boolean value to false
to dismiss child view. It works like a charm instead of navigation animation.
I would be endlessly happy for any help or suggestions.
I have a similar problem. My example is a bit more involved but arguably more generic. Hope it helps.
My TCA setup looks like this:
One can get the child store by scoping the parent store:
And the child view’s
body
looks like this:Here is what happened:
parent.child = nil
.objectWillChange
is called.WithViewStore
is marked dirty.WithViewStore
is called, and generates a new child view tree.My solution is to kill step 3. First, let's extend the child state with another property:
Second, when scoping, let's do:
Lastly, we can modify the
WithViewStore
with a customremoveDuplicates
closure:Here is how it works. The scoped child state can be
nil
in two cases, when the view is first created and the view is being dismissed. In the first case, the old isnil
. In the second case, the new isnil
. The customremoveDuplicates
essentially does this: when a child state is being dismissed, we skip any update. So the only animation being played is the transition animation. The content stays the same.