From 74b7706de9ff3b1613aaf911f2285401ca39c45d Mon Sep 17 00:00:00 2001 From: pubiqq Date: Wed, 6 Jul 2022 12:00:10 -0700 Subject: [PATCH] [ShapeableImageView] Don't change layer type when view is detached from the window When the exit transition starts, the layer type is set to LAYER_TYPE_NONE (inside onDetachedFromWindow). In this case, clearPaint (Paint with Xfermode = PorterDuff.Mode.DST_OUT) stops working correctly. The patch just deletes the layer type setup from onDetachedFromWindow, leaving the layer type set to LAYER_TYPE_HARDWARE. Resolves https://github.com/material-components/material-components-android/issues/2703 Resolves https://github.com/material-components/material-components-android/pull/2792 GIT_ORIGIN_REV_ID=b05230b40529251b8b16cc02f1cfd64f3801c1d8 PiperOrigin-RevId: 459308833 --- .../material/imageview/ShapeableImageView.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/lib/java/com/google/android/material/imageview/ShapeableImageView.java b/lib/java/com/google/android/material/imageview/ShapeableImageView.java index ff27775f151..0dccd0d4bae 100644 --- a/lib/java/com/google/android/material/imageview/ShapeableImageView.java +++ b/lib/java/com/google/android/material/imageview/ShapeableImageView.java @@ -108,6 +108,8 @@ public ShapeableImageView(Context context, @Nullable AttributeSet attrs, int def context.obtainStyledAttributes( attrs, R.styleable.ShapeableImageView, defStyle, DEF_STYLE_RES); + setLayerType(LAYER_TYPE_HARDWARE, null); + strokeColor = MaterialResources.getColorStateList( context, attributes, R.styleable.ShapeableImageView_strokeColor); @@ -150,18 +152,6 @@ public ShapeableImageView(Context context, @Nullable AttributeSet attrs, int def } } - @Override - protected void onDetachedFromWindow() { - setLayerType(LAYER_TYPE_NONE, null); - super.onDetachedFromWindow(); - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - setLayerType(LAYER_TYPE_HARDWARE, null); - } - @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec);