Hasan Nagizade
11/07/2022, 4:28 AMPablichjenkov
11/07/2022, 5:12 AMHasan Nagizade
11/07/2022, 8:15 AMPablichjenkov
11/07/2022, 5:02 PMAndroid ViewModel
just to host your composable State
to survive configuration changes. Then in the ‘Navigation graph class composables’ you extract your State from the Android ViewModel and pass that State down to the composables by sections. Don’t pass the root State to child composables, split you big State in child States too, and pass that child State to the child composable. It makes the composable easier to test and preview.
You can see in the link below an example of using Android ViewModel as a State holder with the use of hilt.
https://github.com/pablichjenkov/ComposeStudy/blob/04298ca8393d3eea0f5b7883fb22316[…]src/main/java/com/pablichj/study/compose/home/HomeNavigation.kt
In other platforms like iOS or Desktop they might call ViewModel
what we call State
. The reason is those platforms don’t have the term stolen like we have in Android. But my Advice is just use the Android ViewModel
as a configuration change persister rather than a real ViewModel that contains UI and Domain logic. Place that logic in your State.Hasan Nagizade
11/07/2022, 7:08 PM