Skip to content

Commit

Permalink
[TextInputLayout][a11y] Fixed text field's focused rect wrong behavio…
Browse files Browse the repository at this point in the history
…r when using a11y magnification.

Before, in requestRectangleOnScreen we were setting the text input layout’s rectangle to a specific and constant position, which caused the zoomed in screen to be fixed to the left instead of following the input text as it was typed. We should use the edit text’s rectangle’s position first, then adjust for the text field’s height (which includes the helper/error text), then use that updated rectangle on the super call of the method.

PiperOrigin-RevId: 435402032
(cherry picked from commit dce4419)
  • Loading branch information
leticiarossi authored and hunterstich committed Mar 22, 2022
1 parent 981129f commit a8d8e70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
Expand Up @@ -152,45 +152,42 @@ public boolean isTextInputLayoutFocusedRectEnabled() {
return textInputLayoutFocusedRectEnabled;
}

private boolean shouldUseTextInputLayoutFocusedRect(@Nullable TextInputLayout textInputLayout) {
return textInputLayout != null && textInputLayoutFocusedRectEnabled;
}

@Override
public void getFocusedRect(@Nullable Rect r) {
super.getFocusedRect(r);
TextInputLayout textInputLayout = getTextInputLayout();
if (textInputLayout != null
&& textInputLayoutFocusedRectEnabled
&& r != null) {
if (shouldUseTextInputLayoutFocusedRect(textInputLayout) && r != null) {
textInputLayout.getFocusedRect(parentRect);
r.bottom = parentRect.bottom;
}
}

@Override
public boolean getGlobalVisibleRect(@Nullable Rect r, @Nullable Point globalOffset) {
boolean result = super.getGlobalVisibleRect(r, globalOffset);
TextInputLayout textInputLayout = getTextInputLayout();
if (textInputLayout != null
&& textInputLayoutFocusedRectEnabled
&& r != null) {
textInputLayout.getGlobalVisibleRect(parentRect, globalOffset);
r.bottom = parentRect.bottom;
}
return result;
return shouldUseTextInputLayoutFocusedRect(textInputLayout)
? textInputLayout.getGlobalVisibleRect(r, globalOffset)
: super.getGlobalVisibleRect(r, globalOffset);
}

@Override
public boolean requestRectangleOnScreen(@Nullable Rect rectangle) {
boolean result = super.requestRectangleOnScreen(rectangle);
TextInputLayout textInputLayout = getTextInputLayout();
if (textInputLayout != null && textInputLayoutFocusedRectEnabled) {
if (shouldUseTextInputLayoutFocusedRect(textInputLayout) && rectangle != null) {
int bottomOffset = textInputLayout.getHeight() - getHeight();
parentRect.set(
0,
textInputLayout.getHeight()
- getResources().getDimensionPixelOffset(R.dimen.mtrl_edittext_rectangle_top_offset),
textInputLayout.getWidth(),
textInputLayout.getHeight());
textInputLayout.requestRectangleOnScreen(parentRect, true);
rectangle.left,
rectangle.top,
rectangle.right,
rectangle.bottom + bottomOffset);
return super.requestRectangleOnScreen(parentRect);
} else {
return super.requestRectangleOnScreen(rectangle);
}
return result;
}

@Override
Expand Down
Expand Up @@ -34,8 +34,6 @@
<dimen name="mtrl_textinput_box_stroke_width_focused">2dp</dimen>
<dimen name="mtrl_textinput_box_label_cutout_padding">4dp</dimen>

<dimen name="mtrl_edittext_rectangle_top_offset">12dp</dimen>

<!-- Dimens for edit text's top and bottom padding adjustments for large font scale settings. -->
<dimen name="material_filled_edittext_font_1_3_padding_top">23dp</dimen>
<dimen name="material_filled_edittext_font_1_3_padding_bottom">12dp</dimen>
Expand Down

0 comments on commit a8d8e70

Please sign in to comment.