MultiModalInjectionScope


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.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)
    mouse { dragAndDrop(topLeft, bottomRight) }
}

Summary

Public functions

Unit
indirectPointer(
    indirectPointerEventPrimaryDirectionalMotionAxis: IndirectPointerEventPrimaryDirectionalMotionAxis,
    inputDeviceSize: IntSize,
    block: IndirectPointerInjectionScope.() -> Unit
)

Injects all indirect pointer events sent by the given block.

Cmn
Unit
key(block: KeyInjectionScope.() -> Unit)

Injects all key events sent by the given block

Cmn
Unit

Injects all mouse events sent by the given block

Cmn
Unit

Injects all rotary events sent by the given block

Cmn
Unit

Injects all touch events sent by the given block

Cmn
Unit

Injects all trackpad events sent by the given block

Cmn

Inherited functions

From androidx.compose.ui.unit.Density
open Int

Convert Dp to Int by rounding

Cmn
open Int

Convert Sp to Int by rounding

Cmn
open Dp

Convert an Int pixel value to Dp.

Cmn
open Dp

Convert a Float pixel value to a Dp

Cmn
open DpSize

Convert a Size to a DpSize.

Cmn
open Float

Convert Dp to pixels.

Cmn
open Float

Convert Sp to pixels.

Cmn
open Rect

Convert a DpRect to a Rect.

Cmn
open Size

Convert a DpSize to a Size.

Cmn
open TextUnit

Convert an Int pixel value to Sp.

Cmn
open TextUnit

Convert a Float pixel value to a Sp

Cmn
From androidx.compose.ui.unit.FontScaling
Dp

Convert Sp to Dp.

Cmn
TextUnit

Convert Dp to Sp.

Cmn
From androidx.compose.ui.test.InjectionScope
Unit
advanceEventTime(durationMillis: Long)

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

Cmn
open Offset

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

Cmn

Inherited properties

From androidx.compose.ui.unit.Density
Float

The logical density of the display.

Cmn
From androidx.compose.ui.unit.FontScaling
Float

Current user preference for the scaling factor for fonts.

Cmn
From androidx.compose.ui.test.InjectionScope
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open Long

The default time between two successive events.

Cmn
open Int

The height of the node in px.

Cmn
open 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.

Cmn
open 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.

Cmn
open Float

The y-coordinate for the top 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.

Cmn
open 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.

Cmn
open 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.

Cmn
open 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.

Cmn
ViewConfiguration

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

Cmn
IntSize

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

Cmn
open Int

The width of the node in px.

Cmn

Public functions

indirectPointer

fun indirectPointer(
    indirectPointerEventPrimaryDirectionalMotionAxis: IndirectPointerEventPrimaryDirectionalMotionAxis,
    inputDeviceSize: IntSize,
    block: IndirectPointerInjectionScope.() -> Unit
): Unit

Injects all indirect pointer events sent by the given block. This API requires an active focus state meaning developers need to request focus to the component or a child of the component via SemanticsNodeInteraction.requestFocus() before calling this function. If no component is currently focused, the event will not trigger.

Parameters
indirectPointerEventPrimaryDirectionalMotionAxis: IndirectPointerEventPrimaryDirectionalMotionAxis

The main movement axis (horizontal or vertical) for single-directional scrolling when using the touchpad inputDeviceSize. For instance, if the primary axis is set to X, a display prioritizes scrolling its content (for both horizontal and vertical containers) based on the device's X-axis movement. Note that this input axis may not correspond directly to the resulting scrolling axis on the display (e.g., X-axis movement causing vertical scrolling).

inputDeviceSize: IntSize

The dimensions of the external indirect pointer input device that provide the boundaries for indirect input. If you go outside these dimensions, the tests will throw an exception. Note: This is not related to the screen coordinates.

block: IndirectPointerInjectionScope.() -> Unit

Block of code/events to execute in indirect scope

key

fun key(block: KeyInjectionScope.() -> Unit): Unit

Injects all key events sent by the given block

mouse

fun mouse(block: MouseInjectionScope.() -> Unit): Unit

Injects all mouse events sent by the given block

rotary

fun rotary(block: RotaryInjectionScope.() -> Unit): Unit

Injects all rotary events sent by the given block

touch

fun touch(block: TouchInjectionScope.() -> Unit): Unit

Injects all touch events sent by the given block

trackpad

fun trackpad(block: TrackpadInjectionScope.() -> Unit): Unit

Injects all trackpad events sent by the given block