androidx.compose.foundation

Interfaces

AndroidExternalSurfaceScope

AndroidExternalSurfaceScope is a scoped environment provided when an AndroidExternalSurface or AndroidEmbeddedExternalSurface is first initialized.

android
BasicTooltipState

The state that is associated with an instance of a tooltip.

Cmn
Indication

Indication represents visual effects that occur when certain interactions happens.

Cmn
IndicationInstance

This interface is deprecated. IndicationInstance has been deprecated along with the rememberUpdatedInstance that returns it.

Cmn
IndicationNodeFactory

IndicationNodeFactory is an Indication that creates Modifier.Node instances to render visual effects that occur when certain interactions happens.

Cmn
MarqueeSpacing

Defines a calculateSpacing method that determines the space after the end of basicMarquee content before drawing the content again.

Cmn
OverscrollEffect

An OverscrollEffect represents a visual effect that displays when the edges of a scrolling container have been reached with a scroll or fling.

Cmn
OverscrollFactory

A factory for creating OverscrollEffects.

Cmn
ScrollIndicatorState

Represents the state required to draw a scroll indicator (e.g., a scrollbar), which is typically provided by a scrollable component.

Cmn
SurfaceCoroutineScope

SurfaceCoroutineScope is a scoped environment provided by AndroidExternalSurface and AndroidEmbeddedExternalSurface when a new Surface is created.

android
SurfaceScope

SurfaceScope is a scoped environment provided by AndroidExternalSurface and AndroidEmbeddedExternalSurface to handle Surface lifecycle events.

android

Classes

AndroidExternalSurfaceZOrder

Defines the z-order of an AndroidExternalSurface.

android
BorderStroke

Class to specify the stroke to draw border with.

Cmn
MarqueeAnimationMode

Specifies when the basicMarquee animation runs.

Cmn
MutatorMutex

Mutual exclusion for UI state mutation over time.

Cmn
OverscrollConfiguration

This class is deprecated. Providing `OverscrollConfiguration` through `LocalOverscrollConfiguration` to disable / configure overscroll has been replaced with `LocalOverscrollFactory` and `rememberPlatformOverscrollFactory`.

android
ScrollState

State of the scroll.

Cmn

Objects

BasicTooltipDefaults

BasicTooltip defaults that contain default values for tooltips created.

Cmn
ComposeFoundationFlags

This is a collection of flags which are used to guard against regressions in some of the "riskier" refactors or new feature support that is added to this module.

Cmn
MarqueeDefaults

Namespace for constants representing the default values for various basicMarquee parameters.

Cmn

Annotations

Enums

MutatePriority

Priorities for performing mutation on state.

Cmn

Composables

AndroidEmbeddedExternalSurface

Provides a dedicated drawing Surface embedded directly in the UI hierarchy.

android
AndroidExternalSurface

Provides a dedicated drawing Surface as a separate layer positioned by default behind the window holding the AndroidExternalSurface composable.

android
BasicTooltipBox

BasicTooltipBox that wraps a composable with a tooltip.

Cmn
Canvas

Component that allow you to specify an area on the screen and perform canvas drawing on this area.

Cmn
Image

A composable that lays out and draws a given ImageVector.

Cmn
isSystemInDarkTheme

Returns whether the operating system is in dark theme.

Cmn
rememberBasicTooltipState

Create and remember the default BasicTooltipState.

Cmn
rememberOverscrollEffect

Returns a remembered OverscrollEffect created from the current value of LocalOverscrollFactory.

Cmn
rememberPlatformOverscrollFactory

Creates and remembers an instance of the platform OverscrollFactory, with the provided glowColor and glowDrawPadding values - these values will be used on platform versions where glow overscroll is used.

android
rememberScrollState

Create and remember the ScrollState based on the currently appropriate scroll configuration to allow changing scroll position or observing scroll behavior.

Cmn

Modifiers

background

Draws shape with a solid color behind the content.

Cmn
basicMarquee

Applies an animated marquee effect to the modified content if it's too wide to fit in the available space.

Cmn
border

Modify element to add border with appearance specified with a border and a shape and clip it.

Cmn
clickable

Configure component to receive clicks via input or accessibility "click" event.

Cmn
clipScrollableContainer

Clips bounds of scrollable container on main axis while leaving space for background effects (like shadows) on cross axis.

Cmn
combinedClickable

Configure component to receive clicks, double clicks and long clicks via input or accessibility "click" event.

Cmn
excludeFromSystemGesture

Excludes the layout rectangle from the system gesture.

android
focusGroup

Creates a focus group or marks this component as a focus group.

Cmn
focusable

Configure component to be focusable via focus system or accessibility "focus" event.

Cmn
horizontalScroll

Modify element to allow to scroll horizontally when width of the content is bigger than max constraints allow.

Cmn
hoverable

Configure component to be hoverable via pointer enter/exit events.

Cmn
indication

Draws visual effects for this component when interactions occur.

Cmn
magnifier

Shows a Magnifier widget that shows an enlarged version of the content at sourceCenter relative to the current layout node.

android
onFocusedBoundsChanged

Calls onPositioned whenever the bounds of the currently-focused area changes.

Cmn
overscroll

Renders overscroll from the provided overscrollEffect.

Cmn
preferKeepClear

Mark the layout rectangle as preferring to stay clear of floating windows.

android
progressSemantics

Contains the semantics required for an indeterminate progress indicator, that represents the fact of the in-progress operation.

Cmn
scrollableArea

Configure a component to act as a scrollable area.

Cmn
systemGestureExclusion

Excludes the layout rectangle from the system gesture.

android
verticalScroll

Modify element to allow to scroll vertically when height of the content is bigger than max constraints allow.

Cmn

Top-level functions summary

BasicTooltipState
@ExperimentalFoundationApi
BasicTooltipState(
    initialIsVisible: Boolean,
    isPersistent: Boolean,
    mutatorMutex: MutatorMutex
)

Constructor extension function for BasicTooltipState

Cmn
BorderStroke
BorderStroke(width: Dp, color: Color)

Create BorderStroke class with width and Color

Cmn
MarqueeSpacing
MarqueeSpacing(spacing: Dp)

A MarqueeSpacing with a fixed size.

Cmn
Unit
checkScrollableContainerConstraints(
    constraints: Constraints,
    orientation: Orientation
)
Cmn

Extension functions summary

OverscrollEffect

Returns a wrapped version of this that will not handle any incoming events.

Cmn
OverscrollEffect

Returns a wrapped version of this with an empty OverscrollEffect.node.

Cmn

Top-level properties summary

ProvidableCompositionLocal<Indication>

CompositionLocal that provides an Indication through the hierarchy.

Cmn
ProvidableCompositionLocal<OverscrollConfiguration?>

This property is deprecated. Providing `OverscrollConfiguration` through `LocalOverscrollConfiguration` to disable / configure overscroll has been replaced with `LocalOverscrollFactory` and `rememberPlatformOverscrollFactory`.

android
ProvidableCompositionLocal<OverscrollFactory?>

CompositionLocal that provides an OverscrollFactory through the hierarchy.

Cmn

Top-level functions

BasicTooltipState

@ExperimentalFoundationApi
fun BasicTooltipState(
    initialIsVisible: Boolean = false,
    isPersistent: Boolean = true,
    mutatorMutex: MutatorMutex = BasicTooltipDefaults.GlobalMutatorMutex
): BasicTooltipState

Constructor extension function for BasicTooltipState

Parameters
initialIsVisible: Boolean = false

the initial value for the tooltip's visibility when drawn.

isPersistent: Boolean = true

Boolean that determines if the tooltip associated with this will be persistent or not. If isPersistent is true, then the tooltip will only be dismissed when the user clicks outside the bounds of the tooltip or if BasicTooltipState.dismiss is called. When isPersistent is false, the tooltip will dismiss after a short duration. Ideally, this should be set to true when there is actionable content being displayed within a tooltip.

mutatorMutex: MutatorMutex = BasicTooltipDefaults.GlobalMutatorMutex

MutatorMutex used to ensure that for all of the tooltips associated with the mutator mutex, only one will be shown on the screen at any time.

BorderStroke

fun BorderStroke(width: Dp, color: Color): BorderStroke

Create BorderStroke class with width and Color

Parameters
width: Dp

width of the border in Dp. Use Dp.Hairline for one-pixel border.

color: Color

color to paint the border with

MarqueeSpacing

fun MarqueeSpacing(spacing: Dp): MarqueeSpacing

A MarqueeSpacing with a fixed size.

checkScrollableContainerConstraints

fun checkScrollableContainerConstraints(
    constraints: Constraints,
    orientation: Orientation
): Unit
Parameters
constraints: Constraints

Constraints used to measure the scrollable container

orientation: Orientation

orientation of the scrolling

Throws
IllegalStateException

if the container was measured with the infinity constraints in the direction of scrolling. This usually means nesting scrollable in the same direction containers which is a performance issue and is discouraged.

Extension functions

OverscrollEffect.withoutEventHandling

fun OverscrollEffect.withoutEventHandling(): OverscrollEffect

Returns a wrapped version of this that will not handle any incoming events. This means that calls to OverscrollEffect.applyToScroll / OverscrollEffect.applyToFling will directly execute the provided performScroll / performFling lambdas, without the OverscrollEffect ever seeing the incoming values. OverscrollEffect.node will still be attached, so that overscroll can render.

This can be useful if you want to render an OverscrollEffect in a different component that normally provides events to overscroll, such as a androidx.compose.foundation.lazy.LazyColumn. Use this along with withoutVisualEffect to create two wrapped instances: one that does not handle events, and one that does not draw, so you can ensure that the overscroll effect is only rendered once, and only receives events from one source.

OverscrollEffect.withoutVisualEffect

fun OverscrollEffect.withoutVisualEffect(): OverscrollEffect

Returns a wrapped version of this with an empty OverscrollEffect.node. This prevents the overscroll effect from applying any visual effect, but it will still handle events.

This can be used along with withoutEventHandling in cases where you wish to change where overscroll is rendered for a given component. Pass this wrapped instance that doesn't render to the component that handles events (such as androidx.compose.foundation.lazy.LazyColumn) to prevent it from drawing the overscroll effect. Then to separately render the original overscroll effect, you can directly pass it to Modifier.overscroll (since that modifier only renders, and does not handle events). If instead you want to draw the overscroll in another component that handles events, such as a different lazy list, you need to first wrap the original overscroll effect with withoutEventHandling to prevent it from also dispatching events.

import androidx.compose.foundation.OverscrollEffect
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.overscroll
import androidx.compose.foundation.rememberOverscrollEffect
import androidx.compose.foundation.withoutVisualEffect
import androidx.compose.material.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp

val items = remember { (1..100).toList() }
val state = rememberLazyListState()
val overscroll = rememberOverscrollEffect()
// Create a wrapped version of the above overscroll effect that does not apply a visual effect.
// This will be used inside LazyColumn to provide events to overscroll, without letting
// LazyColumn render the overscroll effect internally.
val overscrollWithoutVisualEffect = overscroll?.withoutVisualEffect()
LazyColumn(
    content = { items(items) { Text("Item $it") } },
    state = state,
    modifier =
        Modifier.size(300.dp)
            .clip(RectangleShape)
            // Manually render the overscroll on top of the lazy list _and_ the 'decorations' we
            // are
            // manually drawing, to make sure they will also be included in the overscroll
            // effect.
            .overscroll(overscroll)
            .drawBehind {
                state.layoutInfo.visibleItemsInfo.drop(1).forEach { info ->
                    val verticalOffset = info.offset.toFloat()
                    drawLine(
                        color = Color.Red,
                        start = Offset(0f, verticalOffset),
                        end = Offset(size.width, verticalOffset),
                    )
                }
            },
    // Pass the overscroll effect that does not apply a visual effect inside the LazyList to
    // receive overscroll events
    overscrollEffect = overscrollWithoutVisualEffect,
)

Top-level properties

LocalIndication

val LocalIndicationProvidableCompositionLocal<Indication>

CompositionLocal that provides an Indication through the hierarchy. This Indication will be used by default to draw visual effects for interactions such as press and drag in components such as clickable.

By default this will provide a debug indication, this should always be replaced.

LocalOverscrollConfiguration

@ExperimentalFoundationApi
val LocalOverscrollConfigurationProvidableCompositionLocal<OverscrollConfiguration?>

Composition local to provide configuration for scrolling containers down the hierarchy. null means there will be no overscroll at all.

LocalOverscrollFactory

val LocalOverscrollFactoryProvidableCompositionLocal<OverscrollFactory?>

CompositionLocal that provides an OverscrollFactory through the hierarchy. This will be used by default by scrolling components, so you can provide an OverscrollFactory here to override the overscroll used by components within a hierarchy.

See rememberOverscrollEffect to remember an OverscrollEffect from the current provided value.