MultiModalInjectionScope
-
Cmn
sealed interface MultiModalInjectionScope : 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.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) } }
| See also | |
|---|---|
InjectionScope |
|
TouchInjectionScope |
|
MouseInjectionScope |
|
KeyInjectionScope |
|
RotaryInjectionScope |
|
TrackpadInjectionScope |
Summary
Public functions |
||
|---|---|---|
Unit |
indirectPointer(Injects all indirect pointer events sent by the given |
Cmn
|
Unit |
key(block: KeyInjectionScope.() -> Unit)Injects all key events sent by the given |
Cmn
|
Unit |
mouse(block: MouseInjectionScope.() -> Unit)Injects all mouse events sent by the given |
Cmn
|
Unit |
rotary(block: RotaryInjectionScope.() -> Unit)Injects all rotary events sent by the given |
Cmn
|
Unit |
touch(block: TouchInjectionScope.() -> Unit)Injects all touch events sent by the given |
Cmn
|
Unit |
trackpad(block: TrackpadInjectionScope.() -> Unit)Injects all trackpad events sent by the given |
Cmn
|
Inherited functions |
|||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||
|
Inherited properties |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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: 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