Procházet zdrojové kódy

Support fontSize and selectedFontSize options on Android

Guy Carmeli před 6 roky
rodič
revize
3fd183a51b

+ 3
- 1
docs/docs/styling.md Zobrazit soubor

@@ -224,7 +224,9 @@ Navigation.mergeOptions(this.props.componentId, {
224 224
   },
225 225
   bottomTabs: {
226 226
     titleDisplayMode: 'alwaysShow' | 'showWhenActive' | 'alwaysHide' // Sets the title state for each tab.
227
-  }
227
+  },
228
+  bottomTab: {
229
+    selectedFontSize: 19 // Selected tab font size in sp
228 230
 }
229 231
 ```
230 232
 

+ 1
- 1
lib/android/app/build.gradle Zobrazit soubor

@@ -72,7 +72,7 @@ dependencies {
72 72
     implementation 'com.android.support:design:26.1.0'
73 73
     implementation 'com.android.support:appcompat-v7:26.1.0'
74 74
     implementation 'com.android.support:support-v4:26.1.0'
75
-    implementation 'com.github.wix-playground:ahbottomnavigation:2.4.3'
75
+    implementation 'com.github.wix-playground:ahbottomnavigation:2.4.5'
76 76
 
77 77
     implementation 'com.github.clans:fab:1.6.4'
78 78
 

+ 11
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabOptions.java Zobrazit soubor

@@ -5,9 +5,12 @@ import android.support.annotation.Nullable;
5 5
 
6 6
 import com.reactnativenavigation.parse.params.Color;
7 7
 import com.reactnativenavigation.parse.params.NullColor;
8
+import com.reactnativenavigation.parse.params.NullNumber;
8 9
 import com.reactnativenavigation.parse.params.NullText;
10
+import com.reactnativenavigation.parse.params.Number;
9 11
 import com.reactnativenavigation.parse.params.Text;
10 12
 import com.reactnativenavigation.parse.parsers.ColorParser;
13
+import com.reactnativenavigation.parse.parsers.NumberParser;
11 14
 import com.reactnativenavigation.parse.parsers.TextParser;
12 15
 import com.reactnativenavigation.utils.TypefaceLoader;
13 16
 
@@ -28,6 +31,8 @@ public class BottomTabOptions {
28 31
         options.badge = TextParser.parse(json, "badge");
29 32
         options.testId = TextParser.parse(json, "testID");
30 33
         options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", ""));
34
+        options.fontSize = NumberParser.parse(json, "fontSize");
35
+        options.selectedFontSize = NumberParser.parse(json, "selectedFontSize");
31 36
         return options;
32 37
     }
33 38
 
@@ -39,6 +44,8 @@ public class BottomTabOptions {
39 44
     public Color selectedIconColor = new NullColor();
40 45
     public Text testId = new NullText();
41 46
     public Text badge = new NullText();
47
+    public Number fontSize = new NullNumber();
48
+    public Number selectedFontSize = new NullNumber();
42 49
     @Nullable public Typeface fontFamily;
43 50
 
44 51
 
@@ -51,6 +58,8 @@ public class BottomTabOptions {
51 58
         if (other.selectedIconColor.hasValue()) selectedIconColor = other.selectedIconColor;
52 59
         if (other.badge.hasValue()) badge = other.badge;
53 60
         if (other.testId.hasValue()) testId = other.testId;
61
+        if (other.fontSize.hasValue()) fontSize = other.fontSize;
62
+        if (other.selectedFontSize.hasValue()) selectedFontSize = other.selectedFontSize;
54 63
         if (other.fontFamily != null) fontFamily = other.fontFamily;
55 64
     }
56 65
 
@@ -62,6 +71,8 @@ public class BottomTabOptions {
62 71
         if (!iconColor.hasValue()) iconColor = defaultOptions.iconColor;
63 72
         if (!selectedIconColor.hasValue()) selectedIconColor = defaultOptions.selectedIconColor;
64 73
         if (!badge.hasValue()) badge = defaultOptions.badge;
74
+        if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
75
+        if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize;
65 76
         if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
66 77
     }
67 78
 }

+ 9
- 7
lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabOptionsPresenter.java Zobrazit soubor

@@ -39,13 +39,15 @@ public class BottomTabOptionsPresenter {
39 39
 
40 40
     public void present() {
41 41
         for (int i = 0; i < tabs.size(); i++) {
42
-            BottomTabOptions bottomTab = tabs.get(i).options.copy().withDefaultOptions(defaultOptions).bottomTabOptions;
43
-            bottomTabs.setBadge(i, bottomTab.badge.get(""));
44
-            bottomTabs.setTitleTypeface(i, bottomTab.fontFamily);
45
-            bottomTabs.setIconActiveColor(i, bottomTab.selectedIconColor.get(null));
46
-            bottomTabs.setIconInactiveColor(i, bottomTab.iconColor.get(null));
47
-            bottomTabs.setTitleActiveColor(i, bottomTab.selectedTextColor.get(null));
48
-            bottomTabs.setTitleInactiveColor(i, bottomTab.textColor.get(null));
42
+            BottomTabOptions tab = tabs.get(i).options.copy().withDefaultOptions(defaultOptions).bottomTabOptions;
43
+            bottomTabs.setBadge(i, tab.badge.get(""));
44
+            bottomTabs.setTitleTypeface(i, tab.fontFamily);
45
+            bottomTabs.setIconActiveColor(i, tab.selectedIconColor.get(null));
46
+            bottomTabs.setIconInactiveColor(i, tab.iconColor.get(null));
47
+            bottomTabs.setTitleActiveColor(i, tab.selectedTextColor.get(null));
48
+            bottomTabs.setTitleInactiveColor(i, tab.textColor.get(null));
49
+            bottomTabs.setTitleInactiveTextSizeInSp(i, tab.fontSize.hasValue() ? Float.valueOf(tab.fontSize.get()) : null);
50
+            bottomTabs.setTitleActiveTextSizeInSp(i, tab.selectedFontSize.hasValue() ? Float.valueOf(tab.selectedFontSize.get()) : null);
49 51
         }
50 52
     }
51 53