Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fab button crash issue with double tap [issue- #1027] #1070

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yagmurerdogan
Copy link

I create a view extension called "clickWithDebounce" to fix fab button crash issue with double tap. [issue #1027 ]
Clicks shorter than 1 second cannot be made.
Thus, we can use "clickWithDebounce" instead of "setOnClickListener" without any crash.

@google-cla
Copy link

google-cla bot commented Jan 5, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.


import android.view.View

fun View.clickWithDebounce(debounceTime: Long = 1000L, action: () -> Unit) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be easier to understand the variable's purpose if it had a more meaningful name, such as "minClickInterval" or "clickThrottleInterval". This indicates that the variable represents the minimum amount of time between clicks to execute an action.

@gmikhail
Copy link

gmikhail commented Mar 2, 2023

I don't think adding a delay is the right way. Many people on StackOverflow recommend something like this (note that this is code from my app not from this sample app):

val action = CurrentFragmentDirections.actionCurrentFragmentToSecondFragment(args)
val navController = findNavController()
// Navigate only if we located in the current fragment (currentDestination id changed if we already navigated)
if(navController.currentDestination?.id == R.id.currentFragment)
    navController.navigate(action)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants