From fd77f12147baa1086bfc244cca3cfca704130c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Kurucz?= Date: Fri, 19 May 2023 09:36:45 +0000 Subject: [PATCH] Only do snapback animations on Swipeable views SwipeHelper is observing all the children of the notification shade, it is translating them on swipes and performs dismiss or snapback animations on them. NotificationSwipeHelper overrides a couple of methods to make them only work for views implementing the SwipeableView interface. The SwipeHelper#snapChild method is triggered for non swipeable views as well, and it starts an animation for them, but previously we never noticed, because the `setTranslation` method is overriden, so views never had a starting translation to snap back from. Updating the snapback anim to a spring animation (ag/22119722) caused a regression, because the spring anim can do an overshoot from the target position if it was given some starting velocity. This is a trivial fix to skip triggering the snapback anim for non swipeable views. Fixes: 278858192 Test: atest NotificationSwipeHelperTest Test: try to drag the non swipeable views in the NotificationShade and observe that they stay in place Change-Id: I5afb7bb94c052faf0025abe15f586937733c5fa4 --- .../stack/NotificationSwipeHelper.java | 6 ++++- .../stack/NotificationSwipeHelperTest.java | 23 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java index 993c3801cecd7..b956207190b75 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelper.java @@ -354,7 +354,11 @@ class NotificationSwipeHelper extends SwipeHelper implements NotificationSwipeAc @Override protected void snapChild(final View animView, final float targetLeft, float velocity) { - superSnapChild(animView, targetLeft, velocity); + if (animView instanceof SwipeableView) { + // only perform the snapback animation on views that are swipeable inside the shade. + superSnapChild(animView, targetLeft, velocity); + } + mCallback.onDragCancelled(animView); if (targetLeft == 0) { handleMenuCoveredOrDismissed(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java index 551499e0fb55d..7632d01d4d43a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSwipeHelperTest.java @@ -392,23 +392,32 @@ public class NotificationSwipeHelperTest extends SysuiTestCase { @Test public void testSnapchild_targetIsZero() { - doNothing().when(mSwipeHelper).superSnapChild(mView, 0, 0); - mSwipeHelper.snapChild(mView, 0, 0); + doNothing().when(mSwipeHelper).superSnapChild(mNotificationRow, 0, 0); + mSwipeHelper.snapChild(mNotificationRow, 0, 0); - verify(mCallback, times(1)).onDragCancelled(mView); - verify(mSwipeHelper, times(1)).superSnapChild(mView, 0, 0); + verify(mCallback, times(1)).onDragCancelled(mNotificationRow); + verify(mSwipeHelper, times(1)).superSnapChild(mNotificationRow, 0, 0); verify(mSwipeHelper, times(1)).handleMenuCoveredOrDismissed(); } @Test public void testSnapchild_targetNotZero() { + doNothing().when(mSwipeHelper).superSnapChild(mNotificationRow, 10, 0); + mSwipeHelper.snapChild(mNotificationRow, 10, 0); + + verify(mCallback, times(1)).onDragCancelled(mNotificationRow); + verify(mSwipeHelper, times(1)).superSnapChild(mNotificationRow, 10, 0); + verify(mSwipeHelper, times(0)).handleMenuCoveredOrDismissed(); + } + + @Test + public void testSnapchild_targetNotSwipeable() { doNothing().when(mSwipeHelper).superSnapChild(mView, 10, 0); mSwipeHelper.snapChild(mView, 10, 0); - verify(mCallback, times(1)).onDragCancelled(mView); - verify(mSwipeHelper, times(1)).superSnapChild(mView, 10, 0); - verify(mSwipeHelper, times(0)).handleMenuCoveredOrDismissed(); + verify(mCallback).onDragCancelled(mView); + verify(mSwipeHelper, never()).superSnapChild(mView, 10, 0); } @Test