Object

FloatingToolbarDefaults

Contains default values used for the floating toolbar implementations.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Common
@ExperimentalMaterial3ExpressiveApi
object FloatingToolbarDefaults

Contains default values used for the floating toolbar implementations.

Properties

Common
val ContainerSize: Dp

Default size used for HorizontalFloatingToolbar and VerticalFloatingToolbar container

Common
val ContainerExpandedElevation: Dp =  // TODO read from token

Default expanded elevation used for HorizontalFloatingToolbar and VerticalFloatingToolbar

Common
val ContainerCollapsedElevation: Dp =  // TODO read from token

Default collapsed elevation used for HorizontalFloatingToolbar and VerticalFloatingToolbar

Common
val ContainerExpandedElevationWithFab: Dp =  // TODO read from token

Default expanded elevation used for HorizontalFloatingToolbar and VerticalFloatingToolbar with FAB.

This elevation will only affect the toolbar part of the component. The FAB that is provided in a slot will have its own elevation and can be controlled independently.

Common
val ContainerCollapsedElevationWithFab: Dp =  // TODO read from token

Default collapsed elevation used for HorizontalFloatingToolbar and VerticalFloatingToolbar with FAB.

This elevation will only affect the toolbar part of the component. The FAB that is provided in a slot will have its own elevation and can be controlled independently.

Common
val ContainerShape: Shape

Default shape used for HorizontalFloatingToolbar and VerticalFloatingToolbar

Common
val ContentPadding =
    PaddingValues(
        start = FloatingToolbarTokens.ContainerLeadingSpace,
        top = FloatingToolbarTokens.ContainerLeadingSpace,
        end = FloatingToolbarTokens.ContainerTrailingSpace,
        bottom = FloatingToolbarTokens.ContainerTrailingSpace,
    )

Default padding used for HorizontalFloatingToolbar and VerticalFloatingToolbar when content are default size (24dp) icons in IconButton that meet the minimum touch target (48.dp).

Common
val ScreenOffset = FloatingToolbarTokens.ContainerExternalPadding

Default offset from the edge of the screen used for HorizontalFloatingToolbar and VerticalFloatingToolbar.

Common
val ScrollDistanceThreshold: Dp

A default threshold in Dp for the content's scrolling that defines when the toolbar should be collapsed or expanded.

Functions

animationSpec

@Composable
    fun <T> animationSpec(): FiniteAnimationSpec<T>

Returns a default animation spec used for HorizontalFloatingToolbars and VerticalFloatingToolbars.


exitAlwaysScrollBehavior

@ExperimentalMaterial3ExpressiveApi
    @Composable
    fun exitAlwaysScrollBehavior(
        exitDirection: FloatingToolbarExitDirection,
        state: FloatingToolbarState = rememberFloatingToolbarState(),
        snapAnimationSpec: AnimationSpec<Float> = MotionSchemeKeyTokens.DefaultEffects.value(),
        flingAnimationSpec: DecayAnimationSpec<Float> = rememberSplineBasedDecay(),
    ): FloatingToolbarScrollBehavior

Returns a FloatingToolbarScrollBehavior. A floating toolbar that is set up with this FloatingToolbarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.

Parameters

exitDirection indicates the direction towards which the floating toolbar exits the screen
state the state object to be used to control or observe the floating toolbar's scroll state. See rememberFloatingToolbarState for a state that is remembered across compositions.
snapAnimationSpec an AnimationSpec that defines how the floating toolbar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position
flingAnimationSpec an DecayAnimationSpec that defines how to fling the floating app bar when the user flings the toolbar itself, or the content below it

horizontalEnterTransition

@Composable
    fun horizontalEnterTransition(expandFrom: Alignment.Horizontal) =
        expandHorizontally(animationSpec = animationSpec(), expandFrom = expandFrom)

Default enter transition used for HorizontalFloatingToolbar when expanding


verticalEnterTransition

@Composable
    fun verticalEnterTransition(expandFrom: Alignment.Vertical) =
        expandVertically(animationSpec = animationSpec(), expandFrom = expandFrom)

Default enter transition used for VerticalFloatingToolbar when expanding


horizontalExitTransition

@Composable
    fun horizontalExitTransition(shrinkTowards: Alignment.Horizontal) =
        shrinkHorizontally(animationSpec = animationSpec(), shrinkTowards = shrinkTowards)

Default exit transition used for HorizontalFloatingToolbar when shrinking


verticalExitTransition

@Composable
    fun verticalExitTransition(shrinkTowards: Alignment.Vertical) =
        shrinkVertically(animationSpec = animationSpec(), shrinkTowards = shrinkTowards)

Default exit transition used for VerticalFloatingToolbar when shrinking


standardFloatingToolbarColors

@Composable
    fun standardFloatingToolbarColors(): FloatingToolbarColors

Creates a FloatingToolbarColors that represents the default standard colors used in the various floating toolbars.


vibrantFloatingToolbarColors

@Composable
    fun vibrantFloatingToolbarColors(): FloatingToolbarColors

Creates a FloatingToolbarColors that represents the default vibrant colors used in the various floating toolbars.


standardFloatingToolbarColors

@Composable
    fun standardFloatingToolbarColors(
        toolbarContainerColor: Color = Color.Unspecified,
        toolbarContentColor: Color = Color.Unspecified,
        fabContainerColor: Color = Color.Unspecified,
        fabContentColor: Color = Color.Unspecified,
    ): FloatingToolbarColors

Creates a FloatingToolbarColors that represents the default standard colors used in the various floating toolbars.

Parameters

toolbarContainerColor the container color for the floating toolbar.
toolbarContentColor the content color for the floating toolbar.
fabContainerColor the container color for an adjacent floating action button.
fabContentColor the content color for an adjacent floating action button.

vibrantFloatingToolbarColors

@Composable
    fun vibrantFloatingToolbarColors(
        toolbarContainerColor: Color = Color.Unspecified,
        toolbarContentColor: Color = Color.Unspecified,
        fabContainerColor: Color = Color.Unspecified,
        fabContentColor: Color = Color.Unspecified,
    ): FloatingToolbarColors

Creates a FloatingToolbarColors that represents the default vibrant colors used in the various floating toolbars.

Parameters

toolbarContainerColor the container color for the floating toolbar.
toolbarContentColor the content color for the floating toolbar.
fabContainerColor the container color for an adjacent floating action button.
fabContentColor the content color for an adjacent floating action button.

VibrantFloatingActionButton

@Composable
    fun VibrantFloatingActionButton(
        onClick: () -> Unit,
        modifier: Modifier = Modifier,
        shape: Shape = FloatingActionButtonDefaults.shape,
        containerColor: Color = vibrantFloatingToolbarColors().fabContainerColor,
        contentColor: Color = vibrantFloatingToolbarColors().fabContentColor,
        interactionSource: MutableInteractionSource? = null,
        content: @Composable () -> Unit,
    ) =
        FloatingActionButton(
            onClick = onClick,
            modifier = modifier.fillMaxSize(),
            shape = shape,
            containerColor = containerColor,
            contentColor = contentColor,
            elevation =
                FloatingActionButtonDefaults.elevation(
                    defaultElevation = ElevationTokens.Level2,
                    pressedElevation = ElevationTokens.Level2,
                    focusedElevation = ElevationTokens.Level2,
                    hoveredElevation = ElevationTokens.Level3,
                ),
            interactionSource = interactionSource,
            content = content,
        )

Creates a FloatingActionButton that represents a toolbar floating action button with vibrant colors.

The FAB's elevation and size will be controlled by the floating toolbar, so it's applied with a Modifier.fillMaxSize.

Parameters

onClick called when this FAB is clicked
modifier the Modifier to be applied to this FAB
shape defines the shape of this FAB's container and shadow
containerColor the color used for the background of this FAB. Defaults to the FloatingToolbarColors.fabContainerColor from the vibrantFloatingToolbarColors.
contentColor the preferred color for content inside this FAB. Defaults to the FloatingToolbarColors.fabContentColor from the vibrantFloatingToolbarColors.
interactionSource an optional hoisted MutableInteractionSource for observing and emitting Interactions for this FAB. You can use this to change the FAB's appearance or preview the FAB in different states. Note that if null is provided, interactions will still happen internally.
content the content of this FAB, typically an Icon

StandardFloatingActionButton

@Composable
    fun StandardFloatingActionButton(
        onClick: () -> Unit,
        modifier: Modifier = Modifier,
        shape: Shape = FloatingActionButtonDefaults.shape,
        containerColor: Color = standardFloatingToolbarColors().fabContainerColor,
        contentColor: Color = standardFloatingToolbarColors().fabContentColor,
        interactionSource: MutableInteractionSource? = null,
        content: @Composable () -> Unit,
    ) =
        FloatingActionButton(
            onClick = onClick,
            modifier = modifier.fillMaxSize(),
            shape = shape,
            containerColor = containerColor,
            contentColor = contentColor,
            elevation =
                FloatingActionButtonDefaults.elevation(
                    defaultElevation = ElevationTokens.Level2,
                    pressedElevation = ElevationTokens.Level2,
                    focusedElevation = ElevationTokens.Level2,
                    hoveredElevation = ElevationTokens.Level3,
                ),
            interactionSource = interactionSource,
            content = content,
        )

Creates a FloatingActionButton that represents a toolbar floating action button with standard colors.

The FAB's elevation and size will be controlled by the floating toolbar, so it's applied with a Modifier.fillMaxSize.

Parameters

onClick called when this FAB is clicked
modifier the Modifier to be applied to this FAB
shape defines the shape of this FAB's container and shadow
containerColor the color used for the background of this FAB. Defaults to the FloatingToolbarColors.fabContainerColor from the standardFloatingToolbarColors.
contentColor the preferred color for content inside this FAB. Defaults to the FloatingToolbarColors.fabContentColor from the standardFloatingToolbarColors.
interactionSource an optional hoisted MutableInteractionSource for observing and emitting Interactions for this FAB. You can use this to change the FAB's appearance or preview the FAB in different states. Note that if null is provided, interactions will still happen internally.
content the content of this FAB, typically an Icon

floatingToolbarVerticalNestedScroll

fun Modifier.floatingToolbarVerticalNestedScroll(
        expanded: Boolean,
        onExpand: () -> Unit,
        onCollapse: () -> Unit,
        expandScrollDistanceThreshold: Dp = ScrollDistanceThreshold,
        collapseScrollDistanceThreshold: Dp = ScrollDistanceThreshold,
        reverseLayout: Boolean = false,
    ): Modifier

This Modifier tracks vertical scroll events on the scrolling container that a floating toolbar appears above. It then calls onExpand and onCollapse to adjust the toolbar's state based on the scroll direction and distance.

Essentially, it expands the toolbar when you scroll down past a certain threshold and collapses it when you scroll back up. You can customize the expand and collapse thresholds through the expandScrollDistanceThreshold and collapseScrollDistanceThreshold.

Parameters

expanded the current expanded state of the floating toolbar
onExpand callback to be invoked when the toolbar should expand
onCollapse callback to be invoked when the toolbar should collapse
expandScrollDistanceThreshold the scroll distance (in dp) required to trigger an onExpand
collapseScrollDistanceThreshold the scroll distance (in dp) required to trigger an onCollapse
reverseLayout indicates that the scrollable content has a reversed scrolling direction