# compose

Brady Aiello

12/25/2020, 1:20 AM
Since Composables will eventually replace Fragments, I was wondering if we'll be able to scope ViewModels to Composables, or Composable destinations within Compose Navigation? Keeping lots of ViewModels all scoped to a single Activity, or keeping one god-ViewModel would both hold data for every page in memory concurrently, and that seems like a bad idea. Am I wrong, or is there another strategy the Compose folks are considering?

Adam Powell

12/25/2020, 2:23 AM
see the other thread above regarding replace or not; that's up to you
if you're using all-compose, there's no reason to leave activity recreation for configuration changes enabled since compose knows how to handle them at a much finer granularity
😇 2
👍 1
🤔 4
which then means the arch components
superclass doesn't serve much purpose; any old object you
remember {}
persists as normal
we have the
APIs in compose already for saving across process restarts, and that doesn't experience the same
scoping questions
🎉 7
that's the long term
in the short term, I believe the navigation team is closer to the AAC
scope provider APIs and they intend to use them for navigation destinations - I might be out of date on this 🙂
👍 1
so yes, scoping
for situations where you have to keep activity recreation for compatibility with other parts of your code will be possible. I haven't kept up with the current state of the art on this at the moment

Brady Aiello

12/25/2020, 7:28 AM
You disable activity recreation for any configuration changes? I wasn't aware this was the recommended practice for pure Compose apps. If we ignore config changes, will Compose still act appropriately with locale or dark theme changes for instance? Gonna test this out tomorrow.
👌 1

Shakil Karim

12/25/2020, 11:11 AM
I hope we can eliminate ViewModel and fragments in Compose only app, that would simplify things so much.
👍 4

Brady Aiello

12/25/2020, 5:08 PM
Thanks, Adam! When you say the savedInstanceState APIs, you mean these?
👌 1
Okay, cool. Thank you! 🎄
👍 1

Ian Lake

12/29/2020, 11:21 PM
Navigation already scopes ViewModels to individual destinations and had since it's first alpha 😃
👍 2