Function

performIndirectPointerInput

Executes an indirect pointer gesture globally, targeting the currently focused Compose UI (from root to the focused node).

indirectPointerInputAssertDuringClick

fun indirectPointerInputAssertDuringClick() {
    // Ensure the node is within the focus path (otherwise, you won't get the event).
    composeTestRule.onNodeWithTag("myComponent").requestFocus()
    composeTestRule.performIndirectPointerInput(
        indirectPointerEventPrimaryDirectionalMotionAxis =
            IndirectPointerEventPrimaryDirectionalMotionAxis.X,
        // Horizontal trackpad
        inputDeviceSize = IntSize(width = 5000, height = 1000),
    ) {
        down(position = Offset(x = inputDeviceCenterX, y = inputDeviceCenterY))
    }
    // Assert some pressed state is visible
    composeTestRule.performIndirectPointerInput(
        indirectPointerEventPrimaryDirectionalMotionAxis =
            IndirectPointerEventPrimaryDirectionalMotionAxis.X,
        // Horizontal trackpad
        inputDeviceSize = IntSize(width = 5000, height = 1000),
    ) {
        up()
    }
}

indirectPointerInputClick

// Click options:
fun indirectPointerInputClick() {
    // Ensure the node is within the focus path (otherwise, you won't get the event).
    composeTestRule.onNodeWithTag("myComponent").requestFocus()
    composeTestRule.performIndirectPointerInput(
        indirectPointerEventPrimaryDirectionalMotionAxis =
            IndirectPointerEventPrimaryDirectionalMotionAxis.X,
        // Horizontal trackpad
        inputDeviceSize = IntSize(width = 5000, height = 1000),
    ) {
        click()
    }
}

indirectPointerInputClickAndDrag

fun indirectPointerInputClickAndDrag() {
    // Ensure the node is within the focus path (otherwise, you won't get the event).
    composeTestRule.onNodeWithTag("myComponent").requestFocus()
    composeTestRule.performIndirectPointerInput(
        indirectPointerEventPrimaryDirectionalMotionAxis =
            IndirectPointerEventPrimaryDirectionalMotionAxis.X,
        // Horizontal trackpad
        inputDeviceSize = IntSize(width = 5000, height = 1000),
    ) {
        click()
        advanceEventTime(durationMillis = 100)
        swipeLeft(startX = inputDeviceRight, endX = inputDeviceLeft)
    }
}

indirectPointerInputSwipeRight

// Swipe options
fun indirectPointerInputSwipeRight() {
    // Ensure your node is within the focus path (otherwise, you won't get the event).
    composeTestRule.onNodeWithTag("myComponent").requestFocus()
    composeTestRule.performIndirectPointerInput(
        indirectPointerEventPrimaryDirectionalMotionAxis =
            IndirectPointerEventPrimaryDirectionalMotionAxis.X,
        // Horizontal trackpad
        inputDeviceSize = IntSize(width = 5000, height = 1000),
    ) {
        swipeRight(startX = inputDeviceLeft, endX = inputDeviceRight)
    }
}

Last updated: