Changes on @ObservableObject inside State does not update UI #1630
-
DescriptionHello, Do you guys have a solution for such cases where we need to use a manager observable class inside the state? You can see the code below. The ObservableObject that i need to use.
The reducer which i use it
Checklist
Expected behaviorNo response Actual behaviorNo response Steps to reproduceNo response The Composable Architecture version informationNo response Destination operating systemIOS 16 Xcode version information14.0.1 Swift Compiler version informationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @raduncicen! let store: StoreOf<Camera>
@ObservedObject var viewStore: ViewStoreOf<Camera>
@ObservedObject var coordinator: ARViewCoordinator
init(store: StoreOf<Camera>) {
self.store = store
let viewStore = ViewStore(store, observe: { $0 })
self.viewStore = viewStore
self.coordinator = viewStore.arViewCoordinator
} This is probably not how I would do it, but it can be enough to make it work in you case. This is likely not a TCA bug, as there is nothing that changes in your case to warrant a new view rendering, so I would say that it's working as expected in this situation. |
Beta Was this translation helpful? Give feedback.
-
Hi @raduncicen, as @tgrapperon points out this is not a bug in TCA and so I'm going to convert this to a discussion. In general, if you hold reference types in |
Beta Was this translation helpful? Give feedback.
Hey @raduncicen!
If you're using
UIViewRepresentable
, itsCoordinator
is not required to be anObservableObject
, and it will furthermore not be observed as such by theRepresentable
. When usingUIViewRepresentable
, theCoordinator
is private, and usually an implementation detail with which you don't talk directly (for example from a reducer).I never tried to install the
Coordinator
as anObservedObject
directly in theUIViewRepresentable
, so I don't know if it would work.So the idea is to wrap UIKit in
UIViewRepresentable
, ideally with a value-type API and closures/bindings to control it. But in your case, it could maybe work if you simply rewrite yourView
's init like this: