placeholder

fun Modifier.placeholder(enabled: Boolean = true, color: Color = LocalPlaceholderTheme.current.color, shape: Shape = LocalPlaceholderTheme.current.shape, highlight: PlaceholderHighlight? = LocalPlaceholderTheme.current.highlight, placeholderFadeTransitionSpec: () -> FiniteAnimationSpec<Float> = LocalPlaceholderTheme.current.placeholderFadeTransitionSpec, contentFadeTransitionSpec: () -> FiniteAnimationSpec<Float> = LocalPlaceholderTheme.current.contentFadeTransitionSpec): Modifier

Draws a placeholder effect over content while it is loading.

This modifier displays an animated placeholder overlay that covers the content when enabled is true, and smoothly transitions to reveal the actual content when enabled becomes false. It's commonly used to indicate loading states for images, text, and other UI elements.

The placeholder can be customized with different colors, shapes, and highlight animations. Several pre-built highlight effects are available in PlaceholderDefaults, including shimmer, fade, pulse, circular reveal, and light reveal.

Example usage:

// Basic placeholder with default fade effect
Text(
text = userName,
modifier = Modifier.placeholder(visible = isLoading)
)

// Customized placeholder with shimmer effect
Image(
painter = profileImage,
contentDescription = "Profile",
modifier = Modifier
.size(100.dp)
.placeholder(
visible = isLoading,
color = Color.LightGray,
shape = CircleShape,
highlight = PlaceholderDefaults.shimmer
)
)

// Placeholder without highlight animation
Card(
modifier = Modifier.placeholder(
visible = isLoading,
highlight = null
)
)

Return

A Modifier that draws the placeholder effect

Parameters

enabled

Whether the placeholder should be visible. When false, the actual content is shown.

color

The background color of the placeholder. Defaults to a semi-transparent gray.

shape

The shape of the placeholder. Defaults to RectangleShape.

highlight

The highlight animation effect to apply. Defaults to PlaceholderDefaults.fade. Set to null to disable highlight animations.

placeholderFadeTransitionSpec

Animation spec for fading the placeholder in/out. Defaults to a spring animation.

contentFadeTransitionSpec

Animation spec for fading the content in/out. Defaults to a spring animation.

See also

for pre-configured highlight effects

for creating custom highlight effects