salomonbrys
11/13/2020, 12:42 PMpavi2410
11/13/2020, 12:46 PMval PreviewAmbient = ambientOf { false }
@Preview
@Composable
fun MainScreenPreview() {
Providers(PreviewAmbient provides true) {
MainScreen()
}
}
@Composable
fun MainScreen() {
val isInPreview = PreviewAmbient.current
...
}
salomonbrys
11/13/2020, 12:47 PM@Composable val isPreview: Boolean get() = ContextAmbient.current.applicationContext !is Application
?Joost Klitsie
11/13/2020, 1:21 PM@Preview
@Composable
fun MainScreen() {
val viewModel by viewModels()// or however kids these days get their viewmodel
}
@Composable
fun MainScreen() {
val viewModel by viewModels()
MainScreen(viewModel.viewState.collectAsState()) // Or pass in separate arguments
}
@Preview
@Composable
fun MainScreen(viewState: ViewState) {
// display things
}
sindrenm
11/13/2020, 1:33 PM@Preview
should probably be on the first composable, and its function name would need to be different. simple smile