zoha131
11/13/2020, 7:25 PMJavier
11/13/2020, 7:34 PMzoha131
11/13/2020, 7:37 PMJavier
11/13/2020, 7:39 PMzoha131
11/13/2020, 7:49 PMJavier
11/13/2020, 7:55 PMIan Lake
11/13/2020, 8:14 PMcomposable lambda, then pass it into your separate screen Composable:
composable("route") {
  val viewModel: YourViewModel = viewModel()
  YourScreen(viewModel)
}Ian Lake
11/13/2020, 8:15 PMYourScreen is then easy to preview with a fake ViewModel, easy to test with a fake ViewModel, etcIan Lake
11/13/2020, 8:23 PMcomposable collect a flow of events from your ViewModelAndrey Kulikov
11/13/2020, 8:25 PMby keyword for the viewModel composable functionIan Lake
11/13/2020, 8:27 PMzoha131
11/13/2020, 8:29 PMHilt to inject ViewModel while testing?zoha131
11/13/2020, 8:33 PMCrane app already using Hilt to inject ViewModel.zoha131
11/13/2020, 8:44 PMViewModel will have repository, database as construction parameter. Would it be good practice to make constructor parameters nullable in order to fake the ViewModelIan Lake
11/13/2020, 9:00 PMJavier
11/13/2020, 10:02 PMDavid Attias
11/16/2020, 11:56 AMby keyword in that case, could you elaborate for me please ?Andrey Kulikov
11/16/2020, 12:11 PMDavid Attias
11/16/2020, 1:19 PMallan.conda
11/20/2020, 9:51 AMallan.conda
11/20/2020, 9:51 AMzoha131
11/20/2020, 9:56 AMcomposable of NavHost.allan.conda
11/20/2020, 10:06 AMfun Screen(state)
fun Screen(viewModel) {
  Screen(viewModel.state)
}
I was thinking the same, but I would have to pass all events from all descendants up to the Screen in order to delegate the logic into the viewModel.
Otherwise, I would have to have overloads of all descendants as well.
Have you thought about this case? Do you just Preview the top level screen?allan.conda
11/20/2020, 10:41 AMzoha131
11/20/2020, 12:27 PMzoha131
11/20/2020, 12:29 PMallan.conda
11/20/2020, 2:23 PMit will require more boilerplate codecan you elaborate
I don’t preview the top level screen. I don’t think that is needed.What do you mean? Your initial post was about making Two Screen composable overloads so you can preview it…”
I will use a stateless screen composable to preview and test.
zoha131
11/20/2020, 2:48 PMWhat do you mean? Your initial post was about making Two Screen composable overloads so you can preview it…”You said top level screen. I have some screens which has multiple nested screens. I thought You are talking about this kind of situation.
zoha131
11/20/2020, 2:54 PMit will require more boilerplate codeif you go with interface approach then you have to create interface for every single screen and a stub implementation of that interface to preview. this is why I think interface approach would require more boilerplate code. and to get rid of this situation I have started using Function as parameter.