MutableInteractionSource
interface MutableInteractionSource : InteractionSource
MutableInteractionSource represents a stream of Interaction
s corresponding to events emitted by
a component. These Interaction
s 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
Flow
, allowing consumers to react to these new
Interaction
s.
An instance of MutableInteractionSource can be created by using the MutableInteractionSource
factory function. This instance should be remember
ed before it is passed to other components
that consume it.
Functions
suspend fun emit(interaction: Interaction)
Emits interaction
into interactions
. This method is not thread-safe and should not be
invoked concurrently.
fun tryEmit(interaction: Interaction): Boolean
Tries to emit interaction
into interactions
without suspending. It returns true
if the
value was emitted successfully.