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, each containing an icon and a text label.

FloatingNavigationBar is a floating-style bottom navigation bar component, also supporting 2 to 5 navigation items, offering different display modes (icon only, text only, icon and text).

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.FloatingNavigationBar
import top.yukonga.miuix.kmp.basic.FloatingNavigationBarMode
import top.yukonga.miuix.kmp.basic.NavigationItem

Basic Usage

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

kotlin
val items = listOf(
    NavigationItem("Home", MiuixIcons.Useful.NavigatorSwitch),
    NavigationItem("Profile", MiuixIcons.Useful.Personal),
    NavigationItem("Settings", MiuixIcons.Useful.Settings)
)
var selectedIndex by remember { mutableStateOf(0) }

Scaffold(
    bottomBar = {
        NavigationBar(
            items = items,
            selected = selectedIndex,
            onClick = { selectedIndex = it }
        )
    }
)

FloatingNavigationBar

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

kotlin
val items = listOf(
    NavigationItem("Home", MiuixIcons.Useful.NavigatorSwitch),
    NavigationItem("Profile", MiuixIcons.Useful.Personal),
    NavigationItem("Settings", MiuixIcons.Useful.Settings)
)
var selectedIndex by remember { mutableStateOf(0) }

Scaffold(
    bottomBar = {
        FloatingNavigationBar(
            items = items,
            selected = selectedIndex,
            onClick = { selectedIndex = it },
            mode = FloatingNavigationBarMode.IconOnly // Show icons only
        )
    }
)

Component States

Selected State

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

Properties

Property NameTypeDescriptionDefault ValueRequired
itemsList<NavigationItem>List of navigation items (2-5)-Yes
selectedIntIndex of the current selected item-Yes
onClick(Int) -> UnitCallback when clicking nav items-Yes
modifierModifierModifier applied to the nav barModifierNo
colorColorBackground color of the nav barMiuixTheme.colorScheme.surfaceContainerNo
showDividerBooleanShow top divider line or nottrueNo
defaultWindowInsetsPaddingBooleanApply default window insets paddingtrueNo

FloatingNavigationBar Properties

Property NameTypeDescriptionDefault ValueRequired
itemsList<NavigationItem>List of navigation items (2-5)-Yes
selectedIntIndex of the current selected item-Yes
onClick(Int) -> UnitCallback when clicking nav items-Yes
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
modeFloatingNavigationBarModeDisplay mode for items (icon/text/both)FloatingNavigationBarMode.IconOnlyNo
Property NameTypeDescriptionDefault ValueRequired
labelStringText label of nav item-Yes
iconImageVectorIcon of navigation item-Yes

FloatingNavigationBarMode Enum

ValueDescription
IconAndTextShow icon and text
IconOnlyShow icon only
TextOnlyShow text only

Advanced Usage

Custom Colors

kotlin
// ... items and selectedIndex defined ...
NavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    color = Color.Red.copy(alpha = 0.3f)
)

Without Divider

kotlin
// ... items and selectedIndex defined ...
NavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    showDivider = false
)

Handling Window Insets

kotlin
// ... items and selectedIndex defined ...
NavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    defaultWindowInsetsPadding = false // Handle window insets padding manually
)

FloatingNavigationBar

Custom Mode (Icon and Text)

kotlin
// ... items and selectedIndex defined ...
FloatingNavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    mode = FloatingNavigationBarMode.IconAndText
)

Custom Mode (Text Only)

kotlin
// ... items and selectedIndex defined ...
FloatingNavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    mode = FloatingNavigationBarMode.TextOnly
)

Custom Color and Corner Radius

kotlin
// ... items and selectedIndex defined ...
FloatingNavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    color = MiuixTheme.colorScheme.primaryContainer,
    cornerRadius = 28.dp,
    mode = FloatingNavigationBarMode.IconAndText
)

Custom Alignment and Padding

kotlin
// ... items and selectedIndex defined ...
FloatingNavigationBar(
    items = items,
    selected = selectedIndex,
    onClick = { selectedIndex = it },
    horizontalAlignment = Alignment.Start, // Align to start
    horizontalOutSidePadding = 16.dp, // Set outside padding
    mode = FloatingNavigationBarMode.IconOnly
)

Using with Page Navigation (Using Scaffold)

Using NavigationBar

kotlin
val pages = listOf("Home", "Profile", "Settings")
val items = listOf(
    NavigationItem("Home", MiuixIcons.Useful.NavigatorSwitch),
    NavigationItem("Profile", MiuixIcons.Useful.Personal),
    NavigationItem("Settings", MiuixIcons.Useful.Settings)
)
var selectedIndex by remember { mutableStateOf(0) }

Scaffold(
    bottomBar = {
        NavigationBar(
            items = items,
            selected = selectedIndex,
            onClick = { selectedIndex = it }
        )
    }
) { 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 items = listOf(
    NavigationItem("Home", MiuixIcons.Useful.NavigatorSwitch),
    NavigationItem("Profile", MiuixIcons.Useful.Personal),
    NavigationItem("Settings", MiuixIcons.Useful.Settings)
)
var selectedIndex by remember { mutableStateOf(0) }

Scaffold(
    bottomBar = {
        FloatingNavigationBar(
            items = items,
            selected = selectedIndex,
            onClick = { selectedIndex = it },
            mode = FloatingNavigationBarMode.IconOnly // Show icons only
        )
    }
) { 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
        )
    }
}

Released under the Apache-2.0 License