LookaheadAnimationVisualDebugging

Functions summary

Unit
@Composable
@ExperimentalLookaheadAnimationVisualDebugApi
LookaheadAnimationVisualDebugging(
    isEnabled: Boolean,
    overlayColor: Color,
    multipleMatchesColor: Color,
    unmatchedElementColor: Color,
    isShowKeyLabelEnabled: Boolean,
    content: @Composable () -> Unit
)

Allows enabling and customizing shared element and animated bounds animation debugging.

Cmn

Functions

LookaheadAnimationVisualDebugging

@Composable
@ExperimentalLookaheadAnimationVisualDebugApi
fun LookaheadAnimationVisualDebugging(
    isEnabled: Boolean = true,
    overlayColor: Color = Color(0x8034A853),
    multipleMatchesColor: Color = Color(0xFFEA4335),
    unmatchedElementColor: Color = Color(0xFF9AA0A6),
    isShowKeyLabelEnabled: Boolean = false,
    content: @Composable () -> Unit
): Unit

Allows enabling and customizing shared element and animated bounds animation debugging. Note that enabling LookaheadAnimationVisualDebugging affects the entire UI subtree generated by the content lambda. It applies to all descendants, regardless of whether they are defined within the same lexical scope.

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.LookaheadAnimationVisualDebugging
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

var isExpanded by mutableStateOf(false)
// Wrap content with LookaheadAnimationVisualDebugging to enable visual debugging.
// Optional parameters allow color customization and decision of whether to show key labels.
// Note that enabling LookaheadAnimationVisualDebugging affects the entire UI subtree generated
// by the content lambda. It applies to all descendants, regardless of whether they are defined
// within the same lexical scope.
LookaheadAnimationVisualDebugging(isShowKeyLabelEnabled = true) {
    SharedTransitionLayout(Modifier.fillMaxSize().clickable { isExpanded = !isExpanded }) {
        AnimatedVisibility(visible = isExpanded) {
            Box(
                Modifier.offset(100.dp, 100.dp)
                    .size(200.dp)
                    .sharedElement(
                        rememberSharedContentState(key = "box"),
                        animatedVisibilityScope = this,
                    )
                    .background(Color.Red)
            )
        }
        AnimatedVisibility(visible = !isExpanded) {
            Box(
                Modifier.offset(0.dp, 0.dp)
                    .size(50.dp)
                    .sharedElement(
                        rememberSharedContentState(key = "box"),
                        animatedVisibilityScope = this,
                    )
                    .background(Color.Blue)
            )
        }
    }
}
Parameters
isEnabled: Boolean = true

Boolean specifying whether to enable animation debugging.

overlayColor: Color = Color(0x8034A853)

The color of the translucent film covering everything underneath the lifted layer (where the shared elements and other elements rendered in overlay are rendered).

multipleMatchesColor: Color = Color(0xFFEA4335)

The color to indicate a shared element key with multiple matches.

unmatchedElementColor: Color = Color(0xFF9AA0A6)

The color to indicate a shared element key with no matches.

isShowKeyLabelEnabled: Boolean = false

Boolean specifying whether to print animated element keys.

content: @Composable () -> Unit

The composable content that debugging visualizations will apply to, although which visualizations appear depends on where the Modifiers are placed.

An example of how to use it: