Skip to content

Commit 0d265b7

Browse files
imhappileticiarossi
authored andcommitted
[Badge] Deprecate autoAdjustToGrandparentBounds attribute since now badges automatically move within first ancestor view that does not clip children
PiperOrigin-RevId: 630215388
1 parent 8f8c6ee commit 0d265b7

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

docs/components/BadgeDrawable.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Option 2: If you do not want `BadgeDrawable` to modify your view hierarchy, you
7979
can specify a `FrameLayout` to display the badge instead.
8080

8181
```java
82-
* BadgeUtils.attachBadgeDrawable(badgeDrawable, anchor, anchorFrameLayoutParent);
82+
BadgeUtils.attachBadgeDrawable(badgeDrawable, anchor, anchorFrameLayoutParent);
8383
```
8484

8585
### `BadgeDrawable` Gravity Modes
@@ -90,13 +90,17 @@ of the anchor (with some offsets). Alternatively, you can use `TOP_START` to
9090
align the badge with the top and start edges of the anchor. Note that
9191
`BOTTOM_START` and `BOTTOM_END` are deprecated and not recommended for use.
9292

93-
### `BadgeDrawable` center offsets
93+
### `BadgeDrawable` placement and offsets
9494

9595
By default, `BadgeDrawable` is aligned with the top and end edges of its anchor
9696
view (with some offsets if `offsetAlignmentMode` is `legacy`). Call `setBadgeGravity(int)` to change it to one of the
9797
other supported modes. To adjust the badge's offsets relative to the anchor's
9898
center, use `setHorizontalOffset(int)` or `setVerticalOffset(int)`
9999

100+
Regardless of offsets, badges are automatically moved to within the bounds of
101+
its first ancestor view that does not clip its children, to ensure that the
102+
badge is not clipped if there is enough space.
103+
100104
### `BadgeDrawable` Attributes
101105

102106
| Feature | Relevant attributes |
@@ -114,7 +118,6 @@ center, use `setHorizontalOffset(int)` or `setVerticalOffset(int)`
114118
| Horizontal Padding | `app:badgeWidePadding` |
115119
| Vertical Padding | `app:badgeVerticalPadding` |
116120
| Large Font Vertical Offset| `app:largeFontVerticalOffsetAdjustment` |
117-
| Auto Adjust | `app:autoAdjustToWithinGrandparentBounds` |
118121

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

lib/java/com/google/android/material/badge/BadgeDrawable.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,12 +1078,15 @@ int getAdditionalVerticalOffset() {
10781078
}
10791079

10801080
/**
1081-
* Sets whether or not to auto adjust the badge placement to within the badge anchor's
1082-
* grandparent view.
1081+
* Sets whether or not to auto adjust the badge placement to within the badge anchor's grandparent
1082+
* view.
10831083
*
1084-
* @param autoAdjustToWithinGrandparentBounds whether or not to auto adjust to within
1085-
* the anchor's grandparent view.
1084+
* @param autoAdjustToWithinGrandparentBounds whether or not to auto adjust to within the anchor's
1085+
* grandparent view.
1086+
* @deprecated Badges now automatically adjust their bounds within the first ancestor view that *
1087+
* clips its children.
10861088
*/
1089+
@Deprecated
10871090
public void setAutoAdjustToWithinGrandparentBounds(boolean autoAdjustToWithinGrandparentBounds) {
10881091
if (state.isAutoAdjustedToGrandparentBounds() == autoAdjustToWithinGrandparentBounds) {
10891092
return;

lib/java/com/google/android/material/badge/BadgeState.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,14 @@ void setNumberLocale(Locale locale) {
604604
currentState.numberLocale = locale;
605605
}
606606

607+
/** Deprecated; badges now adjust to within bounds of first ancestor that clips its children */
608+
@Deprecated
607609
boolean isAutoAdjustedToGrandparentBounds() {
608610
return currentState.autoAdjustToWithinGrandparentBounds;
609611
}
610612

613+
/** Deprecated; badges now adjust to within bounds of first ancestor that clips its children */
614+
@Deprecated
611615
void setAutoAdjustToGrandparentBounds(boolean autoAdjustToGrandparentBounds) {
612616
overridingState.autoAdjustToWithinGrandparentBounds = autoAdjustToGrandparentBounds;
613617
currentState.autoAdjustToWithinGrandparentBounds = autoAdjustToGrandparentBounds;

lib/java/com/google/android/material/badge/res-public/values/public.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
<public name="badgeShapeAppearance" type="attr"/>
3838
<public name="badgeWithTextShapeAppearance" type="attr"/>
3939
<public name="badgeShapeAppearanceOverlay" type="attr"/>
40+
<!-- Deprecated. Badges are automatically moved to within first ancestor
41+
that clips its children. -->
4042
<public name="autoAdjustToWithinGrandparentBounds" type="attr"/>
4143
<public name="badgeWithTextShapeAppearanceOverlay" type="attr"/>
4244
<public name="Widget.MaterialComponents.Badge" type="style"/>

lib/java/com/google/android/material/badge/res/values/attrs.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@
9898
attribute determines how much to shift the normal vertical offset by. -->
9999
<attr name="largeFontVerticalOffsetAdjustment" format="dimension"/>
100100
<!-- Automatically move the badge so it is within the anchor view's
101-
grandparent's bounds. -->
101+
grandparent's bounds. Deprecated, badges are now automatically moved to
102+
within the first ancestor that clips its children. -->
102103
<attr name="autoAdjustToWithinGrandparentBounds" format="boolean"/>
103104
</declare-styleable>
104105

0 commit comments

Comments
 (0)