Maciej S
03/08/2023, 10:24 AMcurioustechizen
03/08/2023, 12:55 PM@Composable fun FooScreen(fooViewModel: FooViewModel, bottomNavViewModel: BottomNavViewModel)
.ModalBottomSheetLayout
. The bottom sheet part itself has quite a lot of logic; and the bottom sheet part is used in from multiple screens. In this situation I did try the the solution of using multiple ViewModels (@Composable fun FooScreen(fooViewModel: FooViewModel, bottomSheetViewModel: BottomSheetViewModel)
)
But this did not work well because the bottom sheet part was not completely independent. For instance, the main content decides whether to show the bottom sheet or not (as opposed to the bottom sheet being a navigation destination).
In such cases what I really want is for the BottomSheetViewModel
to be an independent component; but for a higher level FooViewModel
to include it as a dependency.they still need to take a large number of dependencies (use cases, etc.)We have this too and I feel it is fine. I don't view it as the VM is doing too many things. Instead, the way I look at is is: • The VM accepts user actions and outputs a state. • For each user action, it delegates to a usecase. • For some presentation-only actions it might update the state itself without going to a UseCase but that's fine In general I view the number of UseCase dependencies for a ViewModel is a function of the number of actions that can occur on that screen
Maciej S
03/08/2023, 6:44 PMVinícius Santos
03/10/2023, 7:08 PM//Instead of
viewmodel.state.collectAsState
viewmodel.doSomething
// would be somethinslg like this
viemodel.myIndependentController.state.collectaAsState
viewmodel.myIndependentController.doSomethins
This is a suggestion of use though if you prefer to hide that from the ui you could delegate the calls to the controllers or maybe have some sorte of sealed classes for representing distinct actions that are handled by especific controllers.Yingding Wang
03/11/2023, 11:45 AMcurioustechizen
03/12/2023, 10:14 AMsetContent {MyTopLevelComposable()}
Yingding Wang
03/12/2023, 10:33 AMRay Ryan
03/16/2023, 8:57 PM