Colton Idle
01/26/2022, 4:18 PMremember*State
calls to my VM?
Example:
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed))
Filip Wiesner
01/26/2022, 4:42 PMremember*State
calls to VM because they are usually Composable
.Filip Wiesner
01/26/2022, 4:44 PMColton Idle
01/26/2022, 4:49 PMif (viewModel.state.showModal) {
Dialog(onDismissRequest = { viewModel.state.showModal = false }) {
Box(Modifier.size(dialogWidth, dialogHeight).background(Color.White)){
Text("Modal")
}
}
}
and the VM is a simple:
var showModal by mutableStateOf(false)
but now my designer wants a bottom sheet, and idk how to model my bottom sheet in my VM.Francesc
01/26/2022, 7:41 PMviewModel.state.showModal = false
call a method in your viewmodel to do so. There should be just 1 source of truth (the viewmodel), by allowing the view to mutate the state you have 2Francesc
01/26/2022, 7:42 PMonDialogDismissed
and not something like resetShowModal
because the view should be agnostic of what happens on dismissal, just that it needs to communicate thatColton Idle
01/26/2022, 9:04 PMFrancesc
01/26/2022, 10:58 PM