Optional state change doesn't update View #3118
-
Hi there. I have a feeling that I'm doing something stupidly wrong, but still here is the question. I have a code for showing optional state based on the example in case studies GettingStarted-OptionalState. The code is this (cut out the rest to have a clear example):
View:
Logs:
Initially the view was working fine with non-optional state and now we've added a possibility to show something else when the report is not available. The problem is that when I get the report and I see it is available in debug mode, the view is not being updated, always showing UNDER CONSTRUCTION text. But if I go to the next level of navigation and go back, then the view is updated and I can see the proper view. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @Paul-Svetlichny, can you please provide a fully compiling example that demonstrates the problem? It is difficult to diagnose this problem with just a few code snippets. |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw Okay, I was able to reproduce the issue in a simple test project. Please take a look at the file attached. |
Beta Was this translation helpful? Give feedback.
Hi @Paul-Svetlichny, I believe that problem is your use of
withAnimation
in the reducer. Unfortunately that does not work with@ObservableState
, and in fact it does not even work with vanilla SwiftUI and@Observable
. We filed a feedback about this during the beta period of iOS 17 and never heard back.If you remove those does it work as you expect? And if you do need to perform animation in those actions you can instead send the actions with animation:
…or you can use the
.animation(_:value:)
modifier in the view.And while I don't think it's the cause of any problems in this …