Since Composables will eventually replace Fragment...
# compose
b
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?
a
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
ViewModel
superclass doesn't serve much purpose; any old object you
remember {}
persists as normal
we have the
savedInstanceState
APIs in compose already for saving across process restarts, and that doesn't experience the same
ViewModel
scoping questions
πŸŽ‰ 7
that's the long term
in the short term, I believe the navigation team is closer to the AAC
ViewModel
scope provider APIs and they intend to use them for navigation destinations - I might be out of date on this πŸ™‚
πŸ‘ 1
so yes, scoping
ViewModels
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
b
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
s
I hope we can eliminate ViewModel and fragments in Compose only app, that would simplify things so much.
πŸ‘ 4
b
Thanks, Adam! When you say the savedInstanceState APIs, you mean these? https://developer.android.com/jetpack/compose/interop#savedinstancestate
πŸ‘Œ 1
Okay, cool. Thank you! πŸŽ„
πŸ‘ 1
i
Navigation already scopes ViewModels to individual destinations and had since it's first alpha πŸ˜ƒ
πŸ‘ 2