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

setOnSpinnerOutsideTouchListener does not fire #11

Closed
davischung opened this issue Apr 3, 2020 · 12 comments
Closed

setOnSpinnerOutsideTouchListener does not fire #11

davischung opened this issue Apr 3, 2020 · 12 comments
Assignees
Labels
released released already the last version

Comments

@davischung
Copy link

Please complete the following information:

  • Library Version [e.g. v1.0.0] : 1.0.5
  • Affected Device(s) : Google Pixel 3a

Describe the Bug:

Im using Kotlin with PowerSpinner, setting the onSpinnerOutsideTouchListener using setOnSpinnerOutsideTouchListener { view, motionEvent -> } does not get fired while touching outside spinner when the spinner is open

Expected Behavior:

Expect to get event fired when touching outside spinner when the spinner is open, so that I could close the spinner. It would be good if the spinner could be closed when user click the physical back button.

@skydoves skydoves self-assigned this Apr 4, 2020
@skydoves skydoves added the Release Next This feature will be released on next version label Apr 4, 2020
@skydoves
Copy link
Owner

skydoves commented Apr 4, 2020

@davischung
Hi, I checked it and It will be fixed in the next release.
Thank you for your issue :)

@mariooooo
Copy link

it would be great if you fixed it

@skydoves
Copy link
Owner

skydoves commented Apr 16, 2020

If there is no more issue, the fixed version will be released today. Thank you :)

@skydoves
Copy link
Owner

@davischung @mariooooo
It's released a new version 1.0.6. Thank you for your issue :)

@davischung
Copy link
Author

@skydoves @mariooooo
Verified it fired on 1.0.6, good job.

@mariooooo
Copy link

mariooooo commented Apr 22, 2020

@skydoves
I don’t know, but it doesn’t work for me, maybe I'm doing something wrong
spinner.setOnSpinnerOutsideTouchListener { view, motionEvent -> println("outside touch") spinner.dismiss() }
youtube

@Elytum
Copy link

Elytum commented Apr 23, 2020

Hi !
Same here, 1.0.6 didn't fix the issue, still having to resort to a dirty use of "dispatchTouchEvent" in the activity.
Will try to understand how to fix it later if needed, anyway thanks for the library !

@mariooooo
Copy link

@skydoves
what about this problem?

@skydoves
Copy link
Owner

skydoves commented Apr 27, 2020

@mariooooo
Hi, did you build using the demo project?
It would not be fired if the spinnerVIew is not focusable because of other editText.

Add the below code to the MainActivity.

spinnerView.spinnerOutsideTouchListener = object : OnSpinnerOutsideTouchListener {
      override fun onSpinnerOutsideTouch(view: View, event: MotionEvent) {
        Toast.makeText(baseContext, "touched outside", Toast.LENGTH_SHORT).show()
        spinnerView.dismiss()
      }
    }

@davischung
Copy link
Author

@skydoves
There is a side-issue produced by this setOnSpinnerItemSelectedListener fix. If you click on the PowerSpinnerView it will shows the dropdown, clicking one more time should dismiss the dropdown.

The intention to add a setOnSpinnerOutsideTouchListener is to dismiss the dropdown while click was being detected outside the dropdown, to implement is to call dismiss() in the callback function. However, by adding a setOnSpinnerOutsideTouchListener, clicking on the PowerSpinnerView when dropdown is showing will fire showOrDismiss twice if dismiss() is being called within setOnSpinnerOutsideTouchListener {}, resulting unable to dismiss the PowerSpinnerView dropdown by clicking it again.

One quick fix on my side is to add some handling like below to override the onClickListener:

var dismissTime: Date? = null
binding.spinnerRegionCode.apply {
    ...
    setOnSpinnerOutsideTouchListener { _, _ ->
        dismissTime = Date()
        binding.spinnerRegionCode.dismiss()
    }
}
binding.spinnerRegionCode.setOnClickListener {
    if (Date().time - (dismissTime?.time ?: 0) > 200) {
        binding.spinnerRegionCode.showOrDismiss()
    }
    dismissTime = null
}

See if you could handle it within the library. Thanks.

@ShivamDev31
Copy link

Facing the same issue as @davischung

@skydoves
Copy link
Owner

It is released on the new version 1.0.8!
And you can set the new attribute debounce_duration.

@skydoves skydoves added released released already the last version and removed Release Next This feature will be released on next version labels May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released released already the last version
Projects
None yet
Development

No branches or pull requests

5 participants