Selaa lähdekoodia

Center bottom tab icons when no tab labels are provided

Guy Carmeli 7 vuotta sitten
vanhempi
commit
4ae622fc6e

+ 1
- 1
android/app/build.gradle Näytä tiedosto

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

+ 20
- 2
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java Näytä tiedosto

@@ -4,6 +4,7 @@ import android.content.Context;
4 4
 import android.content.res.AssetManager;
5 5
 import android.graphics.Color;
6 6
 import android.graphics.Typeface;
7
+import android.text.TextUtils;
7 8
 
8 9
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
9 10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
@@ -28,6 +29,7 @@ public class BottomTabs extends AHBottomNavigation {
28 29
         createVisibilityAnimator();
29 30
         setStyle();
30 31
         setFontFamily(context);
32
+        setTitlesDisplayState();
31 33
     }
32 34
 
33 35
     public void addTabs(List<ScreenParams> params, OnTabSelectedListener onTabSelectedListener) {
@@ -50,11 +52,27 @@ public class BottomTabs extends AHBottomNavigation {
50 52
             setAccentColor(params.selectedBottomTabsButtonColor.getColor());
51 53
         }
52 54
 
53
-        setForceTitlesDisplay(params.forceTitlesDisplay);
54
-
55 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 76
     public void setVisibility(boolean hidden, boolean animated) {
59 77
         if (visibilityAnimator != null) {
60 78
             visibilityAnimator.setVisible(!hidden, animated);