Customization
The extension element is a data block that is used to change the behavior and display of elements. You can add an extension to any element.
Additional logic is described in the extension handler DivExtensionHandler.
Available extensions
|
ID |
Description |
Source code |
|
|
Increases the element. |
|
|
|
||
|
|
Controls text autocorrection in input elements (iOS only). |
|
|
|
Automatically crops images in div-image to the expected aspect ratio (iOS only). |
|
|
|
Fixes offscreen rendering issues in overlap containers (iOS only). |
|
|
|
Adds a blur effect to the element (iOS only). |
|
|
|
Applies complex graphical effects to the element background: blur, refraction, color adjustment, and rim highlight (Android only). |
Connection
Note
This section uses the Lottie extension as an example.
build.gradle
dependencies {
implementation "com.yandex.div:div-pinch-to-zoom:${versions.divkit}"
implementation "com.airbnb.android:lottie:${versions.lottie}"
implementation "com.yandex.div:div-lottie:${versions.lottie}"
}
In the code:
val pinchToZoomConfiguration = DivPinchToZoomConfiguration.Builder(this)
.host(window)
.dimColor(0xFF808080.toInt())
.build()
val rawResProvider = object : DivLottieRawResProvider {
override fun provideRes(url: String): Int? {
if (url == "res://love") return R.raw.love_anim
return null
}
override fun provideAssetFile(url: String): String? {
if (url == "asset://banana") return "lottie/lottie_1.json"
return null
}
}
val divConfiguration = DivConfiguration.Builder(DefaultDivImageLoader(Container.imageManager))
.experimentConfig(experimentConfig)
.actionHandler(actionHandler)
.divLogger(logger)
.extension(DivPinchToZoomExtensionHandler(pinchToZoomConfiguration))
.extension(DivLottieExtensionHandler(rawResProvider))
.build()
val divContext = DivContext(baseContext = this, configuration = divConfiguration)
divView = DivView(divContext)
Extension handlers must comply with the DivExtensionHandler protocol.
To connect the handler, pass it to DivBlockModelingContext:
DivBlockModelingContext(
...
extensionHandlers: [
PinchToZoomExtensionHandler(overlayView: rootView),
SomeExtensionHandler()
]
)
import { lottieExtensionBuilder } from '@divkitframework/divkit/client';
import Lottie from 'lottie-web/build/player/lottie';
const map = new Map();
map.set('lottie', lottieExtensionBuilder(Lottie.loadAnimation));
render({
id: 'test',
target: element,
json: {},
extensions: map
});
An example of a connected extension is available in the repository.
Lottie in an animated gif image
To connect the animation to a gif image, fill in the extensions array:
{
"extensions": [
{
"id": "lottie",
"params": {
"lottie_url": "https://assets9.lottiefiles.com/packages/lf20_edpg3c3s.json",
"repeat_count": 3,
"repeat_mode": "restart"
}
}
]
}
Note
repeat_count parameter behavior
repeat_count: 0— animation plays oncerepeat_count: 1— animation plays twicerepeat_count: N— animation plays N+1 timesrepeat_count: -1— infinite looping
|
Parameters |
Description |
|
|
Extension ID. |
|
|
Required URL to Lottie JSON if the When using unsupported URL schemes (not http/https/file/res), animation preloading will be skipped with an error logged. |
|
|
Required parameter if |
|
|
The number of animation repetitions. Use the |
|
|
The action after the animation ends. It can have the values:
|
|
|
The minimum frame from which the animation starts. Used for complex cyclic playback scenarios. |
|
|
Controls automatic animation playback during initialization. If set to |
Input autocorrection control
To control text autocorrection in input elements on iOS, use the input_autocorrection extension:
{
"extensions": [
{
"id": "input_autocorrection",
"params": {
"enabled": false
}
}
]
}
|
Parameters |
Description |
|
|
Extension ID. |
|
|
Controls whether autocorrection is enabled for the input field. Set to |
Automatic image aspect ratio correction
To automatically crop images in div-image to the expected aspect ratio, use the aspect-correction extension (iOS only):
{
"extensions": [
{
"id": "aspect-correction",
"params": {
"aspect_tolerance": 0.001
}
}
]
}
|
Parameters |
Description |
|
|
Extension ID. |
|
|
Aspect ratio deviation tolerance (optional). If the actual aspect ratio differs from the expected one by less than this value, cropping is not applied. Default: 0.001. |
Features:
- Images are cropped centrally when there is a significant deviation from the expected aspect ratio
- If the actual aspect ratio is less than expected - cropped by height
- If the actual aspect ratio is greater than expected - cropped by width
- Caching of processed images is supported for performance optimization
Integration on iOS:
DivBlockModelingContext(
...
extensionHandlers: [
AspectCorrectionExtensionHandler(aspectTolerance: 0.001)
]
)
Rasterization for fixing offscreen rendering
To fix offscreen rendering issues in overlap containers, use the rasterize extension (iOS only):
{
"extensions": [
{
"id": "rasterize"
}
]
}
|
Parameters |
Description |
|
|
Extension ID. |
Features:
- Applies rasterization to blocks via
layer.shouldRasterize = true - Uses
UIScreen.main.scalefor optimal quality - Solves offscreen rendering issues in overlap containers
Integration on iOS:
DivBlockModelingContext(
...
extensionHandlers: [
RasterizeExtensionHandler()
]
)
Blur effect
To add a blur effect to an element, use the blur extension (iOS only):
{
"extensions": [
{
"id": "blur",
"params": {
"style": "regular"
}
}
]
}
|
Parameters |
Description |
|
|
Extension ID. |
|
|
Blur effect style. Available values:
|
Features:
- Uses iOS system blur effects (UIBlurEffect)
- Supports both basic styles and material styles with variants for light and dark themes
- Applied to the entire element to which the extension is added
Integration on iOS:
DivBlockModelingContext(
...
extensionHandlers: [
BlurExtensionHandler()
]
)
Background effects
To apply graphical effects to an element background, use the backdrop-effect extension (Android only):
{
"extensions": [
{
"id": "backdrop-effect",
"params": {
"blur_radius": 10.0,
"refraction_height": 5.0,
"refraction_strength": 0.5,
"chromatic_aberration": 0.3,
"brightness": 1.2,
"contrast": 1.1,
"saturation": 0.9,
"rim_highlight_angle": 45.0,
"rim_highlight_fade": 0.5,
"corner_radius": 16.0
}
}
]
}
|
Parameters |
Description |
|
|
Extension ID. |
|
|
Background blur radius in pixels. Optional parameter. |
|
|
Refraction effect height. Optional parameter. |
|
|
Refraction effect strength (from 0.0 to 1.0). Optional parameter. |
|
|
Chromatic aberration strength for refraction effect (from 0.0 to 1.0). Optional parameter. |
|
|
Background brightness coefficient. Value 1.0 means no change. Optional parameter. |
|
|
Background contrast coefficient. Value 1.0 means no change. Optional parameter. |
|
|
Background saturation coefficient. Value 1.0 means no change. Optional parameter. |
|
|
Light angle for rim highlight in degrees. Optional parameter. |
|
|
Rim highlight fade coefficient (from 0.0 to 1.0). Optional parameter. |
|
|
Corner radius for all corners in pixels. Optional parameter. |
|
|
Array of 4 values for individual corner radii [topLeft, topRight, bottomRight, bottomLeft]. Optional parameter. |
Features:
- On Android 13+ (Tiramisu),
RenderNodeis used for optimal performance - On older Android versions,
Canvasis used to capture the background - The extension automatically tracks changes in the background view position and state (scroll, layout, draw)
- Supports two rim highlight variants: plain (
Plain) and with reflection (Reflection) for Android 13+
Integration on Android:
val backdropEffectHandler = BackdropEffectExtensionHandler()
val divConfiguration = DivConfiguration.Builder(imageLoader)
.extension(backdropEffectHandler)
.build()
val divContext = DivContext(baseContext = this, configuration = divConfiguration)
For programmatic effect configuration, use BackdropEffectDrawable:
val backdropDrawable = BackdropEffectDrawable()
backdropDrawable.setBlurEffect(radius = 10f)
backdropDrawable.setRefractionEffect(height = 5f, strength = 0.5f, chromaticAberration = 0.3f)
backdropDrawable.setColorAdjustment(brightness = 1.2f, contrast = 1.1f, saturation = 0.9f)
backdropDrawable.setRimHighlightEffect(angle = 45f, fade = 0.5f)
backdropDrawable.setCornerRadius(radius = 16f)
// Or for individual radii:
backdropDrawable.setCornerRadii(floatArrayOf(16f, 8f, 8f, 16f))
Learn more
You can discuss topics of interest in the DivKit user community in Telegram: https://t.me/divkit_community_en.