MutableInteractionSource


MutableInteractionSource represents a stream of Interactions corresponding to events emitted by a component. These Interactions can be used to change how components appear in different states, such as when a component is pressed or dragged.

Lower level interaction APIs such as androidx.compose.foundation.clickable and androidx.compose.foundation.gestures.draggable have an MutableInteractionSource parameter, which allows you to hoist an MutableInteractionSource and combine multiple interactions into one event stream.

MutableInteractionSource exposes emit and tryEmit functions. These emit the provided Interaction to the underlying interactions, allowing consumers to react to these new Interactions.

An instance of MutableInteractionSource can be created by using the MutableInteractionSource factory function. This instance should be remembered before it is passed to other components that consume it.

Summary

Public functions

suspend Unit
emit(interaction: Interaction)

Emits interaction into interactions.

Cmn
Boolean
tryEmit(interaction: Interaction)

Tries to emit interaction into interactions without suspending.

Cmn

Inherited properties

From androidx.compose.foundation.interaction.InteractionSource
Flow<Interaction>

Flow representing the stream of all Interactions emitted through this InteractionSource.

Cmn

Public functions

emit

suspend fun emit(interaction: Interaction): Unit

Emits interaction into interactions. This method is not thread-safe and should not be invoked concurrently.

See also
tryEmit

tryEmit

fun tryEmit(interaction: Interaction): Boolean

Tries to emit interaction into interactions without suspending. It returns true if the value was emitted successfully.

See also
emit