Top Bar

TopBar

A customizable top app bar that supports different scroll behaviors and layouts.


Installation

./gradlew lumo --add TopBar

Usage

Basic TopBar

TopBar {
    Text(
        text = "Title",
        style = AppTheme.typography.h3,
        modifier = Modifier.align(Alignment.Center)
    )
}

Scrollable TopBar

val scrollBehavior = TopBarDefaults.enterAlwaysScrollBehavior()
 
Scaffold(
    topBar = {
        TopBar(
            scrollBehavior = scrollBehavior,
            colors = TopBarColors(
                containerColor = AppTheme.colors.surface,
                scrolledContainerColor = AppTheme.colors.surfaceVariant
            )
        ) {
            Text("Scrollable Title")
        }
    }
) { padding ->
    LazyColumn(
        modifier = Modifier
            .fillMaxWidth()
            .nestedScroll(scrollBehavior.nestedScrollConnection),
        contentPadding = padding
    ) {
        items(30) {
            Card(
                modifier = Modifier
                    .fillMaxWidth()
                    .padding(8.dp)
            ) {
                Spacer(modifier = Modifier.height(60.dp))
            }
        }
    }
}
 

API Documentation

TopBar Parameters

ParameterTypeDescription
modifierModifierModifier for the top bar
scrollBehaviorTopBarScrollBehavior?Controls scroll behavior
colorsTopBarColorsColors for different states
windowInsetsWindowInsets?Window insets for the top bar
content@Composable () -> UnitContent of the top bar

Scroll Behaviors

BehaviorDescription
pinnedScrollBehaviorTopBar stays fixed while scrolling
enterAlwaysScrollBehaviorTopBar scrolls with content
exitUntilCollapsedScrollBehaviorTopBar collapses until minimum height