Skip to content

Commit bdef355

Browse files
Material Design Teamraajkumars
authored andcommitted
[TextInputEditText]Fix: TextInputEditText misses some visible lines in CursorAnchorInfo#getVisibleLineBounds after scrolled
TextInputEditText#getGlobalVisibleRect is overridden to call getGlobalVisibleRect on parent TextLayoutInput view directly. It doesn't match with the View#getGlobalVisibleRect implementation where the return globalOffset contains negative amount of the scroll in the view. As a result, calling getLocalVisibleRect will return a wrong rectangle when TextInputEiditText is scrolled. PiperOrigin-RevId: 542341678
1 parent 122c296 commit bdef355

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/java/com/google/android/material/textfield/TextInputEditText.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,17 @@ public void getFocusedRect(@Nullable Rect r) {
169169
@Override
170170
public boolean getGlobalVisibleRect(@Nullable Rect r, @Nullable Point globalOffset) {
171171
TextInputLayout textInputLayout = getTextInputLayout();
172-
return shouldUseTextInputLayoutFocusedRect(textInputLayout)
173-
? textInputLayout.getGlobalVisibleRect(r, globalOffset)
174-
: super.getGlobalVisibleRect(r, globalOffset);
172+
if (shouldUseTextInputLayoutFocusedRect(textInputLayout)) {
173+
boolean isVisible = textInputLayout.getGlobalVisibleRect(r, globalOffset);
174+
if (isVisible && globalOffset != null) {
175+
// View#getGlobalVisibleRect returns a globalOffset offset by the negative amount of the
176+
// scroll in the given view. Here we need to offset the negative amount of the scroll in
177+
// TextInputEditText when calling getGlobalVisibleRect on the parent TextInputLayout.
178+
globalOffset.offset(-getScrollX(), -getScrollY());
179+
}
180+
return isVisible;
181+
}
182+
return super.getGlobalVisibleRect(r, globalOffset);
175183
}
176184

177185
@Override

0 commit comments

Comments
 (0)