Skip to content

Commit 0e9ab66

Browse files
imhappipaulfthomas
authored andcommitted
[NavigationRail] Integrate tokens
PiperOrigin-RevId: 699328711
1 parent 5f44dbc commit 0e9ab66

File tree

5 files changed

+75
-27
lines changed

5 files changed

+75
-27
lines changed

docs/components/NavigationRail.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,17 @@ for more attributes.
369369

370370
#### Navigation item attributes
371371

372-
**Element** | **Attribute** | **Related methods** | **Default value**
373-
------------------------- | ------------------------- | ----------------------------------------------------- | -----------------
374-
**Menu resource** | `app:menu` | `inflateMenu`<br/>`getMenu` | N/A
375-
**Ripple (inactive)** | `app:itemRippleColor` | `setItemRippleColor`<br/>`getItemRippleColor` | `?attr/colorPrimary` at 12% (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/mtrl_navigation_bar_ripple_color.xml))
376-
**Ripple (active)** | `app:itemRippleColor` | `setItemRippleColor`<br/>`getItemRippleColor` | `?attr/colorPrimary` at 12% (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/mtrl_navigation_bar_ripple_color.xml))
377-
**Label visibility mode** | `app:labelVisibilityMode` | `setLabelVisibilityMode`<br/>`getLabelVisibilityMode` | `LABEL_VISIBILITY_AUTO`
378-
**Item minimum height** | `app:itemMinHeight` | `setItemMinimumHeight`<br/>`getItemMinimumHeight` | `NO_ITEM_MINIMUM_HEIGHT`
379-
**Item spacing** | `app:itemSpacing` | `setItemSpacing`<br/>`getItemSpacing` | `0dp`
380-
**Item Gravity** | `app:itemGravity` | `setItemGravity`<br/>`getItemGravity` | `TOP_CENTER`
372+
**Element** | **Attribute** | **Related methods** | **Default value**
373+
--------------------------------- | ---------------------------- | ------------------------------------------------------------------- | -----------------
374+
**Menu resource** | `app:menu` | `inflateMenu`<br/>`getMenu` | N/A
375+
**Ripple (inactive)** | `app:itemRippleColor` | `setItemRippleColor`<br/>`getItemRippleColor` | `?attr/colorPrimary` at 12% (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/mtrl_navigation_bar_ripple_color.xml))
376+
**Ripple (active)** | `app:itemRippleColor` | `setItemRippleColor`<br/>`getItemRippleColor` | `?attr/colorPrimary` at 12% (see all [states](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/navigation/res/color/mtrl_navigation_bar_ripple_color.xml))
377+
**Label visibility mode** | `app:labelVisibilityMode` | `setLabelVisibilityMode`<br/>`getLabelVisibilityMode` | `LABEL_VISIBILITY_AUTO`
378+
**Item minimum height** | `app:itemMinHeight` | `setItemMinimumHeight`<br/>`getItemMinimumHeight` | `NO_ITEM_MINIMUM_HEIGHT`
379+
**Collapsed item minimum height** | `app:collapsedItemMinHeight` | `setCollapsedItemMinimumHeight`<br/>`getCollapsedItemMinimumHeight` | `NO_ITEM_MINIMUM_HEIGHT`
380+
**Expanded item minimum height** | `app:expandedItemMinHeight` | `setExpandedItemMinimumHeight`<br/>`getExpandedItemMinimumHeight` | `NO_ITEM_MINIMUM_HEIGHT`
381+
**Item spacing** | `app:itemSpacing` | `setItemSpacing`<br/>`getItemSpacing` | `0dp`
382+
**Item Gravity** | `app:itemGravity` | `setItemGravity`<br/>`getItemGravity` | `TOP_CENTER`
381383

382384
**Note:** If there's not enough room, `itemMinHeight` and `itemSpacing` may not be respected in order to fit the items.
383385

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

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,10 @@ public NavigationRailView(
169169

170170
// Ensure we are using the correctly themed context rather than the context that was passed in.
171171
context = getContext();
172-
minExpandedWidth =
173-
getContext()
174-
.getResources()
175-
.getDimensionPixelSize(R.dimen.m3_navigation_rail_min_expanded_width);
176-
maxExpandedWidth =
177-
getContext()
178-
.getResources()
179-
.getDimensionPixelSize(R.dimen.m3_navigation_rail_max_expanded_width);
180172
expandedItemSpacing =
181173
getContext()
182174
.getResources()
183175
.getDimensionPixelSize(R.dimen.m3_navigation_rail_expanded_item_spacing);
184-
expandedItemMinHeight =
185-
getContext()
186-
.getResources()
187-
.getDimensionPixelSize(R.dimen.m3_navigation_rail_expanded_item_min_height);
188176
expandedItemGravity = ITEM_GRAVITY_START_CENTER;
189177
expandedIconGravity = ITEM_ICON_GRAVITY_START;
190178

@@ -213,11 +201,31 @@ public NavigationRailView(
213201
setMenuGravity(
214202
attributes.getInt(R.styleable.NavigationRailView_menuGravity, DEFAULT_MENU_GRAVITY));
215203

216-
if (attributes.hasValue(R.styleable.NavigationRailView_itemMinHeight)) {
217-
setCollapsedItemMinimumHeight(
218-
attributes.getDimensionPixelSize(
219-
R.styleable.NavigationRailView_itemMinHeight, NO_ITEM_MINIMUM_HEIGHT));
204+
int collapsedItemMinHeight = attributes.getDimensionPixelSize(
205+
R.styleable.NavigationRailView_itemMinHeight, NO_ITEM_MINIMUM_HEIGHT);
206+
int expandedItemMinHeight = attributes.getDimensionPixelSize(
207+
R.styleable.NavigationRailView_itemMinHeight, NO_ITEM_MINIMUM_HEIGHT);
208+
209+
if (attributes.hasValue(R.styleable.NavigationRailView_collapsedItemMinHeight)) {
210+
collapsedItemMinHeight = attributes.getDimensionPixelSize(
211+
R.styleable.NavigationRailView_collapsedItemMinHeight, NO_ITEM_MINIMUM_HEIGHT);
220212
}
213+
if (attributes.hasValue(R.styleable.NavigationRailView_expandedItemMinHeight)) {
214+
expandedItemMinHeight = attributes.getDimensionPixelSize(
215+
R.styleable.NavigationRailView_expandedItemMinHeight, NO_ITEM_MINIMUM_HEIGHT);
216+
}
217+
setCollapsedItemMinimumHeight(collapsedItemMinHeight);
218+
setExpandedItemMinimumHeight(expandedItemMinHeight);
219+
minExpandedWidth = attributes.getDimensionPixelSize(
220+
R.styleable.NavigationRailView_expandedMinWidth,
221+
context
222+
.getResources()
223+
.getDimensionPixelSize(R.dimen.m3_navigation_rail_min_expanded_width));
224+
maxExpandedWidth = attributes.getDimensionPixelSize(
225+
R.styleable.NavigationRailView_expandedMaxWidth,
226+
context
227+
.getResources()
228+
.getDimensionPixelSize(R.dimen.m3_navigation_rail_max_expanded_width));
221229

222230
if (attributes.hasValue(R.styleable.NavigationRailView_paddingTopSystemWindowInsets)) {
223231
paddingTopSystemWindowInsets =
@@ -568,6 +576,32 @@ public void setCollapsedItemMinimumHeight(@Px int minHeight) {
568576
}
569577
}
570578

579+
/**
580+
* Gets the minimum height of a navigation rail menu item when the navigation rail is collapsed.
581+
*/
582+
public int getCollapsedItemMinimumHeight() {
583+
return collapsedItemMinHeight;
584+
}
585+
586+
/**
587+
* Sets the minimum height of a navigation rail menu item when the navigation rail is expanded.
588+
*
589+
* @param minHeight the min height of the item when the nav rail is collapsed
590+
*/
591+
public void setExpandedItemMinimumHeight(@Px int minHeight) {
592+
expandedItemMinHeight = minHeight;
593+
if (expanded) {
594+
((NavigationRailMenuView) getMenuView()).setItemMinimumHeight(minHeight);
595+
}
596+
}
597+
598+
/**
599+
* Gets the minimum height of a navigation rail menu item when the navigation rail is expanded.
600+
*/
601+
public int getExpandedItemMinimumHeight() {
602+
return expandedItemMinHeight;
603+
}
604+
571605
/**
572606
* Set the padding in between the navigation rail menu items.
573607
*/

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<!-- Definitions of attributes to be exposed as public -->
1919
<resources>
2020
<public name="itemMinHeight" type="attr"/>
21+
<public name="expandedItemMinHeight" type="attr"/>
22+
<public name="expandedMinWidth" type="attr"/>
23+
<public name="expandedMaxWidth" type="attr"/>
2124
<public name="navigationRailStyle" type="attr"/>
2225
<public name="menuGravity" type="attr"/>
2326
<public name="contentMarginTop" type="attr"/>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@
1919
<attr name="navigationRailStyle" format="reference"/>
2020

2121
<declare-styleable name="NavigationRailView">
22-
<!-- The minimum height of each menu item. If not set, the min height -->
22+
<!-- The minimum height of each menu item when the navigation rail. If not set, the min height -->
2323
<!-- will be the same as the width of the rail. -->
2424
<attr name="itemMinHeight" format="dimension"/>
25+
<!-- The minimum height of each menu item when the navigation rail is collapsed. If set, this value
26+
overrides itemMinHeight when the navigation rail is collapsed. -->
27+
<attr name="collapsedItemMinHeight" format="dimension"/>
28+
<!-- The minimum height of each menu item when the navigation rail is expanded. If set, this value
29+
overrides itemMinHeight when the navigation rail is expanded. -->
30+
<attr name="expandedItemMinHeight" format="dimension"/>
31+
<!-- The min width of the navigation rail when it is expanded. -->
32+
<attr name="expandedMinWidth" format="dimension"/>
33+
<!-- The max width of the navigation rail when it is expanded. -->
34+
<attr name="expandedMaxWidth" format="dimension"/>
2535
<!-- Specifies the layout that will be used to create the header view, if any -->
2636
<attr name="headerLayout"/>
2737
<!-- The bottom margin of the header -->

lib/java/com/google/android/material/navigationrail/res/values/dimens.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,5 @@
4747
<dimen name="m3_navigation_rail_min_expanded_width">220dp</dimen>
4848
<dimen name="m3_navigation_rail_max_expanded_width">360dp</dimen>
4949
<dimen name="m3_navigation_rail_expanded_item_spacing">0dp</dimen>
50-
<dimen name="m3_navigation_rail_expanded_item_min_height">56dp</dimen>
5150

5251
</resources>

0 commit comments

Comments
 (0)