androidx.compose.foundation.interaction

MutableInteractionSource

Interface · from org.jetbrains.compose.foundation:foundation:1.12.2

A InteractionSource that events can also be added to. Components take one in their interactionSource parameter and write press, hover and focus events into it. You read them out.

val interactionSource = remember { MutableInteractionSource() }
val pressed by interactionSource.collectIsPressedAsState()
Button(onClick = {}, interactionSource = interactionSource) {
    Text(if (pressed) "Release to send" else "Hold to send")
}

Always create it in remember, or a new one is made on every recomposition and the state is lost.

See InteractionSource for how to read the states and the events.

interface MutableInteractionSource : InteractionSource

Is a

How to get one

Create one with remember { MutableInteractionSource() }.

Create it

Ready-made values and functions that return it

Used by

Parameters that take a MutableInteractionSource.

61 more

Functions

emit

fun emit(interaction: Interaction)

Adds an event, like PressInteraction.Press(offset). A suspend function. Useful in tests, or to show a pressed state from code.

tryEmit

fun tryEmit(interaction: Interaction): Boolean

Adds an event without suspending. Returns false if it couldn't.