Bladeren bron

Set default title and subtitle font sizes

Pretty hacky but it will do for now
Guy Carmeli 6 jaren geleden
bovenliggende
commit
f36a8a44be

+ 7
- 4
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java Bestand weergeven

@@ -12,6 +12,7 @@ import com.reactnativenavigation.parse.TopBarOptions;
12 12
 import com.reactnativenavigation.parse.TopTabOptions;
13 13
 import com.reactnativenavigation.parse.TopTabsOptions;
14 14
 import com.reactnativenavigation.parse.params.Button;
15
+import com.reactnativenavigation.utils.UiUtils;
15 16
 import com.reactnativenavigation.viewcontrollers.IReactView;
16 17
 import com.reactnativenavigation.views.Component;
17 18
 import com.reactnativenavigation.views.topbar.TopBar;
@@ -21,6 +22,8 @@ import java.util.ArrayList;
21 22
 public class OptionsPresenter {
22 23
     private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
23 24
     private static final int DEFAULT_SUBTITLE_COLOR = Color.GRAY;
25
+    private static final float DEFAULT_TITLE_FONT_SIZE = UiUtils.dpToSp(18);
26
+    private static final float DEFAULT_SUBTITLE_FONT_SIZE = UiUtils.dpToSp(14);
24 27
 
25 28
     private TopBar topBar;
26 29
 
@@ -41,14 +44,14 @@ public class OptionsPresenter {
41 44
     }
42 45
 
43 46
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component) {
44
-        if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
47
+        topBar.setTitle(options.title.text.get(""));
45 48
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
46
-        if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
49
+        topBar.setTitleFontSize(options.title.fontSize.get(DEFAULT_TITLE_FONT_SIZE));
47 50
         topBar.setTitleTextColor(options.title.color.get(DEFAULT_TITLE_COLOR));
48 51
         topBar.setTitleTypeface(options.title.fontFamily);
49 52
 
50
-        if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
51
-        if (options.subtitle.fontSize.hasValue()) topBar.setSubtitleFontSize(options.subtitle.fontSize.get());
53
+        topBar.setSubtitle(options.subtitle.text.get(""));
54
+        topBar.setSubtitleFontSize(options.subtitle.fontSize.get(DEFAULT_SUBTITLE_FONT_SIZE));
52 55
         topBar.setSubtitleColor(options.subtitle.color.get(DEFAULT_SUBTITLE_COLOR));
53 56
         topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
54 57
 

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/UiUtils.java Bestand weergeven

@@ -64,4 +64,8 @@ public class UiUtils {
64 64
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
65 65
         return dp * scale + 0.5f;
66 66
     }
67
+
68
+    public static float dpToSp(float dp) {
69
+        return dpToPx(dp) / NavigationApplication.instance.getResources().getDisplayMetrics().density;
70
+    }
67 71
 }