Browse Source

Center bottom tab icons when no tab labels are provided

Guy Carmeli 7 years ago
parent
commit
4ae622fc6e

+ 1
- 1
android/app/build.gradle View File

54
     compile "com.facebook.react:react-native:+"
54
     compile "com.facebook.react:react-native:+"
55
 
55
 
56
     // third party
56
     // third party
57
-    compile "com.aurelhubert:ahbottomnavigation:1.3.3"
57
+    compile "com.aurelhubert:ahbottomnavigation:2.0.6"
58
     compile 'com.balysv.materialmenu:material-menu-toolbar:1.5.4'
58
     compile 'com.balysv.materialmenu:material-menu-toolbar:1.5.4'
59
 
59
 
60
     // tests
60
     // tests

+ 20
- 2
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

4
 import android.content.res.AssetManager;
4
 import android.content.res.AssetManager;
5
 import android.graphics.Color;
5
 import android.graphics.Color;
6
 import android.graphics.Typeface;
6
 import android.graphics.Typeface;
7
+import android.text.TextUtils;
7
 
8
 
8
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
9
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
9
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
28
         createVisibilityAnimator();
29
         createVisibilityAnimator();
29
         setStyle();
30
         setStyle();
30
         setFontFamily(context);
31
         setFontFamily(context);
32
+        setTitlesDisplayState();
31
     }
33
     }
32
 
34
 
33
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
35
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
50
             setAccentColor(params.selectedBottomTabsButtonColor.getColor());
52
             setAccentColor(params.selectedBottomTabsButtonColor.getColor());
51
         }
53
         }
52
 
54
 
53
-        setForceTitlesDisplay(params.forceTitlesDisplay);
54
-
55
         setVisibility(params.bottomTabsHidden, true);
55
         setVisibility(params.bottomTabsHidden, true);
56
     }
56
     }
57
 
57
 
58
+    private void setTitlesDisplayState() {
59
+        if (AppStyle.appStyle.forceTitlesDisplay) {
60
+            setTitleState(TitleState.ALWAYS_SHOW);
61
+        } else {
62
+            centerIconsIfNeeded();
63
+        }
64
+    }
65
+
66
+    private void centerIconsIfNeeded() {
67
+        for (int i = 0; i < getItemsCount(); i++) {
68
+            String title = getItem(0).getTitle(getContext());
69
+            if (!TextUtils.isEmpty(title)) {
70
+                return;
71
+            }
72
+        }
73
+        setTitleState(TitleState.ALWAYS_HIDE);
74
+    }
75
+
58
     public void setVisibility(boolean hidden, boolean animated) {
76
     public void setVisibility(boolean hidden, boolean animated) {
59
         if (visibilityAnimator != null) {
77
         if (visibilityAnimator != null) {
60
             visibilityAnimator.setVisible(!hidden, animated);
78
             visibilityAnimator.setVisible(!hidden, animated);