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

MultiModalInjectionScope

public sealed interface MultiModalInjectionScope extends InjectionScope


The receiver scope of the multi-modal input injection lambda from performMultiModalInput.

MultiModalInjectionScope brings together the receiver scopes of all individual modalities, allowing you to inject gestures that consist of events from different modalities, like touch and mouse. For each modality, there is a function to which you pass a lambda in which you can inject events for that modality: currently, we have touch, mouse and key functions. See their respective docs for more information.

Note that all events generated by the gesture methods are batched together and sent as a whole after performMultiModalInput has executed its code block.

Example of performing a click via touch input followed by drag and drop via mouse input:

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.click
import androidx.compose.ui.test.dragAndDrop
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performMultiModalInput

composeTestRule.onNodeWithTag("myComponent")
    .performMultiModalInput {
        touch { click(center) }
        advanceEventTime(500)
        @OptIn(ExperimentalTestApi::class)
        mouse { dragAndDrop(topLeft, bottomRight) }
    }
See also
InjectionScope
TouchInjectionScope
MouseInjectionScope
KeyInjectionScope
RotaryInjectionScope

Summary

Public methods

abstract void

Injects all key events sent by the given block

abstract void

Injects all mouse events sent by the given block

abstract void

Injects all rotary events sent by the given block

abstract void

Injects all touch events sent by the given block

Inherited methods

From androidx.compose.ui.unit.Density
abstract float

The logical density of the display.

abstract float

Current user preference for the scaling factor for fonts.

default int

Convert Dp to Int by rounding

default int

Convert Sp to Int by rounding

default @NonNull Dp

Convert Sp to Dp.

default @NonNull Dp
orgKt.toDp(int receiver)

Convert an Int pixel value to Dp.

default @NonNull Dp
orgKt.toDp(float receiver)

Convert a Float pixel value to a Dp

default @NonNull DpSize

Convert a Size to a DpSize.

default float
orgKt.toPx(@NonNull Dp receiver)

Convert Dp to pixels.

default float

Convert Sp to pixels.

default @NonNull Rect

Convert a DpRect to a Rect.

default @NonNull Size

Convert a DpSize to a Size.

default @NonNull TextUnit
orgKt.toSp(@NonNull Dp receiver)

Convert Dp to Sp.

default @NonNull TextUnit
orgKt.toSp(int receiver)

Convert an Int pixel value to Sp.

default @NonNull TextUnit
orgKt.toSp(float receiver)

Convert a Float pixel value to a Sp

From androidx.compose.ui.test.InjectionScope
abstract void
advanceEventTime(long durationMillis)

Adds the given durationMillis to the current event time, delaying the next event by that time.

default float

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the bottom edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The bottom left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The bottom right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the left edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the right edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The x-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The y-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default long

The default time between two successive events.

default int

The height of the node in px.

default float

The x-coordinate for the left edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The x-coordinate for the right edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the top edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The top left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The top right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

abstract @NonNull ViewConfiguration

The ViewConfiguration in use by the SemanticsNode from the SemanticsNodeInteraction on which the input injection method is called.

abstract @NonNull IntSize

The size of the visible part of the node we're interacting with in px, i.e. its clipped bounds.

default int

The width of the node in px.

default @NonNull Offset
percentOffset(float x, float y)

Creates an Offset relative to the size of the node we're interacting with.

Public methods

key

@ExperimentalTestApi
abstract void key(
    @ExtensionFunctionType @NonNull Function1<@NonNull KeyInjectionScopeUnit> block
)

Injects all key events sent by the given block

mouse

@ExperimentalTestApi
abstract void mouse(
    @ExtensionFunctionType @NonNull Function1<@NonNull MouseInjectionScopeUnit> block
)

Injects all mouse events sent by the given block

rotary

@ExperimentalTestApi
abstract void rotary(
    @ExtensionFunctionType @NonNull Function1<@NonNull RotaryInjectionScopeUnit> block
)

Injects all rotary events sent by the given block

touch

abstract void touch(
    @ExtensionFunctionType @NonNull Function1<@NonNull TouchInjectionScopeUnit> block
)

Injects all touch events sent by the given block