Skip to content

Commit a93c91a

Browse files
dsn5ftdrchen
authored andcommitted
[Predictive Back][Search] Only use device corner radius if SearchView reaches edge of screen
PiperOrigin-RevId: 524283122
1 parent 1c01e82 commit a93c91a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class MaterialMainContainerBackHelper extends MaterialBackAnimationHelper
6161
private float initialTouchY;
6262
@Nullable private Rect initialHideToClipBounds;
6363
@Nullable private Rect initialHideFromClipBounds;
64-
@Nullable private Integer deviceCornerRadius;
64+
@Nullable private Integer expandedCornerSize;
6565

6666
public MaterialMainContainerBackHelper(@NonNull View view) {
6767
super(view);
@@ -132,7 +132,7 @@ public void updateBackProgress(
132132
view.setTranslationY(translationY);
133133
if (view instanceof ClippableRoundedCornerLayout) {
134134
((ClippableRoundedCornerLayout) view)
135-
.updateCornerRadius(lerp(getDeviceCornerRadius(), collapsedCornerSize, progress));
135+
.updateCornerRadius(lerp(getExpandedCornerSize(), collapsedCornerSize, progress));
136136
}
137137
}
138138

@@ -187,18 +187,24 @@ private ValueAnimator createCornerAnimator(
187187
ClippableRoundedCornerLayout clippableRoundedCornerLayout) {
188188
ValueAnimator cornerAnimator =
189189
ValueAnimator.ofFloat(
190-
clippableRoundedCornerLayout.getCornerRadius(), getDeviceCornerRadius());
190+
clippableRoundedCornerLayout.getCornerRadius(), getExpandedCornerSize());
191191
cornerAnimator.addUpdateListener(
192192
animation ->
193193
clippableRoundedCornerLayout.updateCornerRadius((Float) animation.getAnimatedValue()));
194194
return cornerAnimator;
195195
}
196196

197-
public int getDeviceCornerRadius() {
198-
if (deviceCornerRadius == null) {
199-
deviceCornerRadius = getMaxDeviceCornerRadius();
197+
public int getExpandedCornerSize() {
198+
if (expandedCornerSize == null) {
199+
expandedCornerSize = isAtTopOfScreen() ? getMaxDeviceCornerRadius() : 0;
200200
}
201-
return deviceCornerRadius;
201+
return expandedCornerSize;
202+
}
203+
204+
private boolean isAtTopOfScreen() {
205+
int[] location = new int[2];
206+
view.getLocationOnScreen(location);
207+
return location[1] == 0;
202208
}
203209

204210
private int getMaxDeviceCornerRadius() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private Animator getRootViewAnimator(boolean show) {
347347
Rect clipBounds = new Rect(fromClipBounds);
348348

349349
float fromCornerRadius = searchBar.getCornerSize();
350-
float toCornerRadius = max(rootView.getCornerRadius(), backHelper.getDeviceCornerRadius());
350+
float toCornerRadius = max(rootView.getCornerRadius(), backHelper.getExpandedCornerSize());
351351

352352
ValueAnimator animator =
353353
ValueAnimator.ofObject(new RectEvaluator(clipBounds), fromClipBounds, toClipBounds);

0 commit comments

Comments
 (0)