Skip to content

Commit

Permalink
[Button] Fix inset attributes working incorrectly in RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
pubiqq committed May 7, 2024
1 parent 0d265b7 commit 90a0740
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ void loadFromAttributes(@NonNull TypedArray attributes) {
attributes.getBoolean(R.styleable.MaterialButton_toggleCheckedStateOnClick, true);

// Store padding before setting background, since background overwrites padding values
int paddingStart = ViewCompat.getPaddingStart(materialButton);
int paddingLeft = materialButton.getPaddingLeft();
int paddingTop = materialButton.getPaddingTop();
int paddingEnd = ViewCompat.getPaddingEnd(materialButton);
int paddingRight = materialButton.getPaddingRight();
int paddingBottom = materialButton.getPaddingBottom();

// Update materialButton's background without triggering setBackgroundOverwritten()
Expand All @@ -134,11 +134,10 @@ void loadFromAttributes(@NonNull TypedArray attributes) {
updateBackground();
}
// Set the stored padding values
ViewCompat.setPaddingRelative(
materialButton,
paddingStart + insetLeft,
materialButton.setPadding(
paddingLeft + insetLeft,
paddingTop + insetTop,
paddingEnd + insetRight,
paddingRight + insetRight,
paddingBottom + insetBottom);
}

Expand Down Expand Up @@ -384,14 +383,13 @@ private void updateButtonShape(@NonNull ShapeAppearanceModel shapeAppearanceMode
// changing an existing drawable shape. This is a fallback.
if (IS_LOLLIPOP && !backgroundOverwritten) {
// Store padding before setting background, since background overwrites padding values
int paddingStart = ViewCompat.getPaddingStart(materialButton);
int paddingLeft = materialButton.getPaddingLeft();
int paddingTop = materialButton.getPaddingTop();
int paddingEnd = ViewCompat.getPaddingEnd(materialButton);
int paddingRight = materialButton.getPaddingRight();
int paddingBottom = materialButton.getPaddingBottom();
updateBackground();
// Set the stored padding values
ViewCompat.setPaddingRelative(
materialButton, paddingStart, paddingTop, paddingEnd, paddingBottom);
materialButton.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
} else {
if (getMaterialShapeDrawable() != null) {
getMaterialShapeDrawable().setShapeAppearanceModel(shapeAppearanceModel);
Expand Down Expand Up @@ -443,9 +441,9 @@ public void setInsetTop(@Dimension int newInsetTop) {

private void setVerticalInsets(@Dimension int newInsetTop, @Dimension int newInsetBottom) {
// Store padding before setting background, since background overwrites padding values
int paddingStart = ViewCompat.getPaddingStart(materialButton);
int paddingLeft = materialButton.getPaddingLeft();
int paddingTop = materialButton.getPaddingTop();
int paddingEnd = ViewCompat.getPaddingEnd(materialButton);
int paddingRight = materialButton.getPaddingRight();
int paddingBottom = materialButton.getPaddingBottom();
int oldInsetTop = insetTop;
int oldInsetBottom = insetBottom;
Expand All @@ -455,11 +453,10 @@ private void setVerticalInsets(@Dimension int newInsetTop, @Dimension int newIns
updateBackground();
}
// Set the stored padding values
ViewCompat.setPaddingRelative(
materialButton,
paddingStart,
materialButton.setPadding(
paddingLeft,
paddingTop + newInsetTop - oldInsetTop,
paddingEnd,
paddingRight,
paddingBottom + newInsetBottom - oldInsetBottom);
}

Expand Down

0 comments on commit 90a0740

Please sign in to comment.