Debouncable is action interface used to debounce user input actions.
debouncing
is good to prevent multiple clicks at the same time, double
clicks, and misclicks.
Library is published via JitPack
publishing platform. To use it in your project, add a reference to
JitPack maven to project level build.gradle
:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add library as dependency:
dependencies {
implementation 'com.github.RudolfHladik:debouncable:1.0.0'
}
Debouncable is meant to be used within your ViewModel
or presenter. Start
with Debouncable
interface implementation:
class MyViewModel : ViewModel() , Debouncable
Since this moment you can use debounceAction()
method to debounce user's
clicks:
class MyViewModel : ViewModel() , Debouncable {
fun onClickA() {
debounceAction {
// this code will be debounced
}
}
fun onClickB() = debounceAction { // more idiomatic way
// this code will be debounced
}
}
Debounce limit is set to 200ms
by default. In case you want to override
this value pass requested limit to debounceAction()
:
debounceAction(400L) {
// this code will be debounced
}
Current maintainer and main contributor is Rudolf Hladík.
Debouncable is available under the MIT license. See the LICENSE for more information.