Browse Source

Set subtitle fontSize and fontFamily

Guy Carmeli 6 years ago
parent
commit
f4912d1758

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java View File

@@ -41,17 +41,17 @@ public class OptionsPresenter {
41 41
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
42 42
         if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
43 43
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
44
+        topBar.setTitleTypeface(options.title.fontFamily);
44 45
 
45 46
         if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
46 47
         if (options.subtitle.color.hasValue()) topBar.setSubtitleColor(options.subtitle.color.get());
47
-        if (options.subtitle.fontFamily != null) topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
48
-        if (options.subtitle.fontSize.hasValue()) topBar.setTitleFontSize(options.subtitle.fontSize.get());
48
+        if (options.subtitle.fontSize.hasValue()) topBar.setSubtitleFontSize(options.subtitle.fontSize.get());
49
+        topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
49 50
 
50 51
         topBar.setBackgroundColor(options.background.color);
51 52
         topBar.setBackgroundComponent(options.background.component);
52 53
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
53 54
 
54
-        topBar.setTitleTypeface(options.title.fontFamily);
55 55
         if (options.visible.isFalse()) {
56 56
             if (options.animate.isTrueOrUndefined()) {
57 57
                 topBar.hideAnimate(animationOptions.pop.topBar);

+ 11
- 3
lib/android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

@@ -41,13 +41,21 @@ public class ViewUtils {
41 41
     }
42 42
 
43 43
     public static <T> List<T> findChildrenByClass(ViewGroup root, Class clazz) {
44
+        return findChildrenByClass(root, clazz, child -> true);
45
+    }
46
+
47
+    public static <T> List<T> findChildrenByClass(ViewGroup root, Class clazz, Matcher<T> matcher) {
44 48
         List<T> ret = new ArrayList<>();
45 49
         for (int i = 0; i < root.getChildCount(); i++) {
46
-            View view = root.getChildAt(i);
47
-            if (clazz.isAssignableFrom(view.getClass())) {
48
-                ret.add((T) view);
50
+            View child = root.getChildAt(i);
51
+            if (clazz.isAssignableFrom(child.getClass()) && matcher.match((T) child)) {
52
+                ret.add((T) child);
49 53
             }
50 54
         }
51 55
         return ret;
52 56
     }
57
+
58
+    public interface Matcher<T> {
59
+        boolean match(T child);
60
+    }
53 61
 }

+ 17
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/titlebar/TitleBar.java View File

@@ -77,9 +77,25 @@ public class TitleBar extends Toolbar {
77 77
         if (titleTextView != null) titleTextView.setTypeface(typeface);
78 78
     }
79 79
 
80
+    public void setSubtitleTypeface(Typeface typeface) {
81
+        TextView subtitleTextView = findSubtitleTextView();
82
+        if (subtitleTextView != null) subtitleTextView.setTypeface(typeface);
83
+    }
84
+
85
+    public void setSubtitleFontSize(float size) {
86
+        TextView subtitleTextView = findSubtitleTextView();
87
+        if (subtitleTextView != null) subtitleTextView.setTextSize(size);
88
+    }
89
+
80 90
     @Nullable
81 91
     public TextView findTitleTextView() {
82
-        List<TextView> children = ViewUtils.findChildrenByClass(this, TextView.class);
92
+        List<TextView> children = ViewUtils.findChildrenByClass(this, TextView.class, textView -> textView.getText().equals(getTitle()));
93
+        return children.isEmpty() ? null : children.get(0);
94
+    }
95
+
96
+    @Nullable
97
+    public TextView findSubtitleTextView() {
98
+        List<TextView> children = ViewUtils.findChildrenByClass(this, TextView.class, textView -> textView.getText().equals(getSubtitle()));
83 99
         return children.isEmpty() ? null : children.get(0);
84 100
     }
85 101
 

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java View File

@@ -88,7 +88,11 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
88 88
     }
89 89
 
90 90
     public void setSubtitleFontFamily(Typeface fontFamily) {
91
+        titleBar.setSubtitleTypeface(fontFamily);
92
+    }
91 93
 
94
+    public void setSubtitleFontSize(float size) {
95
+        titleBar.setSubtitleFontSize(size);
92 96
     }
93 97
 
94 98
     public void setTestId(String testId) {