Skip to content

Commit

Permalink
[Predictive Back][Search] Fix issue on Android U where clicking Searc…
Browse files Browse the repository at this point in the history
…hView back button causes SearchBar to disappear and back arrow animation to not run

PiperOrigin-RevId: 536876120
  • Loading branch information
dsn5ft authored and afohrman committed Jun 5, 2023
1 parent 2b5c75f commit e69a324
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Expand Up @@ -92,17 +92,20 @@ public void startBackProgress(@NonNull BackEvent backEvent, @NonNull View collap
@VisibleForTesting
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void startBackProgress(float touchY, @NonNull View collapsedView) {
collapsedView.setVisibility(View.INVISIBLE);

initialHideToClipBounds = ViewUtils.calculateRectFromBounds(view);
initialHideFromClipBounds = ViewUtils.calculateOffsetRectFromBounds(view, collapsedView);
initialTouchY = touchY;
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void updateBackProgress(@NonNull BackEvent backEvent, float collapsedCornerSize) {
public void updateBackProgress(
@NonNull BackEvent backEvent, @NonNull View collapsedView, float collapsedCornerSize) {
super.onUpdateBackProgress(backEvent);

if (collapsedView.getVisibility() != View.INVISIBLE) {
collapsedView.setVisibility(View.INVISIBLE);
}

boolean leftSwipeEdge = backEvent.getSwipeEdge() == BackEvent.EDGE_LEFT;
updateBackProgress(
backEvent.getProgress(), leftSwipeEdge, backEvent.getTouchY(), collapsedCornerSize);
Expand Down
Expand Up @@ -615,23 +615,27 @@ private void setMenuItemsNotClickable(Toolbar toolbar) {
@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
void startBackProgress(@NonNull BackEvent backEvent) {
backHelper.startBackProgress(backEvent, searchBar);

if (searchView.isAdjustNothingSoftInputMode()) {
searchView.clearFocusAndHideKeyboard();
}

// Start and immediately pause the animator set so that we can seek it with setCurrentPlayTime()
// in updateBackProgress() when the progress value changes.
backProgressAnimatorSet = getButtonsProgressAnimator(/* show= */ false);
backProgressAnimatorSet.start();
backProgressAnimatorSet.pause();
}

@RequiresApi(VERSION_CODES.UPSIDE_DOWN_CAKE)
public void updateBackProgress(@NonNull BackEvent backEvent) {
backHelper.updateBackProgress(backEvent, searchBar.getCornerSize());
if (backEvent.getProgress() <= 0f) {
return;
}

if (backProgressAnimatorSet != null) {
backHelper.updateBackProgress(backEvent, searchBar, searchBar.getCornerSize());

if (backProgressAnimatorSet == null) {
if (searchView.isAdjustNothingSoftInputMode()) {
searchView.clearFocusAndHideKeyboard();
}

// Start and immediately pause the animator set so we can seek it with setCurrentPlayTime() in
// subsequent updateBackProgress() calls when the progress value changes.
backProgressAnimatorSet = getButtonsProgressAnimator(/* show= */ false);
backProgressAnimatorSet.start();
backProgressAnimatorSet.pause();
} else {
backProgressAnimatorSet.setCurrentPlayTime(
(long) (backEvent.getProgress() * backProgressAnimatorSet.getDuration()));
}
Expand Down

0 comments on commit e69a324

Please sign in to comment.