Skip to content

Commit

Permalink
[Home] Fix occasional failure to evenly space icons in bottom nav.
Browse files Browse the repository at this point in the history
Instead of relying on the menu items to provide their width to us to
space them apart, a dimension has been added to dimens.xml since the
icons will always be the same size anyway.

[email protected]

(cherry picked from commit e6b519d)

Bug: 763033
Change-Id: Ia34fb7a09589df10f565559da51c01fef972bfbf
Reviewed-on: https://chromium-review.googlesource.com/658300
Reviewed-by: Theresa <[email protected]>
Commit-Queue: Troy Hildebrandt <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#500837}
Reviewed-on: https://chromium-review.googlesource.com/664981
Reviewed-by: Matthew Jones <[email protected]>
Cr-Commit-Position: refs/branch-heads/3202@{crosswalk-project#201}
Cr-Branched-From: fa6a5d8-refs/heads/master@{#499098}
  • Loading branch information
iotitan committed Sep 13, 2017
1 parent 9d1397e commit c36666c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions chrome/android/java/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@
<dimen name="bottom_sheet_help_bubble_inset">10dp</dimen>
<dimen name="bottom_nav_height">40dp</dimen>
<dimen name="bottom_nav_space_from_toolbar">96dp</dimen>
<dimen name="bottom_nav_menu_item_size">24dp</dimen>
<!-- The following two dimensions override defaults in Android's BottomNavigationView -->

<!-- Chrome Home dimensions -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ public void onGlobalLayout() {
* menu items are spaced apart appropriately.
*/
private void updateMenuItemSpacing() {
getMenuView().updateMenuItemSpacingForMinWidth(
mBottomSheet.getWidth(), mBottomSheet.getHeight());
Resources res = getContext().getResources();
getMenuView().updateMenuItemSpacingForMinWidth(mBottomSheet.getWidth(),
mBottomSheet.getHeight(),
res.getDimensionPixelSize(R.dimen.bottom_nav_menu_item_size));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,15 @@ private BottomNavigationItemView getNewItem() {
*
* @param layoutWidth Width of the navigation menu's container.
* @param layoutHeight Height of the navigation menu's container.
* @param iconWidth The width of the menu item icons, necessary for proper spacing.
*/
public void updateMenuItemSpacingForMinWidth(int layoutWidth, int layoutHeight) {
public void updateMenuItemSpacingForMinWidth(int layoutWidth, int layoutHeight, int iconWidth) {
if (mButtons.length == 0) return;

int menuWidth = Math.min(layoutWidth, layoutHeight);
if (menuWidth != mMenuWidth) {
mMenuWidth = menuWidth;
int iconWidths = 0;
for (BottomNavigationItemView item : mButtons) {
iconWidths += item.getWidth() - (item.getPaddingLeft() + item.getPaddingRight());
}

int iconWidths = iconWidth * mButtons.length;
int padding = (menuWidth - iconWidths) / (mButtons.length * 2);
for (BottomNavigationItemView item : mButtons) {
item.setPadding(padding, item.getPaddingTop(), padding, item.getPaddingBottom());
Expand Down

0 comments on commit c36666c

Please sign in to comment.