Skip to content

Commit 7f0a51d

Browse files
imhappileticiarossi
authored andcommitted
[NavigationRail] Fix active indicator label jump when expanding
PiperOrigin-RevId: 713436233
1 parent 57297ae commit 7f0a51d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/java/com/google/android/material/navigation/NavigationBarItemView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ public void setActiveIndicatorExpandedHeight(int height) {
11751175
*
11761176
* @param availableWidth The total width of this item layout.
11771177
*/
1178-
private void updateActiveIndicatorLayoutParams(int availableWidth) {
1178+
public void updateActiveIndicatorLayoutParams(int availableWidth) {
11791179
// Set width to the min of either the desired indicator width or the available width minus
11801180
// a horizontal margin.
11811181
if (availableWidth <= 0 && getVisibility() == VISIBLE) {

lib/java/com/google/android/material/navigation/NavigationBarMenuView.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,4 +1484,14 @@ private void validateMenuItemId(int viewId) {
14841484
throw new IllegalArgumentException(viewId + " is not a valid view id");
14851485
}
14861486
}
1487+
1488+
public void updateActiveIndicator(int availableWidth) {
1489+
if (buttons != null) {
1490+
for (NavigationBarMenuItemView item : buttons) {
1491+
if (item instanceof NavigationBarItemView) {
1492+
((NavigationBarItemView) item).updateActiveIndicatorLayoutParams(availableWidth);
1493+
}
1494+
}
1495+
}
1496+
}
14871497
}

lib/java/com/google/android/material/navigationrail/NavigationRailView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
470470
}
471471
// Measure properly with the max child width
472472
minWidthSpec = makeExpandedWidthMeasureSpec(widthMeasureSpec, getMaxChildWidth());
473+
// If the active indicator is match_parent, it should be notified to update its width
474+
if (getItemActiveIndicatorExpandedWidth() == MATCH_PARENT) {
475+
getNavigationRailMenuView().updateActiveIndicator(MeasureSpec.getSize(minWidthSpec));
476+
}
473477
}
474478
super.onMeasure(minWidthSpec, heightMeasureSpec);
475479
// If the content container is measured to be less than the measured height of the nav rail,

0 commit comments

Comments
 (0)