Composable Component

SmallFloatingActionButton

The FAB represents the most important action on a screen.

SmallFloatingActionButton social preview

AnimatedFloatingActionButtonSample

@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
@Preview
@Composable
fun AnimatedFloatingActionButtonSample() {
    val listState = rememberLazyListState()
    // The FAB is initially shown. Upon scrolling past the first item we hide the FAB by using a
    // remembered derived state to minimize unnecessary compositions.
    val fabVisible by remember { derivedStateOf { listState.firstVisibleItemIndex == 0 } }
    Scaffold(
        floatingActionButton = {
            // A FAB should have a tooltip associated with it.
            TooltipBox(
                positionProvider =
                    TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
                tooltip = { PlainTooltip { Text("Localized description") } },
                state = rememberTooltipState(),
            ) {
                MediumFloatingActionButton(
                    modifier =
                        Modifier.animateFloatingActionButton(
                            visible = fabVisible,
                            alignment = Alignment.BottomEnd,
                        ),
                    onClick = { /* do something */ },
                ) {
                    Icon(
                        Icons.Filled.Add,
                        contentDescription = "Localized description",
                        modifier = Modifier.size(FloatingActionButtonDefaults.MediumIconSize),
                    )
                }
            }
        },
        floatingActionButtonPosition = FabPosition.End,
    ) {
        LazyColumn(state = listState, modifier = Modifier.fillMaxSize()) {
            for (index in 0 until 100) {
                item { Text(text = "List item - $index", modifier = Modifier.padding(24.dp)) }
            }
        }
    }
}

SmallFloatingActionButtonSample

@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
fun SmallFloatingActionButtonSample() {
    // A FAB should have a tooltip associated with it.
    TooltipBox(
        positionProvider =
            TooltipDefaults.rememberTooltipPositionProvider(TooltipAnchorPosition.Above),
        tooltip = { PlainTooltip { Text("Localized description") } },
        state = rememberTooltipState(),
    ) {
        SmallFloatingActionButton(onClick = { /* do something */ }) {
            Icon(Icons.Filled.Add, contentDescription = "Localized description")
        }
    }
}