Prevents multiple rapid clicks by disabling the view temporarily after a click, helping avoid unintended repeated actions.
fun View.onThrottledClick(
throttleDelay: Long = 500L,
onClick: (View) -> Unit
) {
setOnClickListener {
onClick(this)
isClickable = false
postDelayed({ isClickable = true }, throttleDelay)
}
}
button.onThrottledClick {
// Action to perform on click
}
Inspired by Reddit discussion by k1llrogg.