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 14, 2024
1 parent 9b6ceac commit c06f058
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,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 = materialButton.getPaddingStart();
int paddingLeft = materialButton.getPaddingLeft();
int paddingTop = materialButton.getPaddingTop();
int paddingEnd = materialButton.getPaddingEnd();
int paddingRight = materialButton.getPaddingRight();
int paddingBottom = materialButton.getPaddingBottom();

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

Expand Down Expand Up @@ -382,13 +382,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 = materialButton.getPaddingStart();
int paddingLeft = materialButton.getPaddingLeft();
int paddingTop = materialButton.getPaddingTop();
int paddingEnd = materialButton.getPaddingEnd();
int paddingRight = materialButton.getPaddingRight();
int paddingBottom = materialButton.getPaddingBottom();
updateBackground();
// Set the stored padding values
materialButton.setPaddingRelative(paddingStart, paddingTop, paddingEnd, paddingBottom);
materialButton.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
} else {
if (getMaterialShapeDrawable() != null) {
getMaterialShapeDrawable().setShapeAppearanceModel(shapeAppearanceModel);
Expand Down Expand Up @@ -440,9 +440,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 = materialButton.getPaddingStart();
int paddingLeft = materialButton.getPaddingLeft();
int paddingTop = materialButton.getPaddingTop();
int paddingEnd = materialButton.getPaddingEnd();
int paddingRight = materialButton.getPaddingRight();
int paddingBottom = materialButton.getPaddingBottom();
int oldInsetTop = insetTop;
int oldInsetBottom = insetBottom;
Expand All @@ -452,10 +452,10 @@ private void setVerticalInsets(@Dimension int newInsetTop, @Dimension int newIns
updateBackground();
}
// Set the stored padding values
materialButton.setPaddingRelative(
paddingStart,
materialButton.setPadding(
paddingLeft,
paddingTop + newInsetTop - oldInsetTop,
paddingEnd,
paddingRight,
paddingBottom + newInsetBottom - oldInsetBottom);
}

Expand Down

0 comments on commit c06f058

Please sign in to comment.