🌈 Create new beautiful Compose Gradients with our new wesite ->
Interface

CompositionLocalConsumerModifierNode

Implementing this interface allows your Modifier.Node subclass to read CompositionLocals via the currentValueOf function.

CompositionLocalConsumingModifierSample

@Sampled
@Composable
fun CompositionLocalConsumingModifierSample() {
    val localBackgroundColor = compositionLocalOf { Color.White }
    class BackgroundColor :
        Modifier.Node(), DrawModifierNode, CompositionLocalConsumerModifierNode {
        override fun ContentDrawScope.draw() {
            val backgroundColor = currentValueOf(localBackgroundColor)
            drawRect(backgroundColor)
            drawContent()
        }
    }
    val backgroundColorElement =
        object : ModifierNodeElement<BackgroundColor>() {
            override fun create() = BackgroundColor()

            override fun update(node: BackgroundColor) {}

            override fun hashCode() = System.identityHashCode(this)

            override fun equals(other: Any?) = (other === this)

            override fun InspectorInfo.inspectableProperties() {
                name = "backgroundColor"
            }
        }