We just launched Compose Examples featuring over 150+ components! Check it out →

indication

Common

Modifier in Compose Foundation

Draws visual effects for this component when interactions occur.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation:1.8.0-alpha04")
}

Overloads


fun Modifier.indication(interactionSource: InteractionSource, indication: Indication?): Modifier

Parameters

namedescription
interactionSource[InteractionSource] that will be used by [indication] to draw visual effects - this [InteractionSource] represents the stream of [Interaction]s for this component.
indication[Indication] used to draw visual effects. If null, no visual effects will be shown for this component.

Code Example

IndicationSample

@Composable
fun IndicationSample() {
    val interactionSource = remember { MutableInteractionSource() }
    Column {
        Text(
            text = "Click me and my neighbour will indicate as well!",
            modifier =
                Modifier
                    // clickable will dispatch events using MutableInteractionSource
                    .clickable(
                        interactionSource = interactionSource,
                        indication = LocalIndication.current
                    ) {
                        /** do something */
                    }
                    .padding(10.dp)
        )
        Spacer(Modifier.requiredHeight(10.dp))
        Text(
            text = "I'm neighbour and I indicate when you click the other one",
            modifier =
                Modifier
                    // this element doesn't have a click, but will show default indication from the
                    // CompositionLocal as it accepts the same MutableInteractionSource
                    .indication(interactionSource, LocalIndication.current)
                    .padding(10.dp)
        )
    }
}
by @alexstyl