Skip to content

Commit

Permalink
[Badge] Fix table formatting and remove unnecessary badge invalidation
Browse files Browse the repository at this point in the history
Resolves #3356

GIT_ORIGIN_REV_ID=9f6839aa225d567a26a7db948734c28a1bbae44a
PiperOrigin-RevId: 526735605
  • Loading branch information
pubiqq authored and leticiarossi committed Apr 25, 2023
1 parent b335436 commit 44a97f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions docs/components/BadgeDrawable.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,20 @@ center, use `setHorizontalOffset(int)` or `setVerticalOffset(int)`

| Feature | Relevant attributes |
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| Color | `app:backgroundColor` <br> `app:badgeTextColor` |
| Color | `app:backgroundColor` <br> `app:badgeTextColor` |
| Width | `app:badgeWidth` <br> `app:badgeWithTextWidth` |
| Height | `app:badgeHeight` <br> `app:badgeWithTextHeight` |
| Shape | `app:badgeShapeAppearance` <br> `app:badgeShapeAppearanceOverlay` <br> `app:badgeWithTextShapeAppearance` <br> `app:badgeWithTextShapeAppearanceOverlay` |
| Label | `app:badgeText` (for text) <br> `app:number` (for numbers) |
| Label Length | `app:maxCharacterCount` (for all text) <br> `app:maxNumber` (for numbers only) |
| Shape | `app:badgeShapeAppearance` <br> `app:badgeShapeAppearanceOverlay` <br> `app:badgeWithTextShapeAppearance` <br> `app:badgeWithTextShapeAppearanceOverlay` |
| Label | `app:badgeText` (for text) <br> `app:number` (for numbers) |
| Label Length | `app:maxCharacterCount` (for all text) <br> `app:maxNumber` (for numbers only) |
| Label Text Color | `app:badgeTextColor` |
| Label Text Appearance | `app:badgeTextAppearance` |
| Badge Gravity | `app:badgeGravity` |
| Offset Alignment | `app:offsetAlignmentMode` |
| Horizontal Padding | `app:badgeWidePadding` |
| Vertical Padding | `app:badgeVerticalPadding` |
| Auto Adjust | `app:autoAdjustToWithinGrandparentBounds` |

**Note:** If both `app:badgeText` and `app:number` are specified, the badge label will be `app:badgeText`.

### Talkback Support
Expand Down
8 changes: 5 additions & 3 deletions lib/java/com/google/android/material/badge/BadgeDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void updateBadgeCoordinates(
private boolean isAnchorViewWrappedInCompatParent() {
View customBadgeAnchorParent = getCustomBadgeParent();
return customBadgeAnchorParent != null
&& customBadgeAnchorParent.getId() == R.id.mtrl_anchor_parent;
&& customBadgeAnchorParent.getId() == R.id.mtrl_anchor_parent;
}

/** Returns a {@link FrameLayout} that will set this {@code BadgeDrawable} as its foreground. */
Expand Down Expand Up @@ -539,8 +539,10 @@ public void setNumber(int number) {

/** Clears the badge's number. */
public void clearNumber() {
state.clearNumber();
onNumberUpdated();
if (state.hasNumber()) {
state.clearNumber();
onNumberUpdated();
}
}

private void onNumberUpdated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-->

<resources>
<!-- Not used. Kept for backward compatibility -->
<integer name="mtrl_badge_max_character_count">4</integer>
<integer name="m3_badge_max_number">999</integer>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<item name="badgeWithTextHeight">@dimen/mtrl_badge_with_text_size</item>
<item name="badgeWidePadding">@dimen/mtrl_badge_long_text_horizontal_padding</item>
<item name="backgroundColor">?attr/colorError</item>
<item name="maxNumber">999</item>
<item name="maxNumber">@integer/m3_badge_max_number</item>
<item name="badgeGravity">TOP_END</item>
<item name="offsetAlignmentMode">legacy</item>
<item name="badgeTextAppearance">@style/TextAppearance.MaterialComponents.Badge</item>
Expand Down

0 comments on commit 44a97f4

Please sign in to comment.