material-components-android
material-components-android copied to clipboard
[TextField] editText onTouchListener should be onClickListener
Description: DropdownMenuEndIconDelegate sets a touch listener on the autocomplete editText
in DropdownMenuEndIconDelegate.java. The return false
results in this touch listener being triggered twice, once for MotionEvent.ACTION_UP
and once for the subsequent MotionEvent.ACTION_DOWN
.

Expected behavior: Observe in the video the double ripple effect due to onTouchListener being triggered twice. It should only be a single ripple effect.
Source code:
private void setUpDropdownShowHideBehavior(@NonNull final AutoCompleteTextView editText) {
// Set whole layout clickable.
editText.setOnTouchListener( // this should be a click listener
new OnTouchListener() {
@Override
public boolean onTouch(@NonNull View v, @NonNull MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (isDropdownPopupActive()) {
dropdownPopupDirty = false;
}
showHideDropdown(editText);
updateDropdownPopupDirty();
}
return false;
}
});
Minimal sample app repro: Please consider attaching a minimal sample app that reproduces the issue. This will help narrow down the conditions required for reproducing the issue, and it will speed up the bug fix process. You may attach a zip file of the sample app or link to a GitHub repo that contains the sample app.
Android API version: 31
Material Library version: 1.6.1
Device: Pixel 4 API 31 xxhdpi emulator
To help us triage faster, please check to make sure you are using the latest version of the library.
We also happily accept pull requests.
I don't see the double ripple effect happening in our MDC catalog, are you doing anything else to the menu?
The code in the touch listener is only triggered if the event is MotionEvent.ACTION_UP
so it's ignored for any other motion events. Unfortunately, we can't switch that to be a click listener because it would break the current behavior, as a click listener is only triggered if the text input layout has focus.
Closing this issue for now due to no further info available. Please feel free to reopen it if this is still happening.