Skip to content

Commit 10f3d3b

Browse files
Material Design Teamhunterstich
authored andcommitted
[Carousel]Prevent touch events from reaching hidden views.
PiperOrigin-RevId: 698207866
1 parent 06c9ab9 commit 10f3d3b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/java/com/google/android/material/carousel/MaskableFrameLayout.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ public boolean onTouchEvent(MotionEvent event) {
219219
return super.onTouchEvent(event);
220220
}
221221

222+
@Override
223+
public boolean onInterceptTouchEvent(MotionEvent event) {
224+
// Intercept touch events outside the masked bounds and prevent them from
225+
// reaching the children.
226+
if (!maskRect.isEmpty()) {
227+
float x = event.getX();
228+
float y = event.getY();
229+
if (!maskRect.contains(x, y)) {
230+
return true; // Intercept touch events outside the mask
231+
}
232+
}
233+
return super.onInterceptTouchEvent(event);
234+
}
235+
222236
@Override
223237
protected void dispatchDraw(Canvas canvas) {
224238
shapeableDelegate.maybeClip(canvas, super::dispatchDraw);

0 commit comments

Comments
 (0)