Skip to content

Commit

Permalink
Support always using big items
Browse files Browse the repository at this point in the history
When only 3 tabs are present with title hidden
  • Loading branch information
guyca committed Nov 17, 2019
1 parent d31f332 commit 10a66ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum TitleState {
private int bottomNavigationHeight, navigationBarHeight = 0;
private float selectedItemWidth, notSelectedItemWidth;
private boolean forceTint = false;
private boolean alwaysUseBigItems = false;
private TitleState titleState = TitleState.SHOW_WHEN_ACTIVE;

// Notifications
Expand Down Expand Up @@ -288,9 +289,9 @@ protected void createItems() {
LayoutParams layoutParams = new LayoutParams(MATCH_PARENT, layoutHeight);
addView(linearLayoutContainer, layoutParams);

if (titleState != TitleState.ALWAYS_HIDE &&
if ((alwaysUseBigItems && items.size() == MIN_ITEMS) || (titleState != TitleState.ALWAYS_HIDE &&
titleState != TitleState.SHOW_WHEN_ACTIVE_FORCE &&
(items.size() == MIN_ITEMS || titleState == TitleState.ALWAYS_SHOW)) {
(items.size() == MIN_ITEMS || titleState == TitleState.ALWAYS_SHOW))) {
createClassicItems(linearLayoutContainer);
} else {
createSmallItems(linearLayoutContainer);
Expand Down Expand Up @@ -383,7 +384,14 @@ private void createClassicItems(LinearLayout linearLayout) {
AHTextView notification = view.findViewById(R.id.bottom_navigation_notification);

icon.setImageDrawable(item.getDrawable(context));
title.setText(item.getTitle(context));
if (titleState == TitleState.ALWAYS_HIDE) {
title.setVisibility(View.GONE);
((LayoutParams) icon.getLayoutParams()).gravity = Gravity.CENTER;
int iconHeight = resources.getDimensionPixelSize(R.dimen.bottom_navigation_icon);
((MarginLayoutParams) notification.getLayoutParams()).topMargin = (bottomNavigationHeight - iconHeight) / 2 - dpToPx(4);
} else {
title.setText(item.getTitle(context));
}

title.setTypeface(titleTypeface.get(i));

Expand Down Expand Up @@ -1697,4 +1705,12 @@ public interface OnNavigationPositionListener {
void onPositionChange(int y);
}

public void setAlwaysUseBigItems(boolean alwaysUseBigItems) {
this.alwaysUseBigItems = alwaysUseBigItems;
}

private int dpToPx(int dp) {
DisplayMetrics metrics = getResources().getDisplayMetrics();
return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public void updateSelectedBackgroundVisibility(boolean isVisible) {
* Set title state for bottomNavigation
*/
public void setTitleState(AHBottomNavigation.TitleState titleState) {
if (titleState == AHBottomNavigation.TitleState.ALWAYS_HIDE) bottomNavigation.setAlwaysUseBigItems(true);
bottomNavigation.setTitleState(titleState);
}

Expand Down

0 comments on commit 10a66ea

Please sign in to comment.