@@ -131,6 +131,8 @@ public class MaterialButtonGroup extends LinearLayout {
131
131
@ Px private int spacing ;
132
132
@ Nullable private StateListSizeChange buttonSizeChange ;
133
133
134
+ private boolean isChildrenShapeInvalidated = true ;
135
+
134
136
public MaterialButtonGroup (@ NonNull Context context ) {
135
137
this (context , null );
136
138
}
@@ -204,6 +206,7 @@ public void addView(@NonNull View child, int index, @Nullable ViewGroup.LayoutPa
204
206
return ;
205
207
}
206
208
209
+ isChildrenShapeInvalidated = true ;
207
210
super .addView (child , index , params );
208
211
MaterialButton buttonChild = (MaterialButton ) child ;
209
212
setGeneratedIdIfNeeded (buttonChild );
@@ -231,6 +234,7 @@ public void onViewRemoved(View child) {
231
234
originalChildStateListShapeAppearanceModels .remove (indexOfChild );
232
235
}
233
236
237
+ isChildrenShapeInvalidated = true ;
234
238
updateChildShapes ();
235
239
adjustChildMarginsAndUpdateLayout ();
236
240
}
@@ -256,9 +260,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
256
260
@ VisibleForTesting
257
261
void updateChildShapes () {
258
262
// No need to update shape if no inside corners or outer corners are specified.
259
- if (innerCornerSize == null && groupStateListShapeAppearance == null ) {
263
+ if ((innerCornerSize == null && groupStateListShapeAppearance == null )
264
+ || !isChildrenShapeInvalidated ) {
260
265
return ;
261
266
}
267
+ isChildrenShapeInvalidated = false ;
262
268
int childCount = getChildCount ();
263
269
int firstVisibleChildIndex = getFirstVisibleChildIndex ();
264
270
int lastVisibleChildIndex = getLastVisibleChildIndex ();
@@ -580,6 +586,7 @@ public CornerSize getInnerCornerSize() {
580
586
*/
581
587
public void setInnerCornerSize (@ NonNull CornerSize cornerSize ) {
582
588
innerCornerSize = StateListCornerSize .create (cornerSize );
589
+ isChildrenShapeInvalidated = true ;
583
590
updateChildShapes ();
584
591
invalidate ();
585
592
}
@@ -608,6 +615,7 @@ public StateListCornerSize getInnerCornerSizeStateList() {
608
615
@ RestrictTo (Scope .LIBRARY_GROUP )
609
616
public void setInnerCornerSizeStateList (@ NonNull StateListCornerSize cornerSizeStateList ) {
610
617
innerCornerSize = cornerSizeStateList ;
618
+ isChildrenShapeInvalidated = true ;
611
619
updateChildShapes ();
612
620
invalidate ();
613
621
}
@@ -628,6 +636,7 @@ public ShapeAppearanceModel getShapeAppearance() {
628
636
public void setShapeAppearance (@ Nullable ShapeAppearanceModel shapeAppearance ) {
629
637
groupStateListShapeAppearance =
630
638
new StateListShapeAppearanceModel .Builder (shapeAppearance ).build ();
639
+ isChildrenShapeInvalidated = true ;
631
640
updateChildShapes ();
632
641
invalidate ();
633
642
}
@@ -653,6 +662,7 @@ public StateListShapeAppearanceModel getStateListShapeAppearance() {
653
662
public void setStateListShapeAppearance (
654
663
@ Nullable StateListShapeAppearanceModel stateListShapeAppearance ) {
655
664
groupStateListShapeAppearance = stateListShapeAppearance ;
665
+ isChildrenShapeInvalidated = true ;
656
666
updateChildShapes ();
657
667
invalidate ();
658
668
}
0 commit comments