Skip to content

Scaffold

Scaffold is a scaffolding component in Miuix used to implement basic design layout structures. It provides the fundamental framework for application interfaces, including containers for top bars, bottom bars, floating action buttons, and other elements.

WARNING

The Scaffold component provides a suitable container for cross-platform popup windows. Components such as SuperDialog, SuperDropdown, SuperSpinner, and ListPopup are all implemented based on this and therefore need to be wrapped by this component.

INFO

Why not use the official Popup and Dialog instead of creating our own popup window container? Because their cross-platform support is currently incomplete, with some parameters that cannot be modified.

Import

kotlin
import top.yukonga.miuix.kmp.basic.Scaffold

Basic Usage

The Scaffold component can be used to build a page layout with a top bar:

kotlin
Scaffold(
    topBar = {
        SmallTopAppBar(title = "Title" )
    },
    content = { paddingValues ->
        // The content area needs to consider padding
        Box(
            modifier = Modifier
                .padding(top = paddingValues.calculateTopPadding(), start = 26.dp)
                .fillMaxSize()
        ) {
            Text("Content Area")
        }
    }
)

Properties

Scaffold Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to the scaffoldModifierNo
topBar@Composable () -> UnitTop bar, usually a TopAppBar{}No
bottomBar@Composable () -> UnitBottom bar, usually a NavigationBar{}No
floatingActionButton@Composable () -> UnitFloating action button{}No
floatingActionButtonPositionFabPositionPosition to display the floating action buttonFabPosition.EndNo
floatingToolbar@Composable () -> UnitFloating toolbar{}No
floatingToolbarPositionToolbarPositionPosition to display the floating toolbarToolbarPosition.BottomCenterNo
snackbarHost@Composable () -> UnitContainer for displaying Snackbar, Miuix does not provide this component{}No
popupHost@Composable () -> UnitContainer for displaying popup windows{ MiuixPopupHost() }No
containerColorColorBackground color of the scaffoldMiuixTheme.colorScheme.backgroundNo
contentWindowInsetsWindowInsetsWindow insets passed to the contentWindowInsets.statusBarsNo
content@Composable (PaddingValues) -> UnitMain content area of the scaffold-Yes

FabPosition Options

Option NameDescription
StartPlaces the floating action button at the bottom left of the screen, above the bottom bar
CenterPlaces the floating action button at the bottom center of the screen, above the bottom bar
EndPlaces the floating action button at the bottom right of the screen, above the bottom bar
EndOverlayPlaces the floating action button at the bottom right of the screen, overlaying the bottom bar

ToolbarPosition Options

Option NameDescription
TopStartPlaces the floating toolbar at the top start corner
CenterStartPlaces the floating toolbar vertically centered on the start edge
BottomStartPlaces the floating toolbar at the bottom start corner
TopEndPlaces the floating toolbar at the top end corner
CenterEndPlaces the floating toolbar vertically centered on the end edge
BottomEndPlaces the floating toolbar at the bottom end corner
TopCenterPlaces the floating toolbar horizontally centered at the top edge
BottomCenterPlaces the floating toolbar horizontally centered at the bottom edge

Advanced Usage

Page Layout with Top Bar and Bottom Bar

kotlin
val topAppBarScrollBehavior = MiuixScrollBehavior(rememberTopAppBarState())

Scaffold(
    topBar = {
        TopAppBar(
            title = "Title",
            navigationIcon = {
                IconButton(onClick = { /* Handle navigation click */ }) {
                    Icon(MiuixIcons.Useful.Back, contentDescription = "Back")
                }
            },
            scrollBehavior = topAppBarScrollBehavior
        )
    },
    bottomBar = {
        val items = listOf(
            NavigationItem("Home", MiuixIcons.Useful.NavigatorSwitch),
            NavigationItem("Settings", MiuixIcons.Useful.Settings)
        )
        var selectedItem by remember { mutableStateOf(0) }
        NavigationBar(
            items = items,
            selected = selectedItem,
            onClick = { index ->
                selectedItem = index
            },
        )
    },
    content = { paddingValues ->
        // The content area needs to consider padding
        LazyColumn(
            contentPadding = paddingValues,
            modifier = Modifier
                .fillMaxSize()
                // Bind the scroll behavior of the top bar
                .nestedScroll(topAppBarScrollBehavior.nestedScrollConnection)
        ) {
            items(20) { index ->
                SuperArrow(
                    title = "Item $index",
                    onClick = { /* Handle click */ }
                )
                if (index < 19) HorizontalDivider()
            }
        }
    }
)

Page Layout with Floating Action Button

kotlin
Scaffold(
    topBar = {
        SmallTopAppBar(title = "Title")
    },
    floatingActionButton = {
        FloatingActionButton(
            onClick = { /* Handle click event */ }
        ) {
            Icon(MiuixIcons.Useful.New, contentDescription = "Add")
        }
    },
    floatingActionButtonPosition = FabPosition.End,
    content = { paddingValues ->
        // The content area needs to consider padding
        Box(
            modifier = Modifier
                .padding(top = paddingValues.calculateTopPadding(), start = 26.dp)
                .fillMaxSize()
        ) {
               Text("Click the button in the bottom right corner to add content")
        }
    }
)

Page Layout with Snackbar (requires Material components)

kotlin
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()

Scaffold(
    snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
    topBar = {
        SmallTopAppBar(title = "Title")
    },
    floatingActionButton = {
        FloatingActionButton(
            onClick = {
                scope.launch {
                    snackbarHostState.showSnackbar("This is a message!")
                }
            }
        ) {
            Icon(MiuixIcons.Useful.Info, contentDescription = "Show message")
        }
    },
    content = { paddingValues ->
        // The content area needs to consider padding
        Box(
            modifier = Modifier
                .padding(top = paddingValues.calculateTopPadding(), start = 26.dp)
                .fillMaxSize()
        ) {
            Text("Click the button to show Snackbar")
        }
    }
)

Custom Window Insets

kotlin
Scaffold(
    contentWindowInsets = WindowInsets.systemBars,
    topBar = {
        SmallTopAppBar(title = "Title")
    },
    content = { paddingValues ->
        // The content area needs to consider padding
        Box(
            modifier = Modifier
                .padding(top = paddingValues.calculateTopPadding(), start = 26.dp)
                .fillMaxSize()
        ) {
            Text("Content area considering system bars")
        }
    }
)

Released under the Apache-2.0 License