New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Ui

inspectable

Common

Use this to group a common set of modifiers and provide [InspectorInfo] for the resulting modifier.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.ui:ui:1.7.0-beta04")
}

Overloads

@Deprecated(
    "This API will create more invalidations of your modifier than necessary, so it's " +
        "use is discouraged. Implementing the inspectableProperties method on " +
        "ModifierNodeElement is the recommended zero-cost alternative to exposing properties " +
        "on a Modifier to tooling.",
    level = DeprecationLevel.WARNING,

@Suppress("DeprecatedCallableAddReplaceWith"
fun Modifier.inspectable(
    noinline inspectorInfo: InspectorInfo.() -> Unit,
    factory: Modifier.() -> Modifier
)

Code Example

InspectableModifierSample

@Suppress("DEPRECATION"
@Composable
@Sampled
fun InspectableModifierSample() {

    /**
     * Sample with a single parameter
     */
    fun Modifier.simpleFrame(color: Color) = inspectable(
        inspectorInfo = debugInspectorInfo {
            name = "simpleFrame"
            value = color
        }
    ) {
        background(color, RoundedCornerShape(5.0.dp))
    }

    /**
     * Sample with multiple parameters
     */
    fun Modifier.fancyFrame(size: Dp, color: Color) = inspectable(
        inspectorInfo = debugInspectorInfo {
            name = "fancyFrame"
            properties["size"] = size
            properties["color"] = color
        }
    ) {
        background(color, RoundedCornerShape(size))
    }
}