{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

MutableInteractionSource

public interface MutableInteractionSource extends InteractionSource


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 Flow, 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.

See also
InteractionSource
Interaction

Summary

Public methods

abstract void
emit(@NonNull Interaction interaction)

Emits interaction into interactions.

abstract boolean
tryEmit(@NonNull Interaction interaction)

Tries to emit interaction into interactions without suspending.

Inherited methods

From androidx.compose.foundation.interaction.InteractionSource
abstract @NonNull <Error class: unknown class><@NonNull Interaction>

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

Public methods

emit

abstract void emit(@NonNull Interaction interaction)

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

See also
tryEmit

tryEmit

abstract boolean tryEmit(@NonNull Interaction interaction)

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

See also
emit