Reusing blocks on iOS

On iOS, DivKit reuses views that have already been created in two cases:

Reuse when new DivData is set

When a new DivData is set, DivKit always tries to reuse the elements that have already been created. If a view matches the type of the new block, it is not created again but updated with the new data. No additional setup is required for this.

Reuse in complex containers

In complex containers, such as gallery, grid, and tabs, DivKit reuses the views of elements while scrolling. The reuse_id property defines which elements can reuse each other's views.

Using the reuse_id property

For more efficient reuse of blocks in complex containers, it is recommended to set the reuse_id property for blocks with the same structure. This will allow DivKit to reuse views more efficiently.

Example:
{
    "type": "gallery",
    "items": [
        {
            "type": "container",
            "reuse_id": "video_block",
            "items": [
                {
                    "type": "video",
                    ...
                }
            ]
        },
        {
            "type": "container",
            "reuse_id": "image_block",
            "items": [
                {
                    "type": "image",
                    ...
                }
            ]
        },
        {
            "type": "container",
            "reuse_id": "image_block",
            "items": [
                {
                    "type": "image",
                    ...
                }
            ]
        },
        {
            "type": "container",
            "reuse_id": "video_block",
            "items": [
                {
                    "type": "video",
                    ...
                }
            ]
        }
    ]
}

In this example, blocks with the same reuse_id will be reused among themselves. This is especially important for heavy objects such as video to avoid unnecessary recreation.

Learn more

You can discuss topics of interest in the DivKit user community in Telegram: https://t.me/divkit_community_en.

DivKit Repository

Previous