Swipe gestures
The gesture extension runs actions when the user swipes up, down, left, or right over the element.
Example
{
"type": "text",
"text": "Last swipe: @{last_swipe}",
"extensions": [
{
"id": "gesture",
"params": {
"swipe_left": [
{
"log_id": "swipe_left",
"typed": {
"type": "set_variable",
"variable_name": "last_swipe",
"value": {
"type": "string",
"value": "left"
}
}
}
],
"swipe_right": [
{
"log_id": "swipe_right",
"typed": {
"type": "set_variable",
"variable_name": "last_swipe",
"value": {
"type": "string",
"value": "right"
}
}
}
]
}
}
]
}
In this example, a swipe to the left or to the right writes the direction to the last_swipe string variable.
Parameters
|
Parameters |
Description |
|
|
Extension ID. |
|
|
Array of actions that run on a swipe up. Optional parameter. |
|
|
Array of actions that run on a swipe down. Optional parameter. |
|
|
Array of actions that run on a swipe to the left. Optional parameter. |
|
|
Array of actions that run on a swipe to the right. Optional parameter. |
Specify at least one of the parameters.
Connection
build.gradle
dependencies {
implementation "com.yandex.div:div-gesture:${versions.divkit}"
}
In the code:
val gestureExtensionHandler = DivGestureExtensionHandler(
parsingErrorLoggerFactory = object : ParsingErrorLoggerFactory {
override fun create(key: String) = ParsingErrorLogger.LOG
}
)
val divConfiguration = DivConfiguration.Builder(imageLoader)
.extension(gestureExtensionHandler)
.build()
ParsingErrorLoggerFactory creates the logger that receives the errors of parsing the actions from the parameter named key.
DivKitComponents(
...
extensionHandlers: [
GestureExtensionHandler()
]
)
import { Gesture } from '@divkitframework/divkit/client';
const map = new Map();
map.set('gesture', Gesture);
render({
id: 'test',
target: element,
json: {},
extensions: map
});
Learn more
You can discuss topics of interest in the DivKit user community in Telegram: https://t.me/divkit_community_en.