2424import android .util .AttributeSet ;
2525import android .view .MotionEvent ;
2626import android .view .View ;
27+ import android .view .accessibility .AccessibilityNodeInfo ;
2728import android .widget .FrameLayout ;
2829import androidx .annotation .NonNull ;
2930import androidx .annotation .Nullable ;
@@ -45,6 +46,7 @@ public class MaskableFrameLayout extends FrameLayout implements Maskable, Shapea
4546
4647 private float maskXPercentage = NOT_SET ;
4748 private final RectF maskRect = new RectF ();
49+ private final Rect screenBoundsRect = new Rect ();
4850 @ Nullable private OnMaskChangedListener onMaskChangedListener ;
4951 @ NonNull private ShapeAppearanceModel shapeAppearanceModel ;
5052 private final ShapeableDelegate shapeableDelegate = ShapeableDelegate .create (this );
@@ -218,4 +220,25 @@ public boolean onTouchEvent(MotionEvent event) {
218220 protected void dispatchDraw (Canvas canvas ) {
219221 shapeableDelegate .maybeClip (canvas , super ::dispatchDraw );
220222 }
223+
224+ @ Override
225+ public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info ) {
226+ super .onInitializeAccessibilityNodeInfo (info );
227+ // Note: This is a workaround until b/273752775 is resolved. A11y bounds should be set by the
228+ // a11y framework.
229+ info .getBoundsInScreen (screenBoundsRect );
230+
231+ // If the child starts from a negative x, the screen bounds are already cut off at the
232+ // parent so there is no need to reduce the screen bound's left bound. Similarly for negative y.
233+ if (getX () > 0 ) {
234+ screenBoundsRect .left = (int ) (screenBoundsRect .left + maskRect .left );
235+ }
236+ if (getY () > 0 ) {
237+ screenBoundsRect .top = (int ) (screenBoundsRect .top + maskRect .top );
238+ }
239+ screenBoundsRect .right = screenBoundsRect .left + Math .round (maskRect .width ());
240+ screenBoundsRect .bottom = screenBoundsRect .top + Math .round (maskRect .height ());
241+
242+ info .setBoundsInScreen (screenBoundsRect );
243+ }
221244}
0 commit comments