@@ -54,6 +54,7 @@ public class MaskableFrameLayout extends FrameLayout implements Maskable, Shapea
5454 @ Nullable private OnMaskChangedListener onMaskChangedListener ;
5555 @ NonNull private ShapeAppearanceModel shapeAppearanceModel ;
5656 private final MaskableDelegate maskableDelegate = createMaskableDelegate ();
57+ @ Nullable private Boolean savedForceCompatClippingEnabled = null ;
5758
5859 public MaskableFrameLayout (@ NonNull Context context ) {
5960 this (context , null );
@@ -86,6 +87,24 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
8687 onMaskChanged ();
8788 }
8889
90+ @ Override
91+ protected void onAttachedToWindow () {
92+ super .onAttachedToWindow ();
93+ // Restore any saved force compat clipping setting.
94+ if (savedForceCompatClippingEnabled != null ) {
95+ maskableDelegate .setForceCompatClippingEnabled (this , savedForceCompatClippingEnabled );
96+ }
97+ }
98+
99+ @ Override
100+ protected void onDetachedFromWindow () {
101+ // When detaching from the window, force canvas clipping to avoid any transitions from releasing
102+ // the mask outline set by the MaskableDelegate's ViewOutlineProvider, if any.
103+ savedForceCompatClippingEnabled = maskableDelegate .isForceCompatClippingEnabled ();
104+ maskableDelegate .setForceCompatClippingEnabled (this , true );
105+ super .onDetachedFromWindow ();
106+ }
107+
89108 @ Override
90109 public void setShapeAppearanceModel (@ NonNull ShapeAppearanceModel shapeAppearanceModel ) {
91110 this .shapeAppearanceModel =
@@ -160,7 +179,6 @@ private void onMaskChanged() {
160179 }
161180 }
162181
163-
164182 /**
165183 * Set whether this view should always use canvas clipping to clip to its masked shape.
166184 *
@@ -222,6 +240,10 @@ private abstract static class MaskableDelegate {
222240 */
223241 abstract boolean shouldUseCompatClipping ();
224242
243+ boolean isForceCompatClippingEnabled () {
244+ return forceCompatClippingEnabled ;
245+ }
246+
225247 /**
226248 * Set whether the client would like to always use compat clipping regardless of whether other
227249 * means are available.
@@ -366,8 +388,8 @@ public void getOutline(View view, Outline outline) {
366388 }
367389
368390 /**
369- * A {@link MaskableDelegate} for API 33+ that uses {@link ViewOutlineProvider} to clip for
370- * all shapes.
391+ * A {@link MaskableDelegate} for API 33+ that uses {@link ViewOutlineProvider} to clip for all
392+ * shapes.
371393 *
372394 * <p>{@link Outline#setPath(Path)} was added in API 33 and allows using {@link
373395 * ViewOutlineProvider} to clip for all shapes.
0 commit comments