Skip to content

Commit

Permalink
[TextInputEditText]Fix: TextInputEditText misses some visible lines i…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
Material Design Team authored and raajkumars committed Jun 26, 2023
1 parent 122c296 commit bdef355
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,17 @@ public void getFocusedRect(@Nullable Rect r) {
@Override
public boolean getGlobalVisibleRect(@Nullable Rect r, @Nullable Point globalOffset) {
TextInputLayout textInputLayout = getTextInputLayout();
return shouldUseTextInputLayoutFocusedRect(textInputLayout)
? textInputLayout.getGlobalVisibleRect(r, globalOffset)
: super.getGlobalVisibleRect(r, globalOffset);
if (shouldUseTextInputLayoutFocusedRect(textInputLayout)) {
boolean isVisible = textInputLayout.getGlobalVisibleRect(r, globalOffset);
if (isVisible && globalOffset != null) {
// View#getGlobalVisibleRect returns a globalOffset offset by the negative amount of the
// scroll in the given view. Here we need to offset the negative amount of the scroll in
// TextInputEditText when calling getGlobalVisibleRect on the parent TextInputLayout.
globalOffset.offset(-getScrollX(), -getScrollY());
}
return isVisible;
}
return super.getGlobalVisibleRect(r, globalOffset);
}

@Override
Expand Down

0 comments on commit bdef355

Please sign in to comment.