Skip to content

Commit 22cd4db

Browse files
cketchamgsajith
authored andcommitted
Prevent invalidating MaterialShapeDrawable if parameters haven't changed
PiperOrigin-RevId: 219319784
1 parent a25e13c commit 22cd4db

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

lib/java/com/google/android/material/shape/MaterialShapeDrawable.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ public ColorStateList getStrokeColor() {
266266

267267
@Override
268268
public void setTintMode(PorterDuff.Mode tintMode) {
269-
this.tintMode = tintMode;
270-
updateTintFilter();
271-
invalidateSelf();
269+
if (this.tintMode != tintMode) {
270+
this.tintMode = tintMode;
271+
updateTintFilter();
272+
invalidateSelf();
273+
}
272274
}
273275

274276
@Override
@@ -379,8 +381,10 @@ public int getOpacity() {
379381

380382
@Override
381383
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
382-
this.alpha = alpha;
383-
invalidateSelf();
384+
if (this.alpha != alpha) {
385+
this.alpha = alpha;
386+
invalidateSelf();
387+
}
384388
}
385389

386390
@Override
@@ -434,8 +438,10 @@ public int getShadowCompatibilityMode() {
434438
* instead of native elevation shadows.
435439
*/
436440
public void setShadowCompatibilityMode(@CompatibilityShadowMode int mode) {
437-
shadowCompatMode = mode;
438-
invalidateSelf();
441+
if (shadowCompatMode != mode) {
442+
shadowCompatMode = mode;
443+
invalidateSelf();
444+
}
439445
}
440446

441447
/**
@@ -494,8 +500,10 @@ public float getInterpolation() {
494500
* @param interpolation the desired interpolation.
495501
*/
496502
public void setInterpolation(float interpolation) {
497-
this.interpolation = interpolation;
498-
invalidateSelf();
503+
if (this.interpolation != interpolation) {
504+
this.interpolation = interpolation;
505+
invalidateSelf();
506+
}
499507
}
500508

501509
/**
@@ -517,9 +525,11 @@ public int getShadowElevation() {
517525
* shadow.
518526
*/
519527
public void setShadowElevation(int shadowElevation) {
520-
this.shadowCompatRadius = shadowElevation;
521-
this.shadowCompatElevation = shadowElevation;
522-
invalidateSelf();
528+
if (this.shadowCompatElevation != shadowElevation) {
529+
this.shadowCompatRadius = shadowElevation;
530+
this.shadowCompatElevation = shadowElevation;
531+
invalidateSelf();
532+
}
523533
}
524534

525535
/**
@@ -538,8 +548,10 @@ public int getShadowVerticalOffset() {
538548
* shadow appears below it.
539549
*/
540550
public void setShadowVerticalOffset(int shadowOffset) {
541-
this.shadowCompatOffset = shadowOffset;
542-
invalidateSelf();
551+
if (this.shadowCompatOffset != shadowOffset) {
552+
this.shadowCompatOffset = shadowOffset;
553+
invalidateSelf();
554+
}
543555
}
544556

545557
/**
@@ -559,8 +571,10 @@ public int getShadowCompatRotation() {
559571
* shadow to appear to be drawn from the bottom.
560572
*/
561573
public void setShadowCompatRotation(int shadowRotation) {
562-
this.shadowCompatRotation = shadowRotation;
563-
invalidateSelf();
574+
if (this.shadowCompatRotation != shadowRotation) {
575+
this.shadowCompatRotation = shadowRotation;
576+
invalidateSelf();
577+
}
564578
}
565579

566580
/**
@@ -608,8 +622,10 @@ public float getScale() {
608622
* @param scale the desired scale.
609623
*/
610624
public void setScale(float scale) {
611-
this.scale = scale;
612-
invalidateSelf();
625+
if (this.scale != scale) {
626+
this.scale = scale;
627+
invalidateSelf();
628+
}
613629
}
614630

615631
/**
@@ -620,8 +636,10 @@ public void setScale(float scale) {
620636
* @param useTintColorForShadow true if color should match; false otherwise.
621637
*/
622638
public void setUseTintColorForShadow(boolean useTintColorForShadow) {
623-
this.useTintColorForShadow = useTintColorForShadow;
624-
invalidateSelf();
639+
if (this.useTintColorForShadow != useTintColorForShadow) {
640+
this.useTintColorForShadow = useTintColorForShadow;
641+
invalidateSelf();
642+
}
625643
}
626644

627645
/**

0 commit comments

Comments
 (0)