From 12075972ff2633bc232aa5fdd552c45d9a605b40 Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Fri, 12 May 2023 12:49:02 -0700 Subject: A workaround for swipe-down-to-dismiss issue Compatibility RecyclerView reports onNestedScroll `consumed` value as true if scroll is enabled in any direction. The SysUi RecyclerView reports ture only if can be scrolled in the direction of the fling. Add a workaround to ResolverDrawerLayout that restores the legacy functionality. Fix: 264005990 Test: manual testing Change-Id: If379e43c57355489bf8b0265dbab14d796b3dff6 --- .../widget/ResolverDrawerLayout.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'java') diff --git a/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java b/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java index f5e20510..de76a1d2 100644 --- a/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java +++ b/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java @@ -841,7 +841,14 @@ public class ResolverDrawerLayout extends ViewGroup { @Override public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { - if (!consumed && Math.abs(velocityY) > mMinFlingVelocity) { + // TODO: find a more suitable way to fix it. + // RecyclerView started reporting `consumed` as true whenever a scrolling is enabled, + // previously the value was based whether the fling can be performed in given direction + // i.e. whether it is at the top or at the bottom. isRecyclerViewAtTheTop method is a + // workaround that restores the legacy functionality. + boolean shouldConsume = (Math.abs(velocityY) > mMinFlingVelocity) + && (!consumed || (velocityY < 0 && isRecyclerViewAtTheTop(target))); + if (shouldConsume) { if (getShowAtTop()) { if (isDismissable() && velocityY > 0) { abortAnimation(); @@ -863,6 +870,21 @@ public class ResolverDrawerLayout extends ViewGroup { return false; } + private static boolean isRecyclerViewAtTheTop(View target) { + // TODO: there's a very similar functionality in #isNestedRecyclerChildScrolled(), + // consolidate the two. + if (!(target instanceof RecyclerView)) { + return false; + } + RecyclerView recyclerView = (RecyclerView) target; + if (recyclerView.getChildCount() == 0) { + return true; + } + View firstChild = recyclerView.getChildAt(0); + return recyclerView.getChildAdapterPosition(firstChild) == 0 + && firstChild.getTop() >= recyclerView.getPaddingTop(); + } + private boolean performAccessibilityActionCommon(int action) { switch (action) { case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: -- cgit v1.2.3-59-g8ed1b