From be31b0abba55dfbd91eb660f3ec3fdcad7ee03ef Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Mon, 12 Sep 2022 11:08:29 +0200 Subject: [PATCH] [#254] Review: Simplify code by removing private methods --- .../ComponentBottomNavigation.kt | 76 ++++++++----------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt index ca422784c..ab599ae9e 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt @@ -19,7 +19,6 @@ import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.Icon import androidx.compose.material.rememberBottomSheetScaffoldState import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable @@ -45,39 +44,6 @@ private object ComponentBottomNavigation { @Composable @ExperimentalMaterialApi fun ComponentBottomNavigation() { - val selectedNavigationItemCount = rememberSaveable { mutableStateOf(MinNavigationItemCount) } - - ComponentCustomizationBottomSheetScaffold( - bottomSheetScaffoldState = rememberBottomSheetScaffoldState(), - bottomSheetContent = { - BottomNavigationCustomizationContent(selectedNavigationItemCount = selectedNavigationItemCount) - }) { - Column( - modifier = Modifier.fillMaxSize(), - verticalArrangement = Arrangement.Center - ) { - ComponentBottomNavigationBottomBar( - selectedNavigationItemCount = selectedNavigationItemCount - ) - } - } -} - -@Composable -private fun BottomNavigationCustomizationContent(selectedNavigationItemCount: MutableState) { - ComponentCountRow( - modifier = Modifier - .padding(horizontal = dimensionResource(id = R.dimen.ods_screen_horizontal_margin)) - .padding(bottom = dimensionResource(id = R.dimen.spacing_m)), - title = stringResource(id = R.string.component_bottom_navigation_navigation_item_count), - count = selectedNavigationItemCount, - minCount = MinNavigationItemCount, - maxCount = MaxNavigationItemCount - ) -} - -@Composable -private fun ComponentBottomNavigationBottomBar(selectedNavigationItemCount: MutableState) { val context = LocalContext.current val navigationItems = listOf( NavigationItem("Favorites", R.drawable.ic_heart), @@ -87,21 +53,41 @@ private fun ComponentBottomNavigationBottomBar(selectedNavigationItemCount: Muta NavigationItem("Settings", R.drawable.ic_settings) ) + val selectedNavigationItemCount = rememberSaveable { mutableStateOf(MinNavigationItemCount) } val selectedNavigationItem = remember { mutableStateOf(navigationItems[0]) } - OdsBottomNavigation { - navigationItems.take(selectedNavigationItemCount.value) - .forEach { navigationItem -> - OdsBottomNavigationItem( - icon = { Icon(painter = painterResource(id = navigationItem.icon), contentDescription = null) }, - label = navigationItem.title, - selected = selectedNavigationItem.value.title == navigationItem.title, - onClick = { - selectedNavigationItem.value = navigationItem - clickOnElement(context, navigationItem.title) + ComponentCustomizationBottomSheetScaffold( + bottomSheetScaffoldState = rememberBottomSheetScaffoldState(), + bottomSheetContent = { + ComponentCountRow( + modifier = Modifier + .padding(horizontal = dimensionResource(id = R.dimen.ods_screen_horizontal_margin)) + .padding(bottom = dimensionResource(id = R.dimen.spacing_m)), + title = stringResource(id = R.string.component_bottom_navigation_navigation_item_count), + count = selectedNavigationItemCount, + minCount = MinNavigationItemCount, + maxCount = MaxNavigationItemCount + ) + }) { + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center + ) { + OdsBottomNavigation { + navigationItems.take(selectedNavigationItemCount.value) + .forEach { navigationItem -> + OdsBottomNavigationItem( + icon = { Icon(painter = painterResource(id = navigationItem.icon), contentDescription = null) }, + label = navigationItem.title, + selected = selectedNavigationItem.value.title == navigationItem.title, + onClick = { + selectedNavigationItem.value = navigationItem + clickOnElement(context, navigationItem.title) + } + ) } - ) } + } } }