material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.43k stars 3.08k forks source link

[Slider] When select a value not drag the slider ,the onChange method doesn't notify #853

Closed ShowMeThe closed 4 years ago

ShowMeThe commented 4 years ago

Description: When I update the libray from com.google.android.material:material:1.2.0-alpha02 to com.google.android.material:material:1.2.0-alpha03, but when I select a new value the tooltip didn't show and the method of onChange didn't work,the same problem occur in the catalog

Expected behavior: it should working like 1.20-alpha02

Source code:

   <com.google.android.material.slider.Slider
                        android:id="@+id/slide"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"

                       />
        slide.valueFrom = 0f
        slide.valueTo = 20f
        slide.stepSize = 1f

 slide.setOnChangeListener { slider, value ->
            //do something
        }

Android API version: Android Q

Material Library version: com.google.android.material:material:1.2.0-alpha03

Device: oneplus 6

afohrman commented 4 years ago

It seems like the bug you're encountering is that dragging the slider to a new value invokes the onChangeListener, but just selecting a new value without dragging the slider to the new value does not invoke the onChangeListener. If that's not the case, please clarify the issue.

Assuming this is the issue, I was able to reproduce this and I'll bring it to the attention of the engineer currently developing the slider.

ShowMeThe commented 4 years ago

yes,as you say,not only dragging a new value but also selecting should invokes the onChangeListener.

afohrman commented 4 years ago

Okay thank you for clarifying.

cketcham commented 4 years ago

In 1.2.0-alpha03 we added a fix to prevent the Slider from intercepting scroll events from the parent. It looks like in this case it's no longer dispatching the change because we avoid handling the touch event unless there is enough horizontal movement. I'll take a look.

ghost commented 4 years ago

I also can't set slider to a value by selecting it. New value is selected only when I drag of swipe the slider. 1.2.0-alpha06

ExploiTR commented 5 months ago

@pekingme It's still there in latest stable and latest alpha.

Thought maybe this can be a fix : slider.setOnClickListener(v1 -> listener.onValueChange(slider, slider.getValue(), true));

But it didn't work.

aronyi commented 4 months ago

one could misuse setLabelFormatter for that purpose. But just be aware that it gets called multiple times per click and that you should not overload it.