android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.36k stars 8.28k forks source link

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

Open yagmurerdogan opened 1 year ago

yagmurerdogan commented 1 year ago

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[bot] commented 1 year ago

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.

gmikhail commented 1 year ago

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)