Skip to content

Commit

Permalink
feat: label place in button
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisbordet committed Oct 11, 2024
1 parent 4becc42 commit 598d4b4
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions NavBar/src/commonMain/kotlin/tech/bam/dojo/navbar/BottomNavItem.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 598d4b4

Please sign in to comment.