scroll capture: Recover gracefully when anchor view is lost
When manipulating a RecyclerView, the position of a visible child view is used as a feedback signal for scroll tracking. If the view remains detached after scrolling, view operations fail and crash the application. Detect this condition and return an empty result. If the RecyclerView moved during this request, the remaining tiles will be offset by the same amount. This will manifest as a missing section of content. Logging has been added to identify and track this bug. Test: manual repro w/test app; see bug Bug: 239050369 Change-Id: I5a0a62aaad10ffa7838d7902fd9c5f4f84b52ce6
This commit is contained in:
@@ -105,6 +105,13 @@ public class RecyclerViewCaptureHelper implements ScrollCaptureViewHelper<ViewGr
|
||||
}
|
||||
|
||||
if (recyclerView.requestChildRectangleOnScreen(anchor, input, true)) {
|
||||
if (anchor.getParent() == null) {
|
||||
// BUG(b/239050369): Check if the tracked anchor view is still attached.
|
||||
Log.w(TAG, "Bug: anchor view " + anchor + " is detached after scrolling");
|
||||
resultConsumer.accept(result); // empty result
|
||||
return;
|
||||
}
|
||||
|
||||
int scrolled = prevAnchorTop - anchor.getTop(); // inverse of movement
|
||||
mScrollDelta += scrolled; // view.top-- is equivalent to parent.scrollY++
|
||||
result.scrollDelta = mScrollDelta;
|
||||
|
||||
Reference in New Issue
Block a user