Skip to content

Commit bbd942c

Browse files
pekingmehunterstich
authored andcommitted
[MaterialButton] Updated the shapes of buttons when the orientation is changed.
Resolves #4809 PiperOrigin-RevId: 772043388
1 parent 0e6d4f4 commit bbd942c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/java/com/google/android/material/button/MaterialButtonGroup.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public class MaterialButtonGroup extends LinearLayout {
174174
@Px private int spacing;
175175
@Nullable private StateListSizeChange buttonSizeChange;
176176

177-
private boolean isChildrenShapeInvalidated = true;
177+
private boolean childShapesDirty = true;
178178

179179
private final int overflowMenuItemIconPadding;
180180
private boolean buttonOverflowInitialized;
@@ -305,7 +305,7 @@ public void addView(@NonNull View child, int index, @Nullable ViewGroup.LayoutPa
305305

306306
// Recover the original layout params of all children before adding the new child.
307307
recoverAllChildrenLayoutParams();
308-
isChildrenShapeInvalidated = true;
308+
childShapesDirty = true;
309309
// If overflow button has been added, the new child button will be always added before the
310310
// overflow button.
311311
int overflowButtonIndex = indexOfChild(overflowButton);
@@ -340,7 +340,7 @@ public void onViewRemoved(View child) {
340340
originalChildStateListShapeAppearanceModels.remove(indexOfChild);
341341
}
342342

343-
isChildrenShapeInvalidated = true;
343+
childShapesDirty = true;
344344
updateChildShapes();
345345

346346
// Recover the original layout params of all children before updating the child layout.
@@ -517,11 +517,10 @@ private void updateOverflowMenuItemsState() {
517517
@VisibleForTesting
518518
void updateChildShapes() {
519519
// No need to update shape if no inside corners or outer corners are specified.
520-
if ((innerCornerSize == null && groupStateListShapeAppearance == null)
521-
|| !isChildrenShapeInvalidated) {
520+
if ((innerCornerSize == null && groupStateListShapeAppearance == null) || !childShapesDirty) {
522521
return;
523522
}
524-
isChildrenShapeInvalidated = false;
523+
childShapesDirty = false;
525524
int childCount = getChildCount();
526525
int firstVisibleChildIndex = getFirstVisibleChildIndex();
527526
int lastVisibleChildIndex = getLastVisibleChildIndex();
@@ -790,6 +789,14 @@ private int getButtonAllowedWidthIncrease(int index) {
790789

791790
// ================ Getters and setters ===================
792791

792+
@Override
793+
public void setOrientation(int orientation) {
794+
if (getOrientation() != orientation) {
795+
childShapesDirty = true;
796+
}
797+
super.setOrientation(orientation);
798+
}
799+
793800
/**
794801
* Returns the {@link StateListSizeChange} of child buttons on state changes.
795802
*
@@ -851,7 +858,7 @@ public CornerSize getInnerCornerSize() {
851858
*/
852859
public void setInnerCornerSize(@NonNull CornerSize cornerSize) {
853860
innerCornerSize = StateListCornerSize.create(cornerSize);
854-
isChildrenShapeInvalidated = true;
861+
childShapesDirty = true;
855862
updateChildShapes();
856863
invalidate();
857864
}
@@ -880,7 +887,7 @@ public StateListCornerSize getInnerCornerSizeStateList() {
880887
@RestrictTo(Scope.LIBRARY_GROUP)
881888
public void setInnerCornerSizeStateList(@NonNull StateListCornerSize cornerSizeStateList) {
882889
innerCornerSize = cornerSizeStateList;
883-
isChildrenShapeInvalidated = true;
890+
childShapesDirty = true;
884891
updateChildShapes();
885892
invalidate();
886893
}
@@ -901,7 +908,7 @@ public ShapeAppearanceModel getShapeAppearance() {
901908
public void setShapeAppearance(@Nullable ShapeAppearanceModel shapeAppearance) {
902909
groupStateListShapeAppearance =
903910
new StateListShapeAppearanceModel.Builder(shapeAppearance).build();
904-
isChildrenShapeInvalidated = true;
911+
childShapesDirty = true;
905912
updateChildShapes();
906913
invalidate();
907914
}
@@ -927,7 +934,7 @@ public StateListShapeAppearanceModel getStateListShapeAppearance() {
927934
public void setStateListShapeAppearance(
928935
@Nullable StateListShapeAppearanceModel stateListShapeAppearance) {
929936
groupStateListShapeAppearance = stateListShapeAppearance;
930-
isChildrenShapeInvalidated = true;
937+
childShapesDirty = true;
931938
updateChildShapes();
932939
invalidate();
933940
}
@@ -1137,8 +1144,7 @@ public LayoutParams(@NonNull Context context, @Nullable AttributeSet attrs) {
11371144

11381145
overflowIcon =
11391146
attributes.getDrawable(R.styleable.MaterialButtonGroup_Layout_layout_overflowIcon);
1140-
overflowText =
1141-
attributes.getText(R.styleable.MaterialButtonGroup_Layout_layout_overflowText);
1147+
overflowText = attributes.getText(R.styleable.MaterialButtonGroup_Layout_layout_overflowText);
11421148

11431149
attributes.recycle();
11441150
}
@@ -1199,8 +1205,8 @@ public LayoutParams(@NonNull MaterialButtonGroup.LayoutParams source) {
11991205
}
12001206

12011207
/**
1202-
* Class for common logic between this MaterialButtonGroup and the OverflowLinearLayout
1203-
* overflow features.
1208+
* Class for common logic between this MaterialButtonGroup and the OverflowLinearLayout overflow
1209+
* features.
12041210
*
12051211
* @hide
12061212
*/

0 commit comments

Comments
 (0)