Browse Source

Support only showing label of selected bottom tab

Guy Carmeli 7 years ago
parent
commit
2357216671

+ 13
- 9
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

29
         createVisibilityAnimator();
29
         createVisibilityAnimator();
30
         setStyle();
30
         setStyle();
31
         setFontFamily(context);
31
         setFontFamily(context);
32
-        setTitlesDisplayState();
33
     }
32
     }
34
 
33
 
35
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
34
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
39
             addItem(item);
38
             addItem(item);
40
             setOnTabSelectedListener(onTabSelectedListener);
39
             setOnTabSelectedListener(onTabSelectedListener);
41
         }
40
         }
41
+        setTitlesDisplayState();
42
     }
42
     }
43
 
43
 
44
     public void setStyleFromScreen(StyleParams params) {
44
     public void setStyleFromScreen(StyleParams params) {
58
     private void setTitlesDisplayState() {
58
     private void setTitlesDisplayState() {
59
         if (AppStyle.appStyle.forceTitlesDisplay) {
59
         if (AppStyle.appStyle.forceTitlesDisplay) {
60
             setTitleState(TitleState.ALWAYS_SHOW);
60
             setTitleState(TitleState.ALWAYS_SHOW);
61
+        } else if (hasTabsWithLabels()) {
62
+            setTitleState(TitleState.SHOW_WHEN_ACTIVE);
61
         } else {
63
         } else {
62
-            centerIconsIfNeeded();
64
+            setTitleState(TitleState.ALWAYS_HIDE);
63
         }
65
         }
64
     }
66
     }
65
 
67
 
66
-    private void centerIconsIfNeeded() {
68
+    private boolean hasTabsWithLabels() {
67
         for (int i = 0; i < getItemsCount(); i++) {
69
         for (int i = 0; i < getItemsCount(); i++) {
68
             String title = getItem(0).getTitle(getContext());
70
             String title = getItem(0).getTitle(getContext());
69
             if (!TextUtils.isEmpty(title)) {
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
     public void setVisibility(boolean hidden, boolean animated) {
78
     public void setVisibility(boolean hidden, boolean animated) {
114
     }
116
     }
115
 
117
 
116
     private boolean hasBadgeTextColor() {
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
     private boolean hasBadgeBackgroundColor() {
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
     private boolean hasBottomTabFontFamily() {
128
     private boolean hasBottomTabFontFamily() {
126
     }
130
     }
127
 
131
 
128
     private void setFontFamily(Context context) {
132
     private void setFontFamily(Context context) {
129
-        if(hasBottomTabFontFamily()) {
133
+        if (hasBottomTabFontFamily()) {
130
 
134
 
131
             AssetManager assetManager = context.getAssets();
135
             AssetManager assetManager = context.getAssets();
132
             String fontFamilyName = AppStyle.appStyle.bottomTabFontFamily;
136
             String fontFamilyName = AppStyle.appStyle.bottomTabFontFamily;
142
                 e.printStackTrace();
146
                 e.printStackTrace();
143
             }
147
             }
144
 
148
 
145
-            if(typeFace != null) {
149
+            if (typeFace != null) {
146
                 setTitleTypeface(typeFace);
150
                 setTitleTypeface(typeFace);
147
             }
151
             }
148
         }
152
         }