keys

fun View.keys(handled: (KeyEvent) -> Boolean = { true }): Flow<KeyEvent>

Create a Flow of key events on the View instance.

Parameters

handled

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

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.keys { event.keyCode == KeyEvent.KEYCODE_ENTER }
.onEach { event ->
// handle key event
}
.launchIn(uiScope)