kyleduo / SwitchButton

A cute widget of Switch Button for you to create beautiful and friendly UI.
4.72k stars 866 forks source link

SwitchButton setEnabled(false) makes onTouchEvent to return false #98

Closed igormorse closed 6 years ago

igormorse commented 7 years ago

Hello, I was working with this library for a couple mounths and just now I realized that if you run the method setEnabled(false) it prevents you from clicking in the Switch passing the clicking event to the parent.

Here is a code sample in SwitchButton.java:

@Override
public boolean onTouchEvent(MotionEvent event) {

    if (!isEnabled() || !isClickable() || !isFocusable()) {
        return false;
    }

If you check the documentation for onTouchEvent() , you'll find:

Returns: True if the event was handled, false otherwise.

Is this the expected behaviour ? I would like to block the Switching thing but I also wanted to be able to perform clicking on it but not doing the OnChecked thing.

kyleduo commented 7 years ago

Yes, and there is no standalone configuration to disable switch gesture. I think switch gesture is a good interaction and no need to disable it. However, the latest version, 2.0.0, change this behavior a little and if you use it in a scrollable view, SwitchButton will ignore vertical gestures so scrollable view will works fine. If this is the reason of you want to disable the gesture, you can update to the latest version and see if it has solved your problem.