Marc
04/03/2024, 6:13 PMUme Channel
04/03/2024, 6:40 PMAlexander Maryanovsky
04/03/2024, 7:57 PM/**
* Invokes [action] when the [InteractionSource] emits a [FocusInteraction.Focus] and then [FocusInteraction.Unfocus].
*/
@Composable
inline fun InteractionSource.onLostFocus(crossinline action: () -> Unit) {
LaunchedEffect(this) {
var hasFocus = false
interactions.collect { interaction ->
when (interaction) {
is FocusInteraction.Focus -> hasFocus = true
is FocusInteraction.Unfocus -> {
if (hasFocus)
action()
hasFocus = false
}
}
}
}
}
Alexander Maryanovsky
04/03/2024, 7:58 PM