Skip to content

Commit

Permalink
[Predictive Back][Search] Only use device corner radius if SearchView…
Browse files Browse the repository at this point in the history
… reaches edge of screen

PiperOrigin-RevId: 524283122
  • Loading branch information
dsn5ft authored and drchen committed Apr 17, 2023
1 parent 1c01e82 commit a93c91a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Expand Up @@ -61,7 +61,7 @@ public class MaterialMainContainerBackHelper extends MaterialBackAnimationHelper
private float initialTouchY;
@Nullable private Rect initialHideToClipBounds;
@Nullable private Rect initialHideFromClipBounds;
@Nullable private Integer deviceCornerRadius;
@Nullable private Integer expandedCornerSize;

public MaterialMainContainerBackHelper(@NonNull View view) {
super(view);
Expand Down Expand Up @@ -132,7 +132,7 @@ public void updateBackProgress(
view.setTranslationY(translationY);
if (view instanceof ClippableRoundedCornerLayout) {
((ClippableRoundedCornerLayout) view)
.updateCornerRadius(lerp(getDeviceCornerRadius(), collapsedCornerSize, progress));
.updateCornerRadius(lerp(getExpandedCornerSize(), collapsedCornerSize, progress));
}
}

Expand Down Expand Up @@ -187,18 +187,24 @@ private ValueAnimator createCornerAnimator(
ClippableRoundedCornerLayout clippableRoundedCornerLayout) {
ValueAnimator cornerAnimator =
ValueAnimator.ofFloat(
clippableRoundedCornerLayout.getCornerRadius(), getDeviceCornerRadius());
clippableRoundedCornerLayout.getCornerRadius(), getExpandedCornerSize());
cornerAnimator.addUpdateListener(
animation ->
clippableRoundedCornerLayout.updateCornerRadius((Float) animation.getAnimatedValue()));
return cornerAnimator;
}

public int getDeviceCornerRadius() {
if (deviceCornerRadius == null) {
deviceCornerRadius = getMaxDeviceCornerRadius();
public int getExpandedCornerSize() {
if (expandedCornerSize == null) {
expandedCornerSize = isAtTopOfScreen() ? getMaxDeviceCornerRadius() : 0;
}
return deviceCornerRadius;
return expandedCornerSize;
}

private boolean isAtTopOfScreen() {
int[] location = new int[2];
view.getLocationOnScreen(location);
return location[1] == 0;
}

private int getMaxDeviceCornerRadius() {
Expand Down
Expand Up @@ -347,7 +347,7 @@ private Animator getRootViewAnimator(boolean show) {
Rect clipBounds = new Rect(fromClipBounds);

float fromCornerRadius = searchBar.getCornerSize();
float toCornerRadius = max(rootView.getCornerRadius(), backHelper.getDeviceCornerRadius());
float toCornerRadius = max(rootView.getCornerRadius(), backHelper.getExpandedCornerSize());

ValueAnimator animator =
ValueAnimator.ofObject(new RectEvaluator(clipBounds), fromClipBounds, toClipBounds);
Expand Down

0 comments on commit a93c91a

Please sign in to comment.