Skip to content

Commit e69a324

Browse files
dsn5ftafohrman
authored andcommitted
[Predictive Back][Search] Fix issue on Android U where clicking SearchView back button causes SearchBar to disappear and back arrow animation to not run
PiperOrigin-RevId: 536876120
1 parent 2b5c75f commit e69a324

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

lib/java/com/google/android/material/motion/MaterialMainContainerBackHelper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,20 @@ public void startBackProgress(@NonNull BackEvent backEvent, @NonNull View collap
9292
@VisibleForTesting
9393
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
9494
public void startBackProgress(float touchY, @NonNull View collapsedView) {
95-
collapsedView.setVisibility(View.INVISIBLE);
96-
9795
initialHideToClipBounds = ViewUtils.calculateRectFromBounds(view);
9896
initialHideFromClipBounds = ViewUtils.calculateOffsetRectFromBounds(view, collapsedView);
9997
initialTouchY = touchY;
10098
}
10199

102100
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
103-
public void updateBackProgress(@NonNull BackEvent backEvent, float collapsedCornerSize) {
101+
public void updateBackProgress(
102+
@NonNull BackEvent backEvent, @NonNull View collapsedView, float collapsedCornerSize) {
104103
super.onUpdateBackProgress(backEvent);
105104

105+
if (collapsedView.getVisibility() != View.INVISIBLE) {
106+
collapsedView.setVisibility(View.INVISIBLE);
107+
}
108+
106109
boolean leftSwipeEdge = backEvent.getSwipeEdge() == BackEvent.EDGE_LEFT;
107110
updateBackProgress(
108111
backEvent.getProgress(), leftSwipeEdge, backEvent.getTouchY(), collapsedCornerSize);

lib/java/com/google/android/material/search/SearchViewAnimationHelper.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -615,23 +615,27 @@ private void setMenuItemsNotClickable(Toolbar toolbar) {
615615
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
616616
void startBackProgress(@NonNull BackEvent backEvent) {
617617
backHelper.startBackProgress(backEvent, searchBar);
618-
619-
if (searchView.isAdjustNothingSoftInputMode()) {
620-
searchView.clearFocusAndHideKeyboard();
621-
}
622-
623-
// Start and immediately pause the animator set so that we can seek it with setCurrentPlayTime()
624-
// in updateBackProgress() when the progress value changes.
625-
backProgressAnimatorSet = getButtonsProgressAnimator(/* show= */ false);
626-
backProgressAnimatorSet.start();
627-
backProgressAnimatorSet.pause();
628618
}
629619

630620
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
631621
public void updateBackProgress(@NonNull BackEvent backEvent) {
632-
backHelper.updateBackProgress(backEvent, searchBar.getCornerSize());
622+
if (backEvent.getProgress() <= 0f) {
623+
return;
624+
}
633625

634-
if (backProgressAnimatorSet != null) {
626+
backHelper.updateBackProgress(backEvent, searchBar, searchBar.getCornerSize());
627+
628+
if (backProgressAnimatorSet == null) {
629+
if (searchView.isAdjustNothingSoftInputMode()) {
630+
searchView.clearFocusAndHideKeyboard();
631+
}
632+
633+
// Start and immediately pause the animator set so we can seek it with setCurrentPlayTime() in
634+
// subsequent updateBackProgress() calls when the progress value changes.
635+
backProgressAnimatorSet = getButtonsProgressAnimator(/* show= */ false);
636+
backProgressAnimatorSet.start();
637+
backProgressAnimatorSet.pause();
638+
} else {
635639
backProgressAnimatorSet.setCurrentPlayTime(
636640
(long) (backEvent.getProgress() * backProgressAnimatorSet.getDuration()));
637641
}

0 commit comments

Comments
 (0)