Skip to content

Commit

Permalink
[BottomNavigationView] Integrate tokens and add shape appearance support
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 524919091
  • Loading branch information
imhappi authored and drchen committed Apr 19, 2023
1 parent add7f5d commit 7bd9724
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Expand Up @@ -26,6 +26,11 @@
<attr name="android:minHeight" />
<!-- Whether or not to add a shadow with a divider that is compatible across pre-21 legacy backgrounds. -->
<attr name="compatShadowEnabled" format="boolean"/>
<!-- Shape appearance style reference for BottomNavigationView. Attribute declaration is in the Shape package. -->
<attr name="shapeAppearance"/>
<!-- Shape appearance overlay style reference for BottomNavigationView. To be used to augment
attributes declared in the shapeAppearance. Attribute declaration is in the Shape package. -->
<attr name="shapeAppearanceOverlay"/>
</declare-styleable>

</resources>
Expand Up @@ -79,6 +79,7 @@
<item name="itemPaddingBottom">@dimen/m3_bottom_nav_item_padding_bottom</item>
<item name="android:minHeight">@dimen/m3_bottom_nav_min_height</item>
<item name="materialThemeOverlay">@style/ThemeOverlay.Material3.BottomNavigationView</item>
<item name="shapeAppearance">@style/ShapeAppearance.M3.Comp.NavigationBar.Container.Shape</item>
</style>

<style name="Widget.Material3.BottomNavigationView" parent="Base.Widget.Material3.BottomNavigationView">
Expand Down
Expand Up @@ -22,6 +22,7 @@
<!-- Generated from token set (md.comp.navigation-bar) in context (platform=android, audience=3p). -->
<!-- Enabled - Container -->
<macro name="m3_comp_navigation_bar_container_color">?attr/colorSurface</macro>
<style name="ShapeAppearance.M3.Comp.NavigationBar.Container.Shape" parent="ShapeAppearance.M3.Sys.Shape.Corner.None"/>
<dimen name="m3_comp_navigation_bar_container_height">80dp</dimen>
<dimen name="m3_comp_navigation_bar_container_elevation">@dimen/m3_sys_elevation_level2</dimen>
<!-- Enabled - Label text -->
Expand Down
Expand Up @@ -193,7 +193,8 @@ public NavigationBarView(

if (getBackground() == null || getBackground() instanceof ColorDrawable) {
// Add a MaterialShapeDrawable as background that supports tinting in every API level.
ViewCompat.setBackground(this, createMaterialShapeDrawableBackground(context));
ViewCompat.setBackground(this, createMaterialShapeDrawableBackground(context,
ShapeAppearanceModel.builder(context, attrs, defStyleAttr, defStyleRes).build()));
}

if (attributes.hasValue(R.styleable.NavigationBarView_itemPaddingTop)) {
Expand Down Expand Up @@ -297,14 +298,16 @@ public void onMenuModeChange(MenuBuilder menu) {}
}

@NonNull
private MaterialShapeDrawable createMaterialShapeDrawableBackground(Context context) {
private MaterialShapeDrawable createMaterialShapeDrawableBackground(
Context context, ShapeAppearanceModel shapeAppearanceModel) {
MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
Drawable originalBackground = getBackground();
if (originalBackground instanceof ColorDrawable) {
materialShapeDrawable.setFillColor(
ColorStateList.valueOf(((ColorDrawable) originalBackground).getColor()));
}
materialShapeDrawable.initializeElevationOverlay(context);
materialShapeDrawable.setShapeAppearanceModel(shapeAppearanceModel);
return materialShapeDrawable;
}

Expand Down

0 comments on commit 7bd9724

Please sign in to comment.