Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

GestureScope

class GestureScope
kotlin.Any
   ↳ androidx.ui.test.GestureScope

The receiver scope for injecting gestures on the semanticsNode identified by the corresponding SemanticsNodeInteraction. Gestures can be injected by calling methods defined on GestureScope, such as click or swipe. The SemanticsNodeInteraction can be found by one of the finder methods such as ComposeTestRule.onNode.

The functions in GestureScope can roughly be divided into two groups: full gestures and partial gestures. Partial gestures are the ones that send individual touch events: down, move, up and cancel. Full gestures are all the other functions, like click, doubleClick, swipe, etc. See the documentation of down for more information about partial gestures. Normally, if you accidentally try to execute a full gesture while in the middle of a partial gesture, an IllegalStateException or IllegalArgumentException will be thrown. However, you might want to do this on purpose, for testing multi-touch gestures, where one finger might tap the screen while another is making a gesture. In that case, make sure the partial gesture uses a non-default pointer id.

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

Next to the functions, GestureScope also exposes several properties that allow you to get coordinates within a node, like the top left corner, its center, or 20% to the left of the right edge and 10% below the top edge (percentOffset).

Example usage:

onNodeWithTag("myWidget")
   .performGesture {
       click(center)
   }

onNodeWithTag("myWidget")
   // Perform an L-shaped gesture
   .performGesture {
       down(topLeft)
       move(topLeft + percentOffset(0f, .1f))
       move(topLeft + percentOffset(0f, .2f))
       move(topLeft + percentOffset(0f, .3f))
       move(topLeft + percentOffset(0f, .4f))
       move(centerLeft)
       move(centerLeft + percentOffset(.1f, 0f))
       move(centerLeft + percentOffset(.2f, 0f))
       move(centerLeft + percentOffset(.3f, 0f))
       move(centerLeft + percentOffset(.4f, 0f))
       move(center)
       up()
   }

Summary

Public constructors

The receiver scope for injecting gestures on the semanticsNode identified by the corresponding SemanticsNodeInteraction.

Extension functions
From androidx.ui.test
Unit

Sends a cancel event to cancel the current partial gesture.

Unit
GestureScope.click(position: Offset = center)

Performs a click gesture at the given position on the associated node, or in the center if the position is omitted.

Unit
GestureScope.doubleClick(position: Offset = center, delay: Duration = doubleClickDelay)

Performs a double click gesture at the given position on the associated node, or in the center if the position is omitted.

Unit
GestureScope.down(pointerId: Int, position: Offset)

Sends a down event for the pointer with the given pointerId at position on the associated node.

Unit

Sends a down event for the default pointer at position on the associated node.

Offset

Transforms the position to global coordinates, as defined by LayoutCoordinates.localToGlobal

Unit
GestureScope.longClick(position: Offset = center, duration: Duration = LongPressTimeout + 100.milliseconds)

Performs a long click gesture at the given position on the associated node, or in the center if the position is omitted.

Unit

Sends a move event without updating any of the pointer positions.

Unit
GestureScope.moveBy(pointerId: Int, delta: Offset)

Sends a move event on the associated node, with the position of the pointer with the given pointerId moved by the given delta.

Unit

Sends a move event on the associated node, with the position of the default pointer moved by the given delta.

Unit
GestureScope.movePointerBy(pointerId: Int, delta: Offset)

Moves the position of the pointer with the given pointerId by the given delta, but does not send a move event.

Unit
GestureScope.movePointerTo(pointerId: Int, position: Offset)

Updates the position of the pointer with the given pointerId to the given position, but does not send a move event.

Unit
GestureScope.moveTo(pointerId: Int, position: Offset)

Sends a move event on the associated node, with the position of the pointer with the given pointerId updated to position.

Unit

Sends a move event on the associated node, with the position of the default pointer updated to position.

Offset
GestureScope.percentOffset(@FloatRange(-1.0, 1.0) x: Float = 0f, @FloatRange(-1.0, 1.0) y: Float = 0f)

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

Unit
GestureScope.pinch(start0: Offset, end0: Offset, start1: Offset, end1: Offset, duration: Duration = 400.milliseconds)

Performs a pinch gesture on the associated node.

Unit
GestureScope.swipe(start: Offset, end: Offset, duration: Duration = 200.milliseconds)

Performs the swipe gesture on the associated node.

Unit

Performs a swipe down gesture on the associated node.

Unit

Performs a swipe left gesture on the associated node.

Unit

Performs a swipe right gesture on the associated node.

Unit

Performs a swipe up gesture on the associated node.

Unit
GestureScope.swipeWithVelocity(start: Offset, end: Offset, @FloatRange(0.0, 3.4E38) endVelocity: Float, duration: Duration = 200.milliseconds)

Performs the swipe gesture on the associated node, such that the velocity when the gesture is finished is roughly equal to endVelocity.

Unit
GestureScope.up(pointerId: Int = 0)

Sends an up event for the pointer with the given pointerId, or the default pointer if pointerId is omitted, on the associated node.

Properties
IntSize

Returns the size of the visible part of the node we're interacting with.

Extension properties
From androidx.ui.test
Float

Returns the y-coordinate for the bottom 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.

Offset

Returns 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.

Offset

Returns 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.

Offset

Returns 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.

Offset

Returns 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.

Offset

Returns 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.

Offset

Returns 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.

Float

Returns the x-coordinate for 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.

Float

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

Int

Shorthand for size.height

Float

Returns the x-coordinate for 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.

Float

Returns the x-coordinate for 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.

Float

Returns the y-coordinate for the bottom 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.

Offset

Returns 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.

Offset

Returns 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.

Offset

Returns 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.

Int

Shorthand for size.width

Public constructors

<init>

GestureScope(node: SemanticsNode)

The receiver scope for injecting gestures on the semanticsNode identified by the corresponding SemanticsNodeInteraction. Gestures can be injected by calling methods defined on GestureScope, such as click or swipe. The SemanticsNodeInteraction can be found by one of the finder methods such as ComposeTestRule.onNode.

The functions in GestureScope can roughly be divided into two groups: full gestures and partial gestures. Partial gestures are the ones that send individual touch events: down, move, up and cancel. Full gestures are all the other functions, like click, doubleClick, swipe, etc. See the documentation of down for more information about partial gestures. Normally, if you accidentally try to execute a full gesture while in the middle of a partial gesture, an IllegalStateException or IllegalArgumentException will be thrown. However, you might want to do this on purpose, for testing multi-touch gestures, where one finger might tap the screen while another is making a gesture. In that case, make sure the partial gesture uses a non-default pointer id.

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

Next to the functions, GestureScope also exposes several properties that allow you to get coordinates within a node, like the top left corner, its center, or 20% to the left of the right edge and 10% below the top edge (percentOffset).

Example usage:

onNodeWithTag("myWidget")
   .performGesture {
       click(center)
   }

onNodeWithTag("myWidget")
   // Perform an L-shaped gesture
   .performGesture {
       down(topLeft)
       move(topLeft + percentOffset(0f, .1f))
       move(topLeft + percentOffset(0f, .2f))
       move(topLeft + percentOffset(0f, .3f))
       move(topLeft + percentOffset(0f, .4f))
       move(centerLeft)
       move(centerLeft + percentOffset(.1f, 0f))
       move(centerLeft + percentOffset(.2f, 0f))
       move(centerLeft + percentOffset(.3f, 0f))
       move(centerLeft + percentOffset(.4f, 0f))
       move(center)
       up()
   }

Properties

visibleSize

val visibleSize: IntSize

Returns the size of the visible part of the node we're interacting with. This is contrary to SemanticsNode.size, which returns the unclipped size of the node.