material-components / material-components/material-components-android

[MaterialButtonGroup] Long press gesture detectors on children may not work (depending on position)

Open
#5,097 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**ATTENTION: This library is now in maintenance mode.**
**See https://github.com/material-components/material-components-android#readme.**

**Only critical issues will be addressed.**

---

**Description:** Long press gesture detector on a button in `MaterialButtonGroup` often fails (depending on its position).

**Expected behavior:** Gesture should be reliably detected.

**Android API version:** 17

**Material Library version:** 1.14.0

**Device:** Pixel

This is more for posterity than anything else, as I assume it won't be fixed. I have a `MaterialButtonGroup` with 3 `MaterialButton` children. Buttons at index 0 and 2 have a `GestureDetector` to detect a long press. Index 1 has weight 0, the others have weight 1.

The button at index 0 reliably detects the gesture, but button at index 2 doesn't. If moved from index 2 to 1, it works. This is because the button shape change that happens when it is pressed moves the `MotionEvent` location, such that it sometimes (not always) falls out of the detector's slop rectangle.

Other than disabling the button shape change (setting `app:buttonSizeChange` to `@null`) I haven't found a way around it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MaterialButtonGroup entry point and reproduce the long-press behavior with three MaterialButton children, focusing on how button shape changes affect MotionEvent positions. Verify behavior for children at different positions, including index 2, while keeping button-size changes enabled; done means long presses are detected reliably.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.