Skip to content

Commit

Permalink
Fix scroll when a view within comment item is focused
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderR committed Oct 9, 2019
1 parent b675d29 commit 098b97b
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,39 @@ public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.R
}

if (focusDirection == View.FOCUS_DOWN) {
scrollVerticallyBy(10, recycler, state);
int scrollAmount = 1 + getScrollExtra(focused);
scrollVerticallyBy(scrollAmount, recycler, state);
return null;
}

return super.onFocusSearchFailed(focused, focusDirection, recycler, state);
}

private int getScrollExtra(View focused) {
if (focused == null) {
return 0;
}

View container = findContainingItemView(focused);
if (container == focused) {
return 0;
}

if (!(container instanceof ViewGroup)) {
return 0;
}

ViewGroup vg = (ViewGroup) container;

Rect rect = new Rect();

focused.getHitRect(rect);

ViewGroup parent = (ViewGroup) focused.getParent();
if (container != parent) {
vg.offsetDescendantRectToMyCoords(parent, rect);
}

return container.getHeight() - rect.bottom;
}
}

0 comments on commit 098b97b

Please sign in to comment.