is it a good practice to embed a `ListDetailPaneSc...
# compose
p
is it a good practice to embed a
ListDetailPaneScaffold
inside a`NavigationSuiteScaffold`? I need both behaviours,
NavigationSuiteScaffold
whould manage all the navigation of the application, but in one screen, I need list detail, so for that screen I need to embed it.
a
Yep definitely! That’s the expected setup, since the navigation UI is generally “global” and doesn’t live in any one specific pane
p
Great, thanks. One other thing. I'm a bit confussed about how to manage viewmodels in this case. Having a main App.kt that handles navigation (and some other shared stuff like displaying an "about us" dialog) with the
NavigationSuiteScaffold
or a custom navigation container... the App.kt scaffold and shared functionality is always onscreen, when you navigate to screen A, screen B or screen C, the parent App.kt scaffold is still visible. So, in this case, should the app have a
AppViewModel
loaded and managing the shared logic (currentDestination, navigation, logic for display about us dialog, other possible shared logic that can be launched from all the screens... ) and also a
ScreenAViewModel
,
ScreenBViewModel
etc... that can coexist at once with
AppViewModel
?
As I see it, there are two things visibles at once, the container of the screen (App.kt) and the screen (ScreenA, ScreenB, etc...) and each one has logic and functionalities, so... should each one have its own viewmodel coexisting at once?
if not... how to deal with this?
a
It’s perfectly fine for each to have its own
ViewModel
, and you can scope `ViewModel`s to have different lifecycles. It sounds like
AppViewModel
would be scoped to the overall
Activity
, and then the different screen view models would be scoped to a particular screen. Communicating between view models with different scopes is tricky though, and you can’t scope a
ViewModel
easily within
ListDetailPaneScaffold
either. Probably the most straightforward route is to have a
ViewModel
scoped to a destination that can handle everything in the list, detail, and showing both together, and then use a
ListDetaliPaneScaffold
within that level.
p
thank you, I thought that it was a bad practice to have two viewmodels at once visible