androidx.compose.ui.graphics
graphicsLayer
Function · from org.jetbrains.compose.ui:ui:1.12.2
No hand-written docs yet.
A Modifier.Element 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.
With scaleX, scaleY, alpha, translationX, translationY, shadowElevation, rotationX, rotationY, rotationZ, cameraDistance, transformOrigin, shape, clip, renderEffect, ambientShadowColor, spotShadowColor, compositingStrategy, blendMode, colorFilter, outsetsSince 1.12
fun Modifier.graphicsLayer(
scaleX: Float = 1f,
scaleY: Float = 1f,
alpha: Float = 1f,
translationX: Float = 0f,
translationY: Float = 0f,
shadowElevation: Float = 0f,
rotationX: Float = 0f,
rotationY: Float = 0f,
rotationZ: Float = 0f,
cameraDistance: Float = DefaultCameraDistance,
transformOrigin: TransformOrigin = TransformOrigin.Center,
shape: Shape = RectangleShape,
clip: Boolean = false,
renderEffect: RenderEffect? = null,
ambientShadowColor: Color = DefaultShadowColor,
spotShadowColor: Color = DefaultShadowColor,
compositingStrategy: CompositingStrategy = CompositingStrategy.Auto,
blendMode: BlendMode = BlendMode.SrcOver,
colorFilter: ColorFilter? = null,
outsets: LayerOutsets = LayerOutsets.Zero,
)
scaleX: FloatOptional
scaleX: FloatOptionalDefault: 1f
see GraphicsLayerScope.scaleX
scaleY: FloatOptional
scaleY: FloatOptionalDefault: 1f
see GraphicsLayerScope.scaleY
alpha: FloatOptional
alpha: FloatOptionalDefault: 1f
see GraphicsLayerScope.alpha
translationX: FloatOptional
translationX: FloatOptionalDefault: 0f
see GraphicsLayerScope.translationX
translationY: FloatOptional
translationY: FloatOptionalDefault: 0f
see GraphicsLayerScope.translationY
shadowElevation: FloatOptional
shadowElevation: FloatOptionalDefault: 0f
see GraphicsLayerScope.shadowElevation
rotationX: FloatOptional
rotationX: FloatOptionalDefault: 0f
see GraphicsLayerScope.rotationX
rotationY: FloatOptional
rotationY: FloatOptionalDefault: 0f
see GraphicsLayerScope.rotationY
rotationZ: FloatOptional
rotationZ: FloatOptionalDefault: 0f
see GraphicsLayerScope.rotationZ
cameraDistance: FloatOptional
cameraDistance: FloatOptionalDefault: DefaultCameraDistance
see GraphicsLayerScope.cameraDistance
transformOrigin: TransformOriginOptional
transformOrigin: TransformOriginOptionalDefault: TransformOrigin.Center
see GraphicsLayerScope.transformOrigin
shape: ShapeOptional
shape: ShapeOptionalDefault: RectangleShape
see GraphicsLayerScope.shape
clip: BooleanOptional
clip: BooleanOptionalDefault: false
see GraphicsLayerScope.clip
renderEffect: RenderEffect?Optional
renderEffect: RenderEffect?OptionalDefault: null
see GraphicsLayerScope.renderEffect
ambientShadowColor: ColorOptional
ambientShadowColor: ColorOptionalDefault: DefaultShadowColor
see GraphicsLayerScope.ambientShadowColor
spotShadowColor: ColorOptional
spotShadowColor: ColorOptionalDefault: DefaultShadowColor
see GraphicsLayerScope.spotShadowColor
compositingStrategy: CompositingStrategyOptional
compositingStrategy: CompositingStrategyOptionalDefault: CompositingStrategy.Auto
see GraphicsLayerScope.compositingStrategy
blendMode: BlendModeOptionalSince 1.9
blendMode: BlendModeOptionalSince 1.9Default: BlendMode.SrcOver
see GraphicsLayerScope.blendMode
colorFilter: ColorFilter?OptionalSince 1.9
colorFilter: ColorFilter?OptionalSince 1.9Default: null
see GraphicsLayerScope.colorFilter
outsets: LayerOutsetsOptional
outsets: LayerOutsetsOptionalDefault: LayerOutsets.Zero
see GraphicsLayerScope.outsets
With block
fun Modifier.graphicsLayer(block: GraphicsLayerScope.() -> Unit): Modifier
block: GraphicsLayerScope.() -> UnitRequired
block: GraphicsLayerScope.() -> UnitRequiredblock on GraphicsLayerScope where you define the layer properties.
Library docs
A Modifier.Element 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 also be used to apply effects to content, such as scaling (scaleX,
scaleY), rotation (rotationX, rotationY, rotationZ), opacity (alpha), shadow
(shadowElevation, shape), clipping (clip, shape), as well as altering the result of the
layer with RenderEffect. Shadow color and ambient colors can be modified by configuring the
spotShadowColor and ambientShadowColor respectively.
CompositingStrategy determines whether or not the contents of this layer are rendered into an
offscreen buffer. This is useful in order to optimize alpha usages with
CompositingStrategy.ModulateAlpha which will skip the overhead of an offscreen buffer but can
generate different rendering results depending on whether or not the contents of the layer are
overlapping. Similarly leveraging CompositingStrategy.Offscreen is useful in situations where
creating an offscreen buffer is preferred usually in conjunction with BlendMode usage.
Note that if you provide a non-zero shadowElevation and if the passed shape is concave the
shadow will not be drawn on Android versions less than 10.
Also note that alpha values less than 1.0f will have their contents implicitly clipped to their
bounds unless CompositingStrategy.ModulateAlpha is specified or layer outsets are provided.
This is because an intermediate compositing layer is created to render contents into first before
being drawn into the destination with the desired alpha. This layer is sized to the bounds of the
composable this modifier is configured on, and contents outside of these bounds are omitted. To
avoid this implicit clipping, LayerOutsets can be used to increase the size of this layer
further from the composable's size. Note that the clip, shape, shadowElevation,
TransformOrigin will all still be based on the original size i.e. the bounds of the composable.
If the layer parameters are backed by a androidx.compose.runtime.State or an animated value
prefer an overload with a lambda block on GraphicsLayerScope as reading a state inside the
block will only cause the layer properties update without triggering recomposition and relayout.