What is the proper way to store tab content state in Compose Multiplatform? "Remember" keeps state only during recompositions, not when one view replaces another. On Android ViewModel should be used, but in Compose Multiplatform there is no ViewModel class.
Asked
Active
Viewed 245 times
1
-
1I keep the state outside the compose-ui tree. You can have a State class that have children states where each child state correspond to a tab state. Eg: https://github.com/pablichjenkov/uistate3/blob/f8de9ec8093cd75085dce4a12ef26e4ea209e553/node/src/commonMain/kotlin/com/pablichj/encubator/node/navbar/NavBarNode.kt#L26 In this example I use a State Holder class named NavBarNode that contains child Nodes for each tab. That mechanism goes all the way to the root state Node that lives outside the compose-ui tree. Could live in an Activity ViewModel or in a Singleton. – Pablo Valdes Dec 23 '22 at 09:56