DrawModifierNode

Known direct subclasses
CacheDrawModifierNode

Expands on the androidx.compose.ui.node.DrawModifierNode by adding the ability to invalidate the draw cache for changes in things like shapes and bitmaps (see Modifier.border for a usage examples).


A Modifier.Node that draws into the space of the layout.

This is the androidx.compose.ui.Modifier.Node equivalent of androidx.compose.ui.draw.DrawModifier

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.node.DrawModifierNode
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.platform.InspectorInfo

class CircleNode(var color: Color) : DrawModifierNode, Modifier.Node() {
    override fun ContentDrawScope.draw() {
        drawCircle(color)
    }
}
data class CircleElement(val color: Color) : ModifierNodeElement<CircleNode>() {
    override fun create() = CircleNode(color)

    override fun update(node: CircleNode) {
        node.color = color
    }

    override fun InspectorInfo.inspectableProperties() {
        name = "color"
        properties["color"] = color
    }
}
fun Modifier.circle(color: Color) = this then CircleElement(color)
Box(Modifier.fillMaxSize().circle(Color.Blue))

Summary

Public functions

Unit
Cmn
open Unit
Cmn

Extension functions

Unit

Invalidates this modifier's draw layer, ensuring that a draw pass will be run on the next frame.

Cmn

Inherited functions

From androidx.compose.ui.node.DelegatableNode
open Unit

Invoked when the density changes for this node.

Cmn
open Unit

Invoked when the layout direction changes for this node.

Cmn

Inherited properties

From androidx.compose.ui.node.DelegatableNode
Modifier.Node

A reference of the Modifier.Node that holds this node's position in the node hierarchy.

Cmn

Public functions

draw

fun ContentDrawScope.draw(): Unit

onMeasureResultChanged

open fun onMeasureResultChanged(): Unit

Extension functions

invalidateDraw

fun DrawModifierNode.invalidateDraw(): Unit

Invalidates this modifier's draw layer, ensuring that a draw pass will be run on the next frame.