jetpack compose
搭建地铁系统页面
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
viewModel: HomeViewModel = viewModel(factory = AppViewModelProvider.Factory)
) {
SideEffect {
viewModel.findMetroSystems()
}
val tabTitles = listOf(stringResource(id = R.string.route), stringResource(id = R.string.line))
var selectedTab by remember { mutableIntStateOf(0) }
Column(
modifier = Modifier
) {
MetroSystemSelection(
metroSystemList = viewModel.metroSystems.value,
selectedMetroSystem = viewModel.selectedMetroSystem.value,
selectMetroSystem = viewModel::selectMetroSystem
)
TabRow(selectedTabIndex = selectedTab) {
Tab(selected = (selectedTab == 0),
onClick = {
selectedTab = 0
viewModel.clearMetroStations()
},
text = { Text(text = tabTitles[0]) }
)
Tab(
selected = (selectedTab == 1),
onClick = {
selectedTab = 1
viewModel.clearMetroStations()
},
text = { Text(text = tabTitles[1]) }
)
}
Column(
modifier = Modifier
.padding(10.dp)
.fillMaxHeight(),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
when (selectedTab) {
0 -> RouteTabContent(viewModel = viewModel)
1 -> LineTabContent(viewModel = viewModel)
}
// MetroStationList(
// metroStations = viewModel.metroStations.value
// )
}
}
}
标签:selectedTab,text,viewModel,tabTitles,value,stringResource,5.11
From: https://www.cnblogs.com/258-333/p/18187368