Disable focus search failures during a layout
If focus changes during a layout and FocusFinder cannot find the
next view, it may call LayoutManager's focus failed method, which
may add new views. This is a problem because we are essentially
calling layout inside a layout which is tricky to handle for any
layout manager.
This CL changes RecyclerView to ignore focus search request that
arrives during a layout or smooth scroll if FocusFinder cannot
find the next view.
When a View gains focus, we run the same checks (already) so that
RecyclerView will not jump around while trying to make the View
visible.
Bug: 18840571
Change-Id: I07c7c8ebcdb5f4d5a064f62caf8ab97e19983426
diff --git a/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java b/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java
index cab10d2..94d7926 100644
--- a/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java
+++ b/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java
@@ -1818,7 +1818,7 @@
}
final FocusFinder ff = FocusFinder.getInstance();
result = ff.findNextFocus(this, focused, direction);
- if (result == null && mAdapter != null && mLayout != null) {
+ if (result == null && mAdapter != null && mLayout != null && !isComputingLayout()) {
eatRequestLayout();
result = mLayout.onFocusSearchFailed(focused, direction, mRecycler, mState);
resumeRequestLayout(false);