Ver código fonte

Support only showing label of selected bottom tab

Guy Carmeli 7 anos atrás
pai
commit
2357216671

+ 13
- 9
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java Ver arquivo

@@ -29,7 +29,6 @@ public class BottomTabs extends AHBottomNavigation {
29 29
         createVisibilityAnimator();
30 30
         setStyle();
31 31
         setFontFamily(context);
32
-        setTitlesDisplayState();
33 32
     }
34 33
 
35 34
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
@@ -39,6 +38,7 @@ public class BottomTabs extends AHBottomNavigation {
39 38
             addItem(item);
40 39
             setOnTabSelectedListener(onTabSelectedListener);
41 40
         }
41
+        setTitlesDisplayState();
42 42
     }
43 43
 
44 44
     public void setStyleFromScreen(StyleParams params) {
@@ -58,19 +58,21 @@ public class BottomTabs extends AHBottomNavigation {
58 58
     private void setTitlesDisplayState() {
59 59
         if (AppStyle.appStyle.forceTitlesDisplay) {
60 60
             setTitleState(TitleState.ALWAYS_SHOW);
61
+        } else if (hasTabsWithLabels()) {
62
+            setTitleState(TitleState.SHOW_WHEN_ACTIVE);
61 63
         } else {
62
-            centerIconsIfNeeded();
64
+            setTitleState(TitleState.ALWAYS_HIDE);
63 65
         }
64 66
     }
65 67
 
66
-    private void centerIconsIfNeeded() {
68
+    private boolean hasTabsWithLabels() {
67 69
         for (int i = 0; i < getItemsCount(); i++) {
68 70
             String title = getItem(0).getTitle(getContext());
69 71
             if (!TextUtils.isEmpty(title)) {
70
-                return;
72
+                return true;
71 73
             }
72 74
         }
73
-        setTitleState(TitleState.ALWAYS_HIDE);
75
+        return false;
74 76
     }
75 77
 
76 78
     public void setVisibility(boolean hidden, boolean animated) {
@@ -114,11 +116,13 @@ public class BottomTabs extends AHBottomNavigation {
114 116
     }
115 117
 
116 118
     private boolean hasBadgeTextColor() {
117
-        return AppStyle.appStyle.bottomTabBadgeTextColor != null && AppStyle.appStyle.bottomTabBadgeTextColor.hasColor();
119
+        return AppStyle.appStyle.bottomTabBadgeTextColor != null &&
120
+               AppStyle.appStyle.bottomTabBadgeTextColor.hasColor();
118 121
     }
119 122
 
120 123
     private boolean hasBadgeBackgroundColor() {
121
-        return AppStyle.appStyle.bottomTabBadgeBackgroundColor != null && AppStyle.appStyle.bottomTabBadgeBackgroundColor.hasColor();
124
+        return AppStyle.appStyle.bottomTabBadgeBackgroundColor != null &&
125
+               AppStyle.appStyle.bottomTabBadgeBackgroundColor.hasColor();
122 126
     }
123 127
 
124 128
     private boolean hasBottomTabFontFamily() {
@@ -126,7 +130,7 @@ public class BottomTabs extends AHBottomNavigation {
126 130
     }
127 131
 
128 132
     private void setFontFamily(Context context) {
129
-        if(hasBottomTabFontFamily()) {
133
+        if (hasBottomTabFontFamily()) {
130 134
 
131 135
             AssetManager assetManager = context.getAssets();
132 136
             String fontFamilyName = AppStyle.appStyle.bottomTabFontFamily;
@@ -142,7 +146,7 @@ public class BottomTabs extends AHBottomNavigation {
142 146
                 e.printStackTrace();
143 147
             }
144 148
 
145
-            if(typeFace != null) {
149
+            if (typeFace != null) {
146 150
                 setTitleTypeface(typeFace);
147 151
             }
148 152
         }