Touchable Component Properties
A touchable component receives input from touch or pointer events and invokes handlers to support custom touch interaction behavior.
onPress
require APL 1.4 or later. Provide an alternate experience for devices running older versions of APL.Touchable components
The following components are touchable components:
Properties
All touchable components have the following properties:
- All actionable component properties.
- All base component properties.
- The touchable component-specific properties listed in the following table. See the meaning of the columns.
Property | Type | Default | Styled | Dynamic | Description |
---|---|---|---|---|---|
gesture , gestures |
Array of gesture handlers | [] | No | No | An array of gesture handlers to run. |
onCancel |
Array of Commands | [] | No | No | Commands to run when a gesture takes over the pointer. |
onDown |
Array of Commands | [] | No | No | Commands to run when a pointer down event occurs. |
onMove |
Array of Commands | [] | No | No | Commands to run as the pointer moves. |
onPress |
Array of Commands | [] | No | No | Commands to run for a pointer down followed by a pointer up. |
onUp |
Array of Commands | [] | No | No | Commands to run when releasing the pointer. |
Use the SendEvent
command to send an Alexa.Presentation.APL.UserEvent request to your skill. For an example of a UserEvent
handler, see Handle a UserEvent request.
layoutDirection component property
The layoutDirection
property on a touchable component determines how the direction
property for a SwipeAway
gesture works.
For details, see the SwipeAway
direction
property.
gesture, gestures
An array of gesture handlers.
When pointer events occur, Alexa checks the gesture handler list (in order) to determine if the event represents a supported gesture. When a gesture handler applies, Alexa runs the onCancel
handler. The applicable gesture handler then processes and handles the pointer events. Examples of gestures include double tap (DoublePress
) and long-press (LongPress
).
When no gesture handlers apply to the pointer event, Alexa passes the event to the applicable onDown
, onMove
, and onUp
handlers.
For details about gestures, see Gestures. For examples, see the individual gesture handler topics:
onCancel
Commands to run when a gesture handler takes over control of the pointer. The event generated has the following form.
"event": {
"source": {
"type": COMPONENT_TYPE, // The type of the component (such as "TouchWrapper", "VectorGraphic")
"handler": "Cancel",
... // Component source properties
},
"component": {
"x": Number, // X-position of the down event in the component (dp)
"y": Number, // Y-position of the down event in the component (dp)
"width": Number, // Width of the component in dp
"height": Number, // Height of the component in dp
}
}
Refer to Event source for a description of event.source
properties.
The onCancel
handler runs in fast mode in the component data-binding context.
onDown
Commands to run when a pointer down event occurs. The event generated has the following form.
"event": {
"source": {
"type": COMPONENT_TYPE, // The type of the component (e.g., "TouchWrapper", "VectorGraphic")
"handler": "Down",
... // Component source properties
},
"component": {
"x": Number, // X-position of the down event in the component (dp)
"y": Number, // Y-position of the down event in the component (dp)
"width": Number, // Width of the component in dp
"height": Number, // Height of the component in dp
}
}
Refer to Event source for a description of event.source
properties.
The onDown
handler runs its commands in fast mode in the component data-binding context.
The VectorGraphic
component adds an additional viewport
property to this event.
onMove
Commands to run when the pointer location moves. The event generated has the following form.
"event": {
"source": {
"type": COMPONENT_TYPE, // The type of the component (e.g., "TouchWrapper", "VectorGraphic")
"handler": "Move",
... // Component source properties
},
"component": {
"x": Number, // X-position of the move event in the component (dp)
"y": Number, // Y-position of the move event in the component (dp)
"width": Number, // Width of the component in dp
"height": Number, // Height of the component in dp
},
"inBounds": Boolean // True if the pointer is within the component bounds
}
The inBounds
calculation for the pointer position doesn't consider any overlapping components.
Refer to Event source for a description of event.source
properties.
The onMove
handler runs its commands in fast mode in the component data-binding context.
The VectorGraphic
component adds an additional viewport
property to this event.
onPress
Commands to run when a press event occurs. The event generated has the form:
"event": {
"source": {
"type": COMPONENT_TYPE, // The type of the component (e.g., "TouchWrapper", "VectorGraphic")
"handler": "Press",
... // Component source properties
}
}
Refer to Event source for a description of event.source
properties.
The onPress
handler runs its commands in normal mode in the component data-binding context.
onUp
Commands to run when a pointer up event occurs. The event generated has the form:
"event": {
"source": {
"type": COMPONENT_TYPE, // The type of the component (e.g., "TouchWrapper", "VectorGraphic")
"handler": "Up",
... // Component source properties
},
"component": {
"x": Number, // X-position of the up event in the component (dp)
"y": Number, // Y-position of the up event in the component (dp)
"width": Number, // Width of the component in dp
"height": Number, // Height of the component in dp
}
"inBounds": Boolean // True if the pointer is within the component bounds
}
The inBounds
calculation for the pointer position doesn't consider any overlapping components.
Refer to Event source for a description of event.source
properties.
The onUp
handler runs its commands in fast mode in the component data-binding context.
The VectorGraphic
component adds an additional viewport
property to this event.
Event handler rules
Mouse or tap events that the user initiates or performs within the transformed bounds of the touchable component trigger the pointer event handlers for that specific component. Alexa uses the following rules when running these handlers:
- The
onDown
handler runs when the down pointer occurs in the transformed bounds of the topmost touchable component. -
As long as the down pointer remains active, the
onMove
handler runs as the pointer location changes if the original down event occurred in the same component.For example, assume two components,
componentA
andcomponentB
.- The user touches
componentB
and moves the pointer. TheonMove
handler forcomponentB
runs. - The user touches
componentA
then moves the pointer into the bounds ofcomponentB
. TheonMove
handler forcomponentB
doesn't run.
- The user touches
-
When the down pointer is released, the
onUp
handler runs if the original down event occurred in the same component.- The user touches
componentB
and then releases the pointer. TheonUp
handler forcomponentB
runs. - The user touches
componentA
, moves into the bounds ofcomponentB
, and then releases the pointer. TheonUp
handler forcomponentB
doesn't run.
- The user touches
-
When the down pointer is released within the transformed bounds of the component, the
onPress
handler runs if the original down event occurred in the same component.- The user touches
componentB
, keeps the pointer within the bounds ofcomponentB
and then releases the pointer. TheonPress
handler forcomponentB
runs. - The user touches
componentB
, moves the pointer outside the bounds ofcomponentB
and releases the pointer. TheonPress
handler forcomponentB
doesn't run.
- The user touches
- The
onPress
handler always runs after theonUp
handler.
If two or more visible touchable components overlap at the point of the initial down pointer event, the topmost component receives the down event and all subsequent move, up, and press events. The lower components don't receive any events.
Gestures are special-purpose handlers that interpret specific motions or pointer actions, such as a swipe or a double-tap. When a gesture handler recognizes that a gesture has started, it runs the onCancel
handler. After the onCancel
handler completes, the gesture handler captures all the pointer events. The onUp
and onMove
handlers are ignored.
The onCancel
handler also runs if APL loses control of the pointer. This might occur if another app takes over the screen.
A touchable component is an actionable component and responds to "enter" key presses when the component has an onPress
handler. If the component doesn't have an onPress
handler, the component does nothing.
When the component has an onPress
handler, "enter" key presses do the following:
- Set the
pressed
component state totrue
when the user presses the enter key. - Set the
pressed
component state back tofalse
when the user releases the enter key. - Run the
onPress
handler.
You can override this behavior by capturing the Enter
and NumpadEnter
keyboard code
events and blocking propagation of the event.
Related topics
- Base Component Properties
- Actionable Component Properties
- TouchWrapper
- VectorGraphic
- Use Alexa Presentation Language with the ASK SDK v2
- Alexa.Presentation.APL Interface Reference
- Alexa Design Guide: Alexa Presentation Language
Last updated: Feb 29, 2024