Olivier Patry
@Composable fun MainLayout(catRepository: CatRepository = (CatRepository((FakeCatDataSource())))) { val catsViewModel = viewModel<CatsViewModel>(factory = CatsViewModelFactory(catRepository)) Surface(color = MaterialTheme.colors.background) { when { !booleanResource(R.bool.is_tablet) -> MainLayoutTabletPhone(catsViewModel) booleanResource(R.bool.is_portrait) -> MainLayoutTabletPortrait(catsViewModel) else -> MainLayoutTabletLandscape(catsViewModel) } } }
var selected by remmeber { mutableStateOf<MyModel>(null) }
mutableState
var selectedCat by remember { mutableStateOf<CatModel?>(null) }
@Composable
rememberSaveable
if (booleanResource(R.bool.is_tablet)) { var selectedCatUUID by rememberSaveable { mutableStateOf<UUID?>(null) } val selectedCat = selectedCatUUID?.let { uuid -> catsViewModel.findCatByUUID(uuid) } if (booleanResource(R.bool.is_portrait)) { MainLayoutTabletPortrait(catsViewModel, selectedCat) { cat -> selectedCatUUID = cat.uuid } } else { MainLayoutTabletLandscape(catsViewModel, selectedCat) { cat -> selectedCatUUID = cat.uuid } } } else { MainLayoutTabletPhone(catsViewModel) }
A modern programming language that makes developers happier.