Skip to content

NavigationBar

NavigationBar is a bottom navigation bar component in Miuix, used to create navigation menus fixed at the bottom of applications. It supports 2 to 5 navigation items, offering different display modes (icon only, text only, icon and text, icon with selected label).

FloatingNavigationBar is a floating-style bottom navigation bar component, also supporting 2 to 5 navigation items, offering different display modes.

These components are typically used in conjunction with the Scaffold component to maintain consistent layout and behavior across different pages in the application.

Import

kotlin
import top.yukonga.miuix.kmp.basic.NavigationBar
import top.yukonga.miuix.kmp.basic.NavigationBarItem
import top.yukonga.miuix.kmp.basic.FloatingNavigationBar
import top.yukonga.miuix.kmp.basic.FloatingNavigationBarItem
import top.yukonga.miuix.kmp.basic.NavigationDisplayMode

Basic Usage

The NavigationBar component can be used to create bottom navigation menus fixed to the bottom:

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val items = listOf("Home", "Profile", "Settings")
val icons = listOf(MiuixIcons.VerticalSplit, MiuixIcons.Contacts, MiuixIcons.Settings)

Scaffold(
    bottomBar = {
        NavigationBar {
            items.forEachIndexed { index, label ->
                NavigationBarItem(
                    selected = selectedIndex == index,
                    onClick = { selectedIndex = index },
                    icon = icons[index],
                    label = label
                )
            }
        }
    }
)

FloatingNavigationBar

The FloatingNavigationBar component can be used to create floating navigation menus at the bottom:

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val items = listOf("Home", "Profile", "Settings")
val icons = listOf(MiuixIcons.VerticalSplit, MiuixIcons.Contacts, MiuixIcons.Settings)

Scaffold(
    bottomBar = {
        FloatingNavigationBar(
            mode = NavigationDisplayMode.IconOnly // Show icons only
        ) {
            items.forEachIndexed { index, label ->
                FloatingNavigationBarItem(
                    selected = selectedIndex == index,
                    onClick = { selectedIndex = index },
                    icon = icons[index],
                    label = label
                )
            }
        }
    }
)

Component States

Selected State

Both NavigationBarItem and FloatingNavigationBarItem automatically handle the visual style of the selected item, displaying it with bold text and highlighting the icon/text.

Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to the nav barModifierNo
colorColorBackground color of the nav barMiuixTheme.colorScheme.surfaceNo
showDividerBooleanShow top divider line or nottrueNo
defaultWindowInsetsPaddingBooleanApply default window insets paddingtrueNo
modeNavigationDisplayModeDisplay mode for itemsNavigationDisplayMode.IconAndTextNo
content@Composable RowScope.()The content of the nav bar-Yes
Property NameTypeDescriptionDefault ValueRequired
selectedBooleanWhether the item is selected-Yes
onClick() -> UnitCallback when the item is clicked-Yes
iconImageVectorIcon of the item-Yes
labelStringLabel of the item-Yes
modifierModifierModifier applied to the itemModifierNo
enabledBooleanWhether the item is enabledtrueNo

FloatingNavigationBar Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to the nav barModifierNo
colorColorBackground color of the nav barMiuixTheme.colorScheme.surfaceContainerNo
cornerRadiusDpCorner radius of the nav barFloatingToolbarDefaults.CornerRadiusNo
horizontalAlignmentAlignment.HorizontalHorizontal alignment within its parentCenterHorizontallyNo
horizontalOutSidePaddingDpHorizontal padding outside the nav bar36.dpNo
shadowElevationDpThe shadow elevation of the nav bar1.dpNo
showDividerBooleanShow divider line around the nav barfalseNo
defaultWindowInsetsPaddingBooleanApply default window insets paddingtrueNo
modeNavigationDisplayModeDisplay mode for items (icon/text/both)NavigationDisplayMode.IconOnlyNo
content@Composable RowScope.()The content of the nav bar-Yes

FloatingNavigationBarItem Properties

Property NameTypeDescriptionDefault ValueRequired
selectedBooleanWhether the item is selected-Yes
onClick() -> UnitCallback when the item is clicked-Yes
iconImageVectorIcon of the item-Yes
labelStringLabel of the item-Yes
modifierModifierModifier applied to the itemModifierNo
enabledBooleanWhether the item is enabledtrueNo
ValueDescription
IconAndTextShow both icon and text
IconOnlyShow icon only
TextOnlyShow text only
IconWithSelectedLabelShow icon always, show text only when selected

Advanced Usage

Custom Colors

kotlin
NavigationBar(
    color = Color.Red.copy(alpha = 0.3f)
) {
    // ... items ...
}

Without Divider

kotlin
NavigationBar(
    showDivider = false
) {
    // ... items ...
}

Handling Window Insets

kotlin
NavigationBar(
    defaultWindowInsetsPadding = false // Handle window insets padding manually
) {
    // ... items ...
}

FloatingNavigationBar

Custom Mode (Icon and Text)

kotlin
FloatingNavigationBar(
    mode = NavigationDisplayMode.IconAndText
) {
    // ... items ...
}

Custom Mode (Text Only)

kotlin
FloatingNavigationBar(
    mode = NavigationDisplayMode.TextOnly
) {
    // ... items ...
}

Custom Color and Corner Radius

kotlin
FloatingNavigationBar(
    color = MiuixTheme.colorScheme.primaryContainer,
    cornerRadius = 28.dp,
    mode = NavigationDisplayMode.IconAndText
) {
    // ... items ...
}

Custom Alignment and Padding

kotlin
FloatingNavigationBar(
    horizontalAlignment = Alignment.Start, // Align to start
    horizontalOutSidePadding = 16.dp, // Set outside padding
    mode = NavigationDisplayMode.IconOnly
) {
    // ... items ...
}

Using with Page Navigation (Using Scaffold)

Using NavigationBar

kotlin
val pages = listOf("Home", "Profile", "Settings")
val icons = listOf(MiuixIcons.VerticalSplit, MiuixIcons.Contacts, MiuixIcons.Settings)
var selectedIndex by remember { mutableStateOf(0) }

Scaffold(
    bottomBar = {
        NavigationBar {
            pages.forEachIndexed { index, label ->
                NavigationBarItem(
                    selected = selectedIndex == index,
                    onClick = { selectedIndex = index },
                    icon = icons[index],
                    label = label
                )
            }
        }
    }
) { paddingValues ->
    // Content area needs to consider padding
    Box(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = "Current Page: ${pages[selectedIndex]}",
            style = MiuixTheme.textStyles.title1
        )
    }
}

Using FloatingNavigationBar

kotlin
val pages = listOf("Home", "Profile", "Settings")
val icons = listOf(MiuixIcons.VerticalSplit, MiuixIcons.Contacts, MiuixIcons.Settings)
var selectedIndex by remember { mutableStateOf(0) }

Scaffold(
    bottomBar = {
        FloatingNavigationBar(
            mode = NavigationDisplayMode.IconOnly // Show icons only
        ) {
            pages.forEachIndexed { index, label ->
                FloatingNavigationBarItem(
                    selected = selectedIndex == index,
                    onClick = { selectedIndex = index },
                    icon = icons[index],
                    label = label
                )
            }
        }
    }
) { paddingValues ->
    // Content area needs to consider padding
    Box(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = "Current Page: ${pages[selectedIndex]}",
            style = MiuixTheme.textStyles.title1
        )
    }
}

Changelog

Released under the Apache-2.0 License