75
75
import androidx .drawerlayout .widget .DrawerLayout ;
76
76
import androidx .drawerlayout .widget .DrawerLayout .DrawerListener ;
77
77
import androidx .drawerlayout .widget .DrawerLayout .SimpleDrawerListener ;
78
+ import com .google .android .material .animation .AnimationUtils ;
78
79
import com .google .android .material .drawable .DrawableUtils ;
79
80
import com .google .android .material .internal .ContextUtils ;
80
81
import com .google .android .material .internal .NavigationMenu ;
@@ -146,6 +147,8 @@ public class NavigationView extends ScrimInsetsFrameLayout implements MaterialBa
146
147
private boolean bottomInsetScrimEnabled = true ;
147
148
148
149
@ Px private int drawerLayoutCornerSize = 0 ;
150
+ private final boolean drawerLayoutCornerSizeBackAnimationEnabled ;
151
+ @ Px private final int drawerLayoutCornerSizeBackAnimationMax ;
149
152
private final ShapeableDelegate shapeableDelegate = ShapeableDelegate .create (this );
150
153
151
154
private final MaterialSideContainerBackHelper sideContainerBackHelper =
@@ -166,6 +169,7 @@ public void onDrawerOpened(@NonNull View drawerView) {
166
169
public void onDrawerClosed (@ NonNull View drawerView ) {
167
170
if (drawerView == NavigationView .this ) {
168
171
backOrchestrator .stopListeningForBackCallbacks ();
172
+ maybeClearCornerSizeAnimationForDrawerLayout ();
169
173
}
170
174
}
171
175
};
@@ -199,6 +203,9 @@ public NavigationView(@NonNull Context context, @Nullable AttributeSet attrs, in
199
203
// placed inside a drawer layout.
200
204
drawerLayoutCornerSize =
201
205
a .getDimensionPixelSize (R .styleable .NavigationView_drawerLayoutCornerSize , 0 );
206
+ drawerLayoutCornerSizeBackAnimationEnabled = drawerLayoutCornerSize == 0 ;
207
+ drawerLayoutCornerSizeBackAnimationMax =
208
+ getResources ().getDimensionPixelSize (R .dimen .m3_navigation_drawer_layout_corner_size );
202
209
203
210
// Set the background to a MaterialShapeDrawable if it hasn't been set or if it can be converted
204
211
// to a MaterialShapeDrawable.
@@ -400,7 +407,7 @@ public void setForceCompatClippingEnabled(boolean enabled) {
400
407
private void maybeUpdateCornerSizeForDrawerLayout (@ Px int width , @ Px int height ) {
401
408
if (getParent () instanceof DrawerLayout
402
409
&& getLayoutParams () instanceof DrawerLayout .LayoutParams
403
- && drawerLayoutCornerSize > 0
410
+ && ( drawerLayoutCornerSize > 0 || drawerLayoutCornerSizeBackAnimationEnabled )
404
411
&& getBackground () instanceof MaterialShapeDrawable ) {
405
412
int layoutGravity = ((DrawerLayout .LayoutParams ) getLayoutParams ()).gravity ;
406
413
boolean isAbsGravityLeft =
@@ -432,6 +439,13 @@ && getBackground() instanceof MaterialShapeDrawable) {
432
439
}
433
440
}
434
441
442
+ private void maybeClearCornerSizeAnimationForDrawerLayout () {
443
+ if (drawerLayoutCornerSizeBackAnimationEnabled && drawerLayoutCornerSize != 0 ) {
444
+ drawerLayoutCornerSize = 0 ;
445
+ maybeUpdateCornerSizeForDrawerLayout (getWidth (), getHeight ());
446
+ }
447
+ }
448
+
435
449
private boolean hasShapeAppearance (@ NonNull TintTypedArray a ) {
436
450
return a .hasValue (R .styleable .NavigationView_itemShapeAppearance )
437
451
|| a .hasValue (R .styleable .NavigationView_itemShapeAppearanceOverlay );
@@ -983,6 +997,13 @@ public void startBackProgress(@NonNull BackEventCompat backEvent) {
983
997
public void updateBackProgress (@ NonNull BackEventCompat backEvent ) {
984
998
Pair <DrawerLayout , DrawerLayout .LayoutParams > drawerLayoutPair = requireDrawerLayoutParent ();
985
999
sideContainerBackHelper .updateBackProgress (backEvent , drawerLayoutPair .second .gravity );
1000
+
1001
+ if (drawerLayoutCornerSizeBackAnimationEnabled ) {
1002
+ float progress = sideContainerBackHelper .interpolateProgress (backEvent .getProgress ());
1003
+ drawerLayoutCornerSize =
1004
+ AnimationUtils .lerp (0 , drawerLayoutCornerSizeBackAnimationMax , progress );
1005
+ maybeUpdateCornerSizeForDrawerLayout (getWidth (), getHeight ());
1006
+ }
986
1007
}
987
1008
988
1009
@ Override
@@ -1009,6 +1030,7 @@ public void handleBackInvoked() {
1009
1030
public void cancelBackProgress () {
1010
1031
requireDrawerLayoutParent ();
1011
1032
sideContainerBackHelper .cancelBackProgress ();
1033
+ maybeClearCornerSizeAnimationForDrawerLayout ();
1012
1034
}
1013
1035
1014
1036
@ CanIgnoreReturnValue
0 commit comments