hello everyone, I have question regarding KMP stat...
# multiplatform
d
hello everyone, I have question regarding KMP state and Swift UI. Can you share your experience on how you manage state in SwiftUI from a shared StateHolder? I have a StateHolder initialized in a native ViewModel (VM):
Copy code
class MyVm: ObservableObject {
    @Published private(set) var state: ScreenState

    func observeViewState() async {
        for await kmpState in stateHolder.state {
            let viewState = onEnum(of: kmpState)
            // Update state here
        }
    }
}

data class ScreenState(
    val value1: SomeClass1,
    val value2: SomeClass2
)
My screen in SwiftUI uses properties to render different parts of the screen:
value1
renders a list of items, and
value2
renders a card. As I understand it and what I see in the logs, if any property in the
@Published
property changes, it causes the entire screen to re-render (both components). That is, if
value1
changes, I expect the list of items to re-render, and the card should remain untouched since there were no changes. So far, I see that for each property in the state, I need to create its own
@Published
variable and pass it specifically to the component. This works on a simple screen, but if I have nested views and more than 3-5 such variables, to update a specific view in the hierarchy, I need to pass a specific
@Published
variable that will control the re-rendering when the corresponding variable changes. What is the preferable approach? Ty in advance
if someone will be interested in the response, you can find it here https://kotlinlang.slack.com/archives/C9JM6Q2UX/p1720734713984049