clicks

fun MenuItem.clicks(handled: (MenuItem) -> Boolean = { true }): Flow<Unit>

Create a Flow of click events on the MenuItem instance.

Parameters

handled

function to be invoked with each value to determine the return value of the underlying MenuItem.OnMenuItemClickListener. Note that the Flow will only emit when this function evaluates to true.

Note: Created flow keeps a strong reference to the MenuItem instance until the coroutine that launched the flow collector is cancelled.

Example of usage:

menuItem.clicks { it.isChecked }
.onEach {
// handle menu item clicked
}
.launchIn(uiScope)

Create a Flow of click events on the View instance.

Note: Created flow keeps a strong reference to the View instance until the coroutine that launched the flow collector is cancelled.

Example of usage:

view.clicks()
.onEach {
// handle view clicked
}
.launchIn(uiScope)