MutableInteractionSource

MutableInteractionSource 代表一个与组件发出的事件相对应的 Interaction 事件流。 它继承自 InteractionSource,并增加了发射新 Interaction 的能力。

clickabledraggable 这样的底层交互 API 拥有一个 MutableInteractionSource 参数, 这允许您将一个 MutableInteractionSource 实例进行状态提升,并将多个交互合并到一个事件流中。

MutableInteractionSource 提供了 emittryEmit 函数。这些函数会将给定的 Interaction 发射到底层的 interactions Flow 中,从而允许消费者对这些新的 Interaction 做出反应。

通常,您应该通过调用 MutableInteractionSource() 工厂函数来创建一个实例,并在它被传递给其他组件之前 使用 remember 将其记住。

Author

M8Test, [email protected], https://m8test.com

See also

Functions

Link copied to clipboard
abstract suspend fun emit(interaction: Interaction)

interaction 发射到 interactions 事件流中。

Link copied to clipboard

获取一个 Flow,它代表了通过此 InteractionSource 发出的所有 Interaction 的事件流。

Link copied to clipboard
abstract fun tryEmit(interaction: Interaction): Boolean

尝试立即将 interaction 发射到 interactions 事件流中,而不会挂起。