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
PlatformLocalization
android
PlatformTextInputMethodRequest

Represents a request to open a platform-specific text input session via PlatformTextInputModifierNode.textInputSession.

Cmn
android
PlatformTextInputModifierNode

A modifier node that can connect to the platform's text input IME system.

Cmn
PlatformTextInputSession

Receiver type for establishTextInputSession.

Cmn
android
PlatformTextInputSessionScope

A PlatformTextInputSession that is also a CoroutineScope.

Cmn
SkiaRootForTest

The marker interface to be implemented by the desktop root backing the composition.

android
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

A ViewConfiguration with Android's default configurations.

android
ClipEntry

Platform specific protocol that expresses an item in the native Clipboard.

Cmn
android
ClipMetadata

Platform specific protocol that describes an item in the native Clipboard.

Cmn
android
ComposeView

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

android
DefaultViewConfiguration
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
NativeClipboard

Native Clipboard specific to each platform.

Cmn
android
TestComposeWindow

A virtual window for testing purposes.

android
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
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

Type aliases

NativeClipboard
android

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
suspend Nothing

Starts a new text input session and suspends until the session is closed.

Cmn
CompositionContext?

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

android
Uri?

Returns the first non-null Uri from the list of ClipData.Items in this ClipEntry.

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

This function is deprecated. This API will create more invalidations of your modifier than necessary, so it's use is discouraged.

Cmn
Modifier

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

Cmn
ClipEntry
android
ClipMetadata
android

Top-level properties summary

Boolean

This property is deprecated. Use ContentCapture.isEnabled instead

android
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<PlatformLocalization>
android
ProvidableCompositionLocal<SavedStateRegistryOwner>

The CompositionLocal containing the current SavedStateRegistryOwner.

android
ProvidableCompositionLocal<SoftwareKeyboardController?>

The CompositionLocal to provide a SoftwareKeyboardController that can control the current software keyboard.

Cmn
ProvidableCompositionLocal<TextInputService?>

This property is deprecated. Use PlatformTextInputModifierNode instead.

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.platform.debugInspectorInfo
import androidx.compose.ui.platform.inspectable

/**
 * 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.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection

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.

establishTextInputSession

suspend fun PlatformTextInputModifierNode.establishTextInputSession(
    block: suspend PlatformTextInputSessionScope.() -> Nothing
): Nothing

Starts a new text input session and suspends until the session is closed.

The block function must call PlatformTextInputSession.startInputMethod to actually show and initiate the connection with the input method. If it does not, the session will end when this function returns without showing the input method.

If this function is called while another session is active, the sessions will not overlap. The new session will interrupt the old one, which will be cancelled and allowed to finish running any cancellation tasks (e.g. finally blocks) before running the new block function.

The session will be closed when:

  • The session function throws an exception.

  • The requesting coroutine is cancelled.

  • Another session is started via this method, either from the same modifier or a different one.

  • The system closes the connection (currently only supported on Android, and there only depending on OS version).

This function should only be called from the modifier node's coroutineScope. If it is not, the session will not automatically be closed if the modifier is detached.

import androidx.compose.ui.platform.establishTextInputSession

class PlatformTextInputModifierNodeSample : Modifier.Node(),
    FocusEventModifierNode,
    PlatformTextInputModifierNode {

    private var focusedJob: Job? = null

    override fun onFocusEvent(focusState: FocusState) {
        focusedJob?.cancel()
        focusedJob = if (focusState.isFocused) {
            // establishTextInputSession is a suspend function, so it must be called from a
            // coroutine. Launching it into this modifier node's coroutine scope ensures the
            // session will automatically be torn down when the node is detached.
            coroutineScope.launch {
                // This will automatically cancel any currently-active session.
                establishTextInputSession {
                    launch {
                        // TODO: Observe text field state, call into system to update it as required
                        //  by the platform.
                    }

                    // Call out to a platform-specific expect/actual function to create the
                    // platform-specific request.
                    val request: PlatformTextInputMethodRequest = createInputRequest()
                    startInputMethod(request)
                }
            }
        } else {
            null
        }
    }

    // This would probably be an expect/actual function.
    private fun PlatformTextInputSession.createInputRequest(): PlatformTextInputMethodRequest {
        TODO("Create platform-specific request")
    }
}
Parameters
block: suspend PlatformTextInputSessionScope.() -> Nothing

A suspend function that will be called when the session is started and that must call PlatformTextInputSession.startInputMethod to actually show and initiate the connection with the input method.

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.

firstUriOrNull

@ExperimentalComposeUiApi
fun ClipEntry.firstUriOrNull(): Uri?

Returns the first non-null Uri from the list of ClipData.Items in this ClipEntry.

Do not forget that each ClipEntry can contain multiple ClipData.Items in its ClipData, therefore it can have multiple Uris. Always check whether you are processing all the items in a given ClipEntry.

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.platform.debugInspectorInfo
import androidx.compose.ui.platform.inspectable

/**
 * 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.

toClipEntry

fun ClipData.toClipEntry(): ClipEntry

Top-level properties

DisableContentCapture

@ExperimentalComposeUiApi
var DisableContentCaptureBoolean

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.

LocalSavedStateRegistryOwner

val LocalSavedStateRegistryOwnerProvidableCompositionLocal<SavedStateRegistryOwner>

The CompositionLocal containing the current SavedStateRegistryOwner.

LocalSoftwareKeyboardController

val LocalSoftwareKeyboardControllerProvidableCompositionLocal<SoftwareKeyboardController?>

The CompositionLocal to provide a SoftwareKeyboardController that can control the current software keyboard.

Will be null if the software keyboard cannot be controlled.

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.