From e624783cec5e465d5f0ead5099c9605308c6afef Mon Sep 17 00:00:00 2001 From: Tin Pham <72054441+tinpham5614@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:22:24 -0800 Subject: [PATCH] belinda-closet-android-product-menu-dropdown-01 (#213) * add product menu dropdown * using drawerState instead of expand --------- Co-authored-by: E. Brink <80282265+brinkbrink@users.noreply.github.com> --- .../belindas_closet/screen/ProductDetail.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt b/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt index 9ad0ee35..2c2c3b84 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt @@ -17,6 +17,8 @@ import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Menu import androidx.compose.material3.Card import androidx.compose.material3.DrawerValue +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -41,6 +43,7 @@ import com.example.belindas_closet.R import com.example.belindas_closet.Routes import com.example.belindas_closet.data.Datasource import com.example.belindas_closet.model.Product +import com.example.belindas_closet.model.ProductType @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -84,6 +87,9 @@ fun ProductDetailPage(navController: NavController) { ) { Icon(imageVector = Icons.Default.Menu, contentDescription = "Menu") } + DropDownCategoryList(drawerState, navController) { + drawerState = DrawerValue.Closed + } } ) }, @@ -158,5 +164,27 @@ fun ProductDetailList(products: List, navController: NavController) { } } } +@Composable +fun DropDownCategoryList(drawerState: DrawerValue, navController: NavController, onDismissRequest: () -> Unit = {}) { + DropdownMenu( + drawerState == DrawerValue.Open, + onDismissRequest = onDismissRequest, + modifier = Modifier + .padding(8.dp) + ) { + ProductType.values().forEach { productType -> + DropdownMenuItem( + text = { Text(productType.type) }, + onClick = { + onDismissRequest() + // navigate to product type page + MainActivity.setProductType(productType.type) + navController.navigate( + Routes.ProductDetail.route) + } + ) + } + } +}