graphicsLayer

Functions summary

Modifier

A Modifier.Node that makes content draw into a draw layer.

Cmn

Functions

Modifier.graphicsLayer

@ExperimentalFoundationStyleApi
fun Modifier.graphicsLayer(
    layerRequired: (() -> Boolean)? = null,
    block: GraphicsLayerScope.() -> Unit
): Modifier

A Modifier.Node that makes content draw into a draw layer. The draw layer can be invalidated separately from parents. A graphicsLayer should be used when the content updates independently from anything above it to minimize the invalidated content.

graphicsLayer can be used to apply effects to content, such as scaling, rotation, opacity, shadow, and clipping. Prefer this version when you have layer properties backed by a androidx.compose.runtime.State or an animated value as reading a state inside block will only cause the layer properties update without triggering recomposition and relayout.

NOTE: block can be invoked multiple times, which is why it's important for performance to minimize work done inside of it. block may also be invoked before effects.

layerRequired can be used to avoid creating a layer that will do nothing. The avoids the overhead of the layer if no properties will be modified from their default value.

Parameters
layerRequired: (() -> Boolean)? = null

return whether the layer is required. If the parameter is null or layerRequired returns true, a layer is created. If layerRequired returns false then the layer is not created and block is not invoked. This can be used to determine if a layer is necessary based on the properties that will be set by block.

block: GraphicsLayerScope.() -> Unit

block on GraphicsLayerScope where you define the layer properties.