{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

androidx.compose.ui.platform

Interfaces

AccessibilityManager

Interface for managing accessibility.

Cmn
ClipboardManager

Interface for managing the Clipboard.

Cmn
InfiniteAnimationPolicy

Provides a policy that will be applied to animations that get their frame time from withInfiniteAnimationFrameNanos or withInfiniteAnimationFrameMillis This can be used to intervene in infinite animations to make them finite, for example by cancelling such coroutines.

Cmn
InspectableValue

A compose value that is inspectable by tools.

Cmn
SoftwareKeyboardController

Provide software keyboard control.

Cmn
TextToolbar

Interface for text-related toolbar.

Cmn
UriHandler

An interface of providing platform specific URL handling.

Cmn
ViewCompositionStrategy

A strategy for managing the underlying Composition of Compose UI Views such as ComposeView and AbstractComposeView.

android
ViewConfiguration

Contains methods to standard constants used in the UI for timeouts, sizes, and distances.

Cmn
ViewRootForInspector

The marker interface to be implemented by Views that are initialized from Compose.

android
ViewRootForTest

The marker interface to be implemented by the View backing the composition.

android
WindowInfo

Provides information about the Window that is hosting this compose hierarchy.

Cmn
WindowRecomposerFactory

A factory for creating an Android window-scoped Recomposer.

android

Classes

AbstractComposeView

Base class for custom android.view.Views implemented using Jetpack Compose UI.

android
AndroidUiDispatcher

A CoroutineDispatcher that will perform dispatch during a handler callback or choreographer's animation frame stage, whichever comes first.

android
AndroidUiFrameClock
android
AndroidUriHandler
android
AndroidViewConfiguration
android
AtomicInt
Cmn
ComposeView

A android.view.View that can host Jetpack Compose UI content.

android
InspectableModifier

Annotates a range of modifiers in a chain with inspector metadata.

Cmn
InspectableModifier.End
Cmn
InspectorInfo

A builder for an InspectableValue.

Cmn
InspectorValueInfo

Implementation of InspectableValue based on a builder InspectorInfo DSL.

Cmn
ValueElement

A ValueElement describes an element of a compose value instance.

Cmn
ValueElementSequence

A builder for a sequence of ValueElement.

Cmn
ViewCompositionStrategy.DisposeOnLifecycleDestroyed

ViewCompositionStrategy that disposes the composition when lifecycle is destroyed.

android

Objects

InfiniteAnimationPolicy.Key
Cmn
LocalSoftwareKeyboardController
Cmn
ViewCompositionStrategy.DisposeOnDetachedFromWindow

ViewCompositionStrategy that disposes the composition whenever the view becomes detached from a window.

android
ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool

The composition will be disposed automatically when the view is detached from a window, unless it is part of a pooling container, such as RecyclerView.

android
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed

ViewCompositionStrategy that disposes the composition when the LifecycleOwner returned by findViewTreeLifecycleOwner of the next window the view is attached to is destroyed.

android
WindowRecomposerPolicy
android

Enums

TextToolbarStatus

Status of the TextToolbar.

Cmn

Top-level functions summary

inline InspectorInfo.() -> Unit
debugInspectorInfo(crossinline definitions: InspectorInfo.() -> Unit)

Use this to specify modifier information for compose tooling.

Cmn
NestedScrollConnection

Create and remember the NestedScrollConnection that enables Nested Scroll Interop between a View parent that implements androidx.core.view.NestedScrollingParent3 and a Compose child.

android

Extension functions summary

Recomposer

Create a Lifecycle and window attachment-aware Recomposer for this View with the same behavior as WindowRecomposerFactory.LifecycleAware.

android
CompositionContext?

Returns the parent CompositionContext for this point in the view hierarchy, or null if none can be found.

android
inline Modifier
Modifier.inspectable(
    noinline inspectorInfo: InspectorInfo.() -> Unit,
    factory: Modifier.() -> Modifier
)

Use this to group a common set of modifiers and provide InspectorInfo for the resulting modifier.

Cmn
Modifier

Applies a tag to allow modified element to be found in tests.

Cmn

Top-level properties summary

ProvidableCompositionLocal<AccessibilityManager?>

The CompositionLocal to provide communication with platform accessibility service.

Cmn
ProvidableCompositionLocal<Autofill?>

The CompositionLocal that can be used to trigger autofill actions.

Cmn
ProvidableCompositionLocal<AutofillTree>

The CompositionLocal that can be used to add import androidx.compose.ui.autofill.AutofillNodes to the autofill tree.

Cmn
ProvidableCompositionLocal<ClipboardManager>

The CompositionLocal to provide communication with platform clipboard service.

Cmn
ProvidableCompositionLocal<Configuration>

The Android Configuration.

android
ProvidableCompositionLocal<Context>

Provides a Context that can be used by Android applications.

android
ProvidableCompositionLocal<Density>

Provides the Density to be used to transform between density-independent pixel units (DP) and pixel units or scale-independent pixel units (SP) and pixel units.

Cmn
ProvidableCompositionLocal<FocusManager>

The CompositionLocal that can be used to control focus within Compose.

Cmn
ProvidableCompositionLocal<FontFamily.Resolver>

The CompositionLocal for compose font resolution from FontFamily.

Cmn
ProvidableCompositionLocal<HapticFeedback>

The CompositionLocal to provide haptic feedback to the user.

Cmn
ProvidableCompositionLocal<InputModeManager>

The CompositionLocal to provide an instance of InputModeManager which controls the current input mode.

Cmn
ProvidableCompositionLocal<Boolean>

Inspectable mode CompositionLocal.

Cmn
ProvidableCompositionLocal<LayoutDirection>

The CompositionLocal to provide the layout direction.

Cmn
ProvidableCompositionLocal<LifecycleOwner>

The CompositionLocal containing the current LifecycleOwner.

android
ProvidableCompositionLocal<PlatformTextInputPluginRegistry>

The CompositionLocal to provide platform text input services.

Cmn
ProvidableCompositionLocal<SavedStateRegistryOwner>

The CompositionLocal containing the current SavedStateRegistryOwner.

android
ProvidableCompositionLocal<TextInputService?>

The CompositionLocal to provide communication with platform text input service.

Cmn
ProvidableCompositionLocal<TextToolbar>

The CompositionLocal to provide text-related toolbar.

Cmn
ProvidableCompositionLocal<UriHandler>

The CompositionLocal to provide functionality related to URL, e.g. open URI.

Cmn
ProvidableCompositionLocal<View>

The CompositionLocal containing the current Compose View.

android
ProvidableCompositionLocal<ViewConfiguration>

The CompositionLocal that provides the ViewConfiguration.

Cmn
ProvidableCompositionLocal<WindowInfo>

The CompositionLocal that provides information about the window that hosts the current Owner.

Cmn
InspectorInfo.() -> Unit

An empty InspectorInfo DSL.

Cmn
Boolean

Turn on inspector debug information.

Cmn

Extension properties summary

CompositionContext?

The CompositionContext that should be used as a parent for compositions at or below this view in the hierarchy.

android

Top-level functions

debugInspectorInfo

inline fun debugInspectorInfo(crossinline definitions: InspectorInfo.() -> Unit): InspectorInfo.() -> Unit

Use this to specify modifier information for compose tooling.

This factory method allows the specified information to be stripped out by ProGuard in release builds.

import androidx.compose.foundation.background
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.platform.inspectable
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
 * Sample with a single parameter
 */
fun Modifier.simpleFrame(color: Color) = inspectable(
    inspectorInfo = debugInspectorInfo {
        name = "simpleFrame"
        value = color
    }
) {
    background(color, RoundedCornerShape(5.0.dp))
}

/**
 * Sample with multiple parameters
 */
fun Modifier.fancyFrame(size: Dp, color: Color) = inspectable(
    inspectorInfo = debugInspectorInfo {
        name = "fancyFrame"
        properties["size"] = size
        properties["color"] = color
    }
) {
    background(color, RoundedCornerShape(size))
}

rememberNestedScrollInteropConnection

@Composable
fun rememberNestedScrollInteropConnection(hostView: View = LocalView.current): NestedScrollConnection

Create and remember the NestedScrollConnection that enables Nested Scroll Interop between a View parent that implements androidx.core.view.NestedScrollingParent3 and a Compose child. This should be used in conjunction with a androidx.compose.ui.input.nestedscroll.nestedScroll modifier. Nested Scroll is enabled by default on the compose side and you can use this connection to enable both nested scroll on the view side and to add glue logic between View and compose.

Note that this only covers the use case where a cooperating parent is used. A cooperating parent is one that implements NestedScrollingParent3, a key layout that does that is androidx.coordinatorlayout.widget.CoordinatorLayout.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.unit.dp

val nestedSrollInterop = rememberNestedScrollInteropConnection()
// Add the nested scroll connection to your top level @Composable element
// using the nestedScroll modifier.
LazyColumn(modifier = Modifier.nestedScroll(nestedSrollInterop)) {
    items(20) { item ->
        Box(
            modifier = Modifier
                .padding(16.dp)
                .height(56.dp)
                .fillMaxWidth()
                .background(Color.Gray),
            contentAlignment = Alignment.Center
        ) {
            Text(item.toString())
        }
    }
}
Parameters
hostView: View = LocalView.current

The View that hosts the compose scrollable, this is usually a ComposeView.

Learn how to enable nested scroll interop:

Extension functions

createLifecycleAwareWindowRecomposer

@ExperimentalComposeUiApi
fun View.createLifecycleAwareWindowRecomposer(
    coroutineContext: CoroutineContext = EmptyCoroutineContext,
    lifecycle: Lifecycle? = null
): Recomposer

Create a Lifecycle and window attachment-aware Recomposer for this View with the same behavior as WindowRecomposerFactory.LifecycleAware.

coroutineContext will override any CoroutineContext elements from the default configuration normally used for this content view. The default CoroutineContext contains AndroidUiDispatcher.CurrentThread; this function should only be called from the UI thread of this View or its intended UI thread if it is currently detached.

If lifecycle is null or not supplied the LifecycleOwner returned by findViewTreeLifecycleOwner will be used; if a non-null lifecycle is not provided and a ViewTreeLifecycleOwner is not present an IllegalStateException will be thrown.

The returned Recomposer will be cancelled when this View is detached from a window or if its determined Lifecycle is destroyed. Recomposition and associated frame-based effects may be throttled or paused while the Lifecycle is not at least Lifecycle.State.STARTED.

findViewTreeCompositionContext

fun View.findViewTreeCompositionContext(): CompositionContext?

Returns the parent CompositionContext for this point in the view hierarchy, or null if none can be found.

See compositionContext to get or set the parent CompositionContext for a specific view.

inspectable

inline fun Modifier.inspectable(
    noinline inspectorInfo: InspectorInfo.() -> Unit,
    factory: Modifier.() -> Modifier
): Modifier

Use this to group a common set of modifiers and provide InspectorInfo for the resulting modifier.

import androidx.compose.foundation.background
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.debugInspectorInfo
import androidx.compose.ui.platform.inspectable
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
 * Sample with a single parameter
 */
fun Modifier.simpleFrame(color: Color) = inspectable(
    inspectorInfo = debugInspectorInfo {
        name = "simpleFrame"
        value = color
    }
) {
    background(color, RoundedCornerShape(5.0.dp))
}

/**
 * Sample with multiple parameters
 */
fun Modifier.fancyFrame(size: Dp, color: Color) = inspectable(
    inspectorInfo = debugInspectorInfo {
        name = "fancyFrame"
        properties["size"] = size
        properties["color"] = color
    }
) {
    background(color, RoundedCornerShape(size))
}

testTag

fun Modifier.testTag(tag: String): Modifier

Applies a tag to allow modified element to be found in tests.

This is a convenience method for a semantics that sets SemanticsPropertyReceiver.testTag.

Top-level properties

LocalAccessibilityManager

val LocalAccessibilityManagerProvidableCompositionLocal<AccessibilityManager?>

The CompositionLocal to provide communication with platform accessibility service.

LocalAutofill

@ExperimentalComposeUiApi
val LocalAutofillProvidableCompositionLocal<Autofill?>

The CompositionLocal that can be used to trigger autofill actions. Eg. Autofill.requestAutofillForNode.

LocalAutofillTree

@ExperimentalComposeUiApi
val LocalAutofillTreeProvidableCompositionLocal<AutofillTree>

The CompositionLocal that can be used to add import androidx.compose.ui.autofill.AutofillNodes to the autofill tree. The AutofillTree is a temporary data structure that will be replaced by Autofill Semantics (b/138604305).

LocalClipboardManager

val LocalClipboardManagerProvidableCompositionLocal<ClipboardManager>

The CompositionLocal to provide communication with platform clipboard service.

LocalConfiguration

val LocalConfigurationProvidableCompositionLocal<Configuration>

The Android Configuration. The Configuration is useful for determining how to organize the UI.

LocalContext

val LocalContextProvidableCompositionLocal<Context>

Provides a Context that can be used by Android applications.

LocalDensity

val LocalDensityProvidableCompositionLocal<Density>

Provides the Density to be used to transform between density-independent pixel units (DP) and pixel units or scale-independent pixel units (SP) and pixel units. This is typically used when a DP is provided and it must be converted in the body of Layout or DrawModifier.

LocalFocusManager

val LocalFocusManagerProvidableCompositionLocal<FocusManager>

The CompositionLocal that can be used to control focus within Compose.

LocalFontFamilyResolver

val LocalFontFamilyResolverProvidableCompositionLocal<FontFamily.Resolver>

The CompositionLocal for compose font resolution from FontFamily.

LocalHapticFeedback

val LocalHapticFeedbackProvidableCompositionLocal<HapticFeedback>

The CompositionLocal to provide haptic feedback to the user.

LocalInputModeManager

val LocalInputModeManagerProvidableCompositionLocal<InputModeManager>

The CompositionLocal to provide an instance of InputModeManager which controls the current input mode.

LocalInspectionMode

val LocalInspectionModeProvidableCompositionLocal<Boolean>

Inspectable mode CompositionLocal. True if the composition is composed inside a Inspectable component.

LocalLayoutDirection

val LocalLayoutDirectionProvidableCompositionLocal<LayoutDirection>

The CompositionLocal to provide the layout direction.

LocalLifecycleOwner

val LocalLifecycleOwnerProvidableCompositionLocal<LifecycleOwner>

The CompositionLocal containing the current LifecycleOwner.

LocalPlatformTextInputPluginRegistry

@ExperimentalTextApi
val LocalPlatformTextInputPluginRegistryProvidableCompositionLocal<PlatformTextInputPluginRegistry>

The CompositionLocal to provide platform text input services.

This is a low-level API for code that talks directly to the platform input method framework. Higher-level text input APIs in the Foundation library are more appropriate for most cases.

LocalSavedStateRegistryOwner

val LocalSavedStateRegistryOwnerProvidableCompositionLocal<SavedStateRegistryOwner>

The CompositionLocal containing the current SavedStateRegistryOwner.

LocalTextInputService

val LocalTextInputServiceProvidableCompositionLocal<TextInputService?>

The CompositionLocal to provide communication with platform text input service.

LocalTextToolbar

val LocalTextToolbarProvidableCompositionLocal<TextToolbar>

The CompositionLocal to provide text-related toolbar.

LocalUriHandler

val LocalUriHandlerProvidableCompositionLocal<UriHandler>

The CompositionLocal to provide functionality related to URL, e.g. open URI.

LocalView

val LocalViewProvidableCompositionLocal<View>

The CompositionLocal containing the current Compose View.

LocalViewConfiguration

val LocalViewConfigurationProvidableCompositionLocal<ViewConfiguration>

The CompositionLocal that provides the ViewConfiguration.

LocalWindowInfo

val LocalWindowInfoProvidableCompositionLocal<WindowInfo>

The CompositionLocal that provides information about the window that hosts the current Owner.

NoInspectorInfo

val NoInspectorInfoInspectorInfo.() -> Unit

An empty InspectorInfo DSL.

isDebugInspectorInfoEnabled

var isDebugInspectorInfoEnabledBoolean

Turn on inspector debug information. Used internally during inspection.

Extension properties

compositionContext

var View.compositionContextCompositionContext?

The CompositionContext that should be used as a parent for compositions at or below this view in the hierarchy. Set to non-null to provide a CompositionContext for compositions created by child views, or null to fall back to any CompositionContext provided by ancestor views.

See findViewTreeCompositionContext.