Compose Modifier

graphicsLayer

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

graphicsLayer

Source set: Common
public 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 of 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 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 block on GraphicsLayerScope where you define the layer properties.
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: