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 Aug 13, 2024
1 parent cfef899 commit eb718a7
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,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 @@ -137,10 +137,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 @@ -412,13 +412,13 @@ private void updateButtonShape() {
// 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 {
MaterialShapeDrawable backgroundDrawable = getMaterialShapeDrawable();
if (backgroundDrawable != null) {
Expand Down Expand Up @@ -521,9 +521,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 @@ -533,10 +533,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 eb718a7

Please sign in to comment.