5.11

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
//            )
        }
    }


}

posted @ 2024-05-11 23:27  258333  阅读(16)  评论(0编辑  收藏  举报