Avoid button multiple rapid clicks

前端 未结 20 1473
猫巷女王i
猫巷女王i 2020-11-28 02:55

I have a problem with my app that if the user clicks the button multiple times quickly, then multiple events are generated before even my dialog holding the button disappear

20条回答
  •  死守一世寂寞
    2020-11-28 03:03

    Put a little example here

    view.safeClick { doSomething() }
    

    @SuppressLint("CheckResult")
    fun View.safeClick(invoke: () -> Unit) {
        RxView
            .clicks(this)
            .throttleFirst(300, TimeUnit.MILLISECONDS)
            .subscribe { invoke() }
    }
    

提交回复
热议问题