https://kotlinlang.org logo
#compose
Title
# compose
c

Ciox

11/01/2023, 3:39 PM
I want to pass data between 4 screens in compose. What strategies should I use? I have seen options of using SharedViewmodel, CompositionLocal and Room?
j

José González D'Amico

11/01/2023, 3:43 PM
maybe that question will be more suitable for #android-architecture? Or you aren't targeting Android only?
c

Ciox

11/01/2023, 3:45 PM
I am building a compose app for android, I am having challenges passing data across different composables. Would you kindly advise?
j

José González D'Amico

11/01/2023, 3:45 PM
not a Compose expert at all, I answered because I'm interested in the response you'd get
f

Francesc

11/01/2023, 3:56 PM
it depends on what navigation framework you use. If you opt for the AAC (Android Architecture Components) navigation, then navigation arguments are available in the viewmodel via the
SavedStateHandle
so that would be an option
c

Ciox

11/01/2023, 4:04 PM
Thank you for the suggestion. Yes, I am using AAC navigation, but have never used
SavedStateHandle
to store data. Let me look into it asI look for more options.
f

Francesc

11/01/2023, 4:06 PM
any argument that you pass to a composable will automatically be populated into the saved stated handle object that the viewmodel receives, so it does all the wiring for you
you can check the NowInAndroid app for reference
c

Ciox

11/01/2023, 4:20 PM
Thank you. Let me use this apprroach
2 Views