From 9343cd67e2e216d4f84cc5c224f6ed88340aa5ac Mon Sep 17 00:00:00 2001 From: hongxiang Date: Thu, 4 Aug 2022 18:32:59 +0800 Subject: [PATCH] feat: AssetDisplayScreen use navigateToDropDown instead of navController as parameter --- .../java/com/huhx/picker/data/AssetRoute.kt | 2 +- .../huhx/picker/view/AssetDisplayScreen.kt | 53 +++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/compose_image_picker/src/main/java/com/huhx/picker/data/AssetRoute.kt b/compose_image_picker/src/main/java/com/huhx/picker/data/AssetRoute.kt index e5c27f6..11886bc 100644 --- a/compose_image_picker/src/main/java/com/huhx/picker/data/AssetRoute.kt +++ b/compose_image_picker/src/main/java/com/huhx/picker/data/AssetRoute.kt @@ -27,7 +27,7 @@ fun AssetPickerRoute( composable("asset_display") { AssetDisplayScreen( viewModel = viewModel, - navController = navController, + navigateToDropDown = { navController.navigate("asset_selector?directory=$it") }, onPicked = onPicked, onClose = onClose, ) diff --git a/compose_image_picker/src/main/java/com/huhx/picker/view/AssetDisplayScreen.kt b/compose_image_picker/src/main/java/com/huhx/picker/view/AssetDisplayScreen.kt index 10455f5..5324d7c 100644 --- a/compose_image_picker/src/main/java/com/huhx/picker/view/AssetDisplayScreen.kt +++ b/compose_image_picker/src/main/java/com/huhx/picker/view/AssetDisplayScreen.kt @@ -50,7 +50,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import androidx.navigation.NavHostController import coil.compose.AsyncImage import coil.decode.VideoFrameDecoder import coil.request.ImageRequest @@ -68,7 +67,7 @@ import kotlinx.coroutines.launch @Composable fun AssetDisplayScreen( viewModel: AssetViewModel, - navController: NavHostController, + navigateToDropDown: (String) -> Unit, onPicked: (List) -> Unit, onClose: (List) -> Unit, ) { @@ -79,7 +78,7 @@ fun AssetDisplayScreen( directory = directory, selectedList = viewModel.selectedList, navigateUp = onClose, - navigateToDropDown = { navController.navigate("asset_selector?directory=$directory") } + navigateToDropDown = navigateToDropDown ) }, bottomBar = { DisplayBottomBar(viewModel, onPicked) } @@ -100,6 +99,30 @@ fun AssetDisplayScreen( } } +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun DisplayTopAppBar( + directory: String, + selectedList: List, + navigateUp: (List) -> Unit, + navigateToDropDown: (String) -> Unit, +) { + CenterAlignedTopAppBar( + modifier = Modifier.statusBarsPadding(), + navigationIcon = { + IconButton(onClick = { navigateUp(selectedList) }) { + Icon(Icons.Filled.Close, contentDescription = "") + } + }, + title = { + Row(modifier = Modifier.clickable { navigateToDropDown(directory) }) { + Text(directory, fontSize = 18.sp) + Icon(Icons.Default.KeyboardArrowDown, contentDescription = "") + } + }, + ) +} + @Composable private fun DisplayBottomBar( viewModel: AssetViewModel, @@ -155,30 +178,6 @@ private fun DisplayBottomBar( } } -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun DisplayTopAppBar( - directory: String, - selectedList: List, - navigateUp: (List) -> Unit, - navigateToDropDown: () -> Unit, -) { - CenterAlignedTopAppBar( - modifier = Modifier.statusBarsPadding(), - navigationIcon = { - IconButton(onClick = { navigateUp(selectedList) }) { - Icon(Icons.Filled.Close, contentDescription = "") - } - }, - title = { - Row(modifier = Modifier.clickable { navigateToDropDown() }) { - Text(directory, fontSize = 18.sp) - Icon(Icons.Default.KeyboardArrowDown, contentDescription = "") - } - }, - ) -} - @OptIn(ExperimentalPagerApi::class) @Composable private fun AssetTab(