Tom De Decker
04/27/2023, 10:26 AMval tabs = if (configuration.isExpanded) {
// Tablet/landscape mode
listOf(
TabType.Foo,
TabType.Bar,
)
} else {
// Phone/portrait mode
listOf(
TabType.Foo,
TabType.Bar,
TabType.MoreInfo,
)
}
Is this something I'd better avoid? If so, what would a better pattern to handle this be?
In practice, the list of tabs is a StateFlow which is collected by a composable, but conceptionally this shouldn't really make a difference.Otávio Gabriel (Tavieto)
04/27/2023, 9:37 PMval config = LocalConfiguration.current
val myList = when (config.orientation) {
androidx.compose.foundation.gestures.Orientation.Vertical.ordinal -> viewModel.listPortrait
else -> viewModel.listLandscape
}
Tom De Decker
04/28/2023, 8:53 AMOtávio Gabriel (Tavieto)
04/28/2023, 2:52 PMvar indexPortrait by rememberSaveable { mutableStateOf(0) }
var indexLandscape by rememberSaveable { mutableStateOf(0) }
val index by remember(indexPortrait, indexLanscape) {
mutableStateOf(
when (config.orientation) {
androidx.compose.foundation.gestures.Orientation.Vertical.ordinal -> indexPortrait
else -> indexLandscape
}
)
}
Colin T
04/30/2023, 10:27 PMvar myOrientation by remember{ mutableStateOf(Configuration.ORIENTATION_PORTRAIT) }
LaunchedEffect(configuration) {
// Save any changes to the orientation value on the configuration object
snapshotFlow { configuration.orientation }
.collectLatest { myOrientation = it }
}
when(myOrientation){
Configuration.ORIENTATION_LANDSCAPE -> {
YourComposable(navController)
}
else -> { ......