From 598d4b4635f185797f1253998d58f6b53a8075b9 Mon Sep 17 00:00:00 2001 From: Dennis BORDET Date: Fri, 11 Oct 2024 14:57:13 +0200 Subject: [PATCH] feat: label place in button --- .../tech/bam/dojo/navbar/BottomNavItem.kt | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/NavBar/src/commonMain/kotlin/tech/bam/dojo/navbar/BottomNavItem.kt b/NavBar/src/commonMain/kotlin/tech/bam/dojo/navbar/BottomNavItem.kt index 67eec24..634cdc7 100644 --- a/NavBar/src/commonMain/kotlin/tech/bam/dojo/navbar/BottomNavItem.kt +++ b/NavBar/src/commonMain/kotlin/tech/bam/dojo/navbar/BottomNavItem.kt @@ -1,13 +1,18 @@ package tech.bam.dojo.navbar +import androidx.compose.animation.animateContentSize +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.RowScope import androidx.compose.material3.Icon import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.NavigationBarItemDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.unit.dp import cafe.adriel.voyager.navigator.tab.Tab import cafe.adriel.voyager.navigator.tab.TabNavigator import tech.bam.dojo.freetimelancetracker.theme.FreetimelanceTrackerColors @@ -18,22 +23,31 @@ fun RowScope.BottomNavItem( navigator: TabNavigator, modifier: Modifier = Modifier, ) { + val isSelected = navigator.current == tab NavigationBarItem( - selected = navigator.current == tab, + selected = isSelected, onClick = { navigator.current = tab }, icon = { tab.options.icon?.let { it: Painter -> - Icon(painter = it, contentDescription = null) + Row( + modifier = Modifier.animateContentSize(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Icon(painter = it, contentDescription = null) + if (isSelected) { + Text( + tab.options.title, + color = FreetimelanceTrackerColors.white, + ) + } + } } }, modifier = modifier, - label = { - Text( - tab.options.title, - ) - }, + label = null, alwaysShowLabel = false, colors = NavigationBarItemDefaults.colors(