diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java index 38159d97ea1..ccc4aa2724a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/BottomTabOptions.java @@ -1,7 +1,6 @@ package com.reactnativenavigation.options; import android.content.Context; -import android.graphics.Typeface; import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; @@ -13,6 +12,7 @@ import com.reactnativenavigation.options.params.Text; import com.reactnativenavigation.options.parsers.BoolParser; import com.reactnativenavigation.options.parsers.ColorParser; +import com.reactnativenavigation.options.parsers.FontParser; import com.reactnativenavigation.options.parsers.IconParser; import com.reactnativenavigation.options.parsers.NumberParser; import com.reactnativenavigation.options.parsers.TextParser; @@ -20,8 +20,6 @@ import org.json.JSONObject; -import androidx.annotation.Nullable; - public class BottomTabOptions { public static BottomTabOptions parse(Context context, TypefaceLoader typefaceManager, JSONObject json) { @@ -39,11 +37,7 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan options.badgeColor = ColorParser.parse(context, json, "badgeColor"); options.animateBadge = BoolParser.parse(json, "animateBadge"); options.testId = TextParser.parse(json, "testID"); - options.fontFamily = typefaceManager.getTypeFace( - json.optString("fontFamily", ""), - json.optString("fontStyle", ""), - json.optString("fontWeight", "") - ); + options.font = FontParser.parse(json); options.fontSize = NumberParser.parse(json, "fontSize"); options.selectedFontSize = NumberParser.parse(json, "selectedFontSize"); options.dotIndicator = DotIndicatorOptions.parse(context, json.optJSONObject("dotIndicator")); @@ -67,7 +61,7 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan public Number fontSize = new NullNumber(); public Number selectedFontSize = new NullNumber(); public Bool selectTabOnPress = new NullBool(); - @Nullable public Typeface fontFamily; + public FontOptions font = new FontOptions(); void mergeWith(final BottomTabOptions other) { @@ -84,7 +78,7 @@ void mergeWith(final BottomTabOptions other) { if (other.testId.hasValue()) testId = other.testId; if (other.fontSize.hasValue()) fontSize = other.fontSize; if (other.selectedFontSize.hasValue()) selectedFontSize = other.selectedFontSize; - if (other.fontFamily != null) fontFamily = other.fontFamily; + font.mergeWith(other.font); if (other.dotIndicator.hasValue()) dotIndicator = other.dotIndicator; if (other.selectTabOnPress.hasValue()) selectTabOnPress = other.selectTabOnPress; } @@ -102,7 +96,7 @@ void mergeWithDefault(final BottomTabOptions defaultOptions) { if (!animateBadge.hasValue()) animateBadge = defaultOptions.animateBadge; if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize; if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize; - if (fontFamily == null) fontFamily = defaultOptions.fontFamily; + font.mergeWithDefault(defaultOptions.font); if (!testId.hasValue()) testId = defaultOptions.testId; if (!dotIndicator.hasValue()) dotIndicator = defaultOptions.dotIndicator; if (!selectTabOnPress.hasValue()) selectTabOnPress = defaultOptions.selectTabOnPress; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java index e4a0e472624..daf17f95485 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/ButtonOptions.java @@ -1,7 +1,6 @@ package com.reactnativenavigation.options; import android.content.Context; -import android.graphics.Typeface; import android.view.MenuItem; import com.reactnativenavigation.options.params.Bool; @@ -16,11 +15,11 @@ import com.reactnativenavigation.options.params.Text; import com.reactnativenavigation.options.parsers.BoolParser; import com.reactnativenavigation.options.parsers.ColorParser; +import com.reactnativenavigation.options.parsers.FontParser; import com.reactnativenavigation.options.parsers.FractionParser; import com.reactnativenavigation.options.parsers.TextParser; import com.reactnativenavigation.utils.CompatUtils; import com.reactnativenavigation.utils.IdFactory; -import com.reactnativenavigation.options.parsers.TypefaceLoader; import org.json.JSONArray; import org.json.JSONObject; @@ -28,8 +27,6 @@ import java.util.ArrayList; import java.util.Objects; -import androidx.annotation.Nullable; - import static com.reactnativenavigation.utils.ObjectUtils.take; public class ButtonOptions { @@ -45,7 +42,7 @@ public class ButtonOptions { public Colour color = new NullColor(); public Colour disabledColor = new NullColor(); public Fraction fontSize = new NullFraction(); - @Nullable public Typeface fontFamily; + public FontOptions font = new FontOptions(); public Text icon = new NullText(); public Text testId = new NullText(); public ComponentOptions component = new ComponentOptions(); @@ -61,13 +58,13 @@ public boolean equals(ButtonOptions other) { color.equals(other.color) && disabledColor.equals(other.disabledColor) && fontSize.equals(other.fontSize) && - Objects.equals(fontFamily, other.fontFamily) && + font.equals(other.font) && icon.equals(other.icon) && testId.equals(other.testId) && component.equals(other.component); } - private static ButtonOptions parseJson(Context context, JSONObject json, TypefaceLoader typefaceManager) { + private static ButtonOptions parseJson(Context context, JSONObject json) { ButtonOptions button = new ButtonOptions(); button.id = take(json.optString("id"), "btn" + CompatUtils.generateViewId()); button.accessibilityLabel = TextParser.parse(json, "accessibilityLabel"); @@ -79,11 +76,7 @@ private static ButtonOptions parseJson(Context context, JSONObject json, Typefac button.color = ColorParser.parse(context, json, "color"); button.disabledColor = ColorParser.parse(context, json, "disabledColor"); button.fontSize = FractionParser.parse(json, "fontSize"); - button.fontFamily = typefaceManager.getTypeFace( - json.optString("fontFamily", ""), - json.optString("fontStyle", ""), - json.optString("fontWeight", "") - ); + button.font = FontParser.parse(json); button.testId = TextParser.parse(json, "testID"); button.component = ComponentOptions.parse(json.optJSONObject("component")); @@ -94,7 +87,7 @@ private static ButtonOptions parseJson(Context context, JSONObject json, Typefac return button; } - public static ArrayList parse(Context context, JSONObject json, String buttonsType, TypefaceLoader typefaceLoader) { + public static ArrayList parse(Context context, JSONObject json, String buttonsType) { ArrayList buttons = new ArrayList<>(); if (!json.has(buttonsType)) { return null; @@ -102,18 +95,18 @@ public static ArrayList parse(Context context, JSONObject json, S JSONArray jsonArray = json.optJSONArray(buttonsType); if (jsonArray != null) { - buttons.addAll(parseJsonArray(context, jsonArray, typefaceLoader)); + buttons.addAll(parseJsonArray(context, jsonArray)); } else { - buttons.add(parseJson(context, json.optJSONObject(buttonsType), typefaceLoader)); + buttons.add(parseJson(context, json.optJSONObject(buttonsType))); } return buttons; } - private static ArrayList parseJsonArray(Context context, JSONArray jsonArray, TypefaceLoader typefaceLoader) { + private static ArrayList parseJsonArray(Context context, JSONArray jsonArray) { ArrayList buttons = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.optJSONObject(i); - ButtonOptions button = ButtonOptions.parseJson(context, json, typefaceLoader); + ButtonOptions button = ButtonOptions.parseJson(context, json); buttons.add(button); } return buttons; @@ -165,7 +158,7 @@ public void mergeWith(ButtonOptions other) { if (other.color.hasValue()) color = other.color; if (other.disabledColor.hasValue()) disabledColor = other.disabledColor; if (other.fontSize.hasValue()) fontSize = other.fontSize; - if (other.fontFamily != null) fontFamily = other.fontFamily; + font.mergeWith(other.font); if (other.testId.hasValue()) testId = other.testId; if (other.component.hasValue()) component = other.component; if (other.showAsAction.hasValue()) showAsAction = other.showAsAction; @@ -183,7 +176,7 @@ public void mergeWithDefault(ButtonOptions defaultOptions) { if (!color.hasValue()) color = defaultOptions.color; if (!disabledColor.hasValue()) disabledColor = defaultOptions.disabledColor; if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize; - if (fontFamily == null) fontFamily = defaultOptions.fontFamily; + font.mergeWithDefault(defaultOptions.font); if (!testId.hasValue()) testId = defaultOptions.testId; if (!component.hasValue()) component = defaultOptions.component; if (!showAsAction.hasValue()) showAsAction = defaultOptions.showAsAction; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/FontOptions.kt b/lib/android/app/src/main/java/com/reactnativenavigation/options/FontOptions.kt new file mode 100644 index 00000000000..0548e3dc910 --- /dev/null +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/FontOptions.kt @@ -0,0 +1,55 @@ +package com.reactnativenavigation.options + +import android.graphics.Typeface +import com.reactnativenavigation.options.params.NullText +import com.reactnativenavigation.options.params.Text +import com.reactnativenavigation.options.parsers.TypefaceLoader + +class FontOptions { + private var isDirty = false + var fontFamily: Text = NullText() + set(value) { + field = value + isDirty = true + } + var fontStyle: Text = NullText() + set(value) { + field = value + isDirty = true + } + var fontWeight: Text = NullText() + set(value) { + field = value + isDirty = true + } + private var _typeface: Typeface? = null + + @JvmOverloads fun getTypeface(typefaceLoader: TypefaceLoader, defaultTypeface: Typeface? = null): Typeface? { + if (isDirty) { + _typeface = typefaceLoader.getTypeFace(fontFamily.get(""), fontStyle.get(""), fontWeight.get("")) + isDirty = false + } + return _typeface + ?: defaultTypeface?.let { typefaceLoader.getTypeFace(fontFamily.get(""), fontStyle.get(""), fontWeight.get(""), it) } + } + + fun mergeWith(other: FontOptions) { + if (other.fontFamily.hasValue()) fontFamily = other.fontFamily + if (other.fontStyle.hasValue()) fontStyle = other.fontStyle + if (other.fontWeight.hasValue()) fontWeight = other.fontWeight + } + + fun mergeWithDefault(defaultOptions: FontOptions) { + if (!fontFamily.hasValue()) fontFamily = defaultOptions.fontFamily + if (!fontStyle.hasValue()) fontStyle = defaultOptions.fontStyle + if (!fontWeight.hasValue()) fontWeight = defaultOptions.fontWeight + } + + fun hasValue() = fontFamily.hasValue() || fontStyle.hasValue() || fontWeight.hasValue() + + override fun equals(other: Any?) = (other as? FontOptions)?.let { + fontFamily.equals(other.fontFamily) && + fontStyle.equals(other.fontStyle) && + fontWeight.equals(other.fontWeight) + } ?: false +} \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java index 7678f0f153a..f4d5b66c995 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/LayoutFactory.java @@ -192,6 +192,7 @@ private ViewController createStack(ReactContext context, LayoutNode node) { new TopBarBackgroundViewCreator(reactInstanceManager), new TitleBarButtonCreator(reactInstanceManager), new IconResolver(activity, new ImageLoader()), + new TypefaceLoader(activity), new RenderChecker(), defaultOptions )) @@ -223,7 +224,7 @@ private ViewController createBottomTabs(ReactContext context, LayoutNode node) { new Presenter(activity, defaultOptions), new BottomTabsAttacher(tabs, bottomTabsPresenter, defaultOptions), bottomTabsPresenter, - new BottomTabPresenter(activity, tabs, new ImageLoader(), defaultOptions)); + new BottomTabPresenter(activity, tabs, new ImageLoader(), new TypefaceLoader(activity), defaultOptions)); } private ViewController createTopTabs(ReactContext context, LayoutNode node) { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java index 9ca19374cbc..b6143e719a9 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/SubtitleOptions.java @@ -1,8 +1,6 @@ package com.reactnativenavigation.options; import android.content.Context; -import android.graphics.Typeface; -import androidx.annotation.Nullable; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.Fraction; @@ -11,6 +9,7 @@ import com.reactnativenavigation.options.params.NullText; import com.reactnativenavigation.options.params.Text; import com.reactnativenavigation.options.parsers.ColorParser; +import com.reactnativenavigation.options.parsers.FontParser; import com.reactnativenavigation.options.parsers.FractionParser; import com.reactnativenavigation.options.parsers.TextParser; import com.reactnativenavigation.options.parsers.TypefaceLoader; @@ -27,11 +26,7 @@ public static SubtitleOptions parse(Context context, TypefaceLoader typefaceMana options.text = TextParser.parse(json, "text"); options.color = ColorParser.parse(context, json, "color"); options.fontSize = FractionParser.parse(json, "fontSize"); - options.fontFamily = typefaceManager.getTypeFace( - json.optString("fontFamily", ""), - json.optString("fontStyle", ""), - json.optString("fontWeight", "") - ); + options.font = FontParser.parse(json); options.alignment = Alignment.fromString(TextParser.parse(json, "alignment").get("")); return options; @@ -40,14 +35,14 @@ public static SubtitleOptions parse(Context context, TypefaceLoader typefaceMana public Text text = new NullText(); public Colour color = new NullColor(); public Fraction fontSize = new NullFraction(); - @Nullable public Typeface fontFamily; + public FontOptions font = new FontOptions(); public Alignment alignment = Alignment.Default; void mergeWith(final SubtitleOptions other) { if (other.text.hasValue()) text = other.text; if (other.color.hasValue()) color = other.color; if (other.fontSize.hasValue()) fontSize = other.fontSize; - if (other.fontFamily != null) fontFamily = other.fontFamily; + font.mergeWith(other.font); if (other.alignment != Alignment.Default) alignment = other.alignment; } @@ -55,7 +50,7 @@ void mergeWithDefault(SubtitleOptions defaultOptions) { if (!text.hasValue()) text = defaultOptions.text; if (!color.hasValue()) color = defaultOptions.color; if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize; - if (fontFamily == null) fontFamily = defaultOptions.fontFamily; + font.mergeWithDefault(defaultOptions.font); if (alignment == Alignment.Default) alignment = defaultOptions.alignment; } } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java index 649a80a9393..5f9736d7efb 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TitleOptions.java @@ -1,8 +1,6 @@ package com.reactnativenavigation.options; import android.content.Context; -import android.graphics.Typeface; -import androidx.annotation.Nullable; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.Fraction; @@ -13,6 +11,7 @@ import com.reactnativenavigation.options.params.Number; import com.reactnativenavigation.options.params.Text; import com.reactnativenavigation.options.parsers.ColorParser; +import com.reactnativenavigation.options.parsers.FontParser; import com.reactnativenavigation.options.parsers.FractionParser; import com.reactnativenavigation.options.parsers.NumberParser; import com.reactnativenavigation.options.parsers.TextParser; @@ -30,11 +29,7 @@ public static TitleOptions parse(Context context, TypefaceLoader typefaceManager options.text = TextParser.parse(json, "text"); options.color = ColorParser.parse(context, json, "color"); options.fontSize = FractionParser.parse(json, "fontSize"); - options.fontFamily = typefaceManager.getTypeFace( - json.optString("fontFamily", ""), - json.optString("fontStyle", ""), - json.optString("fontWeight", "") - ); + options.font = FontParser.parse(json); options.alignment = Alignment.fromString(TextParser.parse(json, "alignment").get("")); options.height = NumberParser.parse(json, "height"); options.topMargin = NumberParser.parse(json, "topMargin"); @@ -46,7 +41,7 @@ public static TitleOptions parse(Context context, TypefaceLoader typefaceManager public Colour color = new NullColor(); public Fraction fontSize = new NullFraction(); public Alignment alignment = Alignment.Default; - @Nullable public Typeface fontFamily; + public FontOptions font = new FontOptions(); public ComponentOptions component = new ComponentOptions(); public Number height = new NullNumber(); public Number topMargin = new NullNumber(); @@ -55,7 +50,7 @@ void mergeWith(final TitleOptions other) { if (other.text.hasValue()) text = other.text; if (other.color.hasValue()) color = other.color; if (other.fontSize.hasValue()) fontSize = other.fontSize; - if (other.fontFamily != null) fontFamily = other.fontFamily; + font.mergeWith(other.font); if (other.alignment != Alignment.Default) alignment = other.alignment; if (other.component.hasValue()) component = other.component; if (other.height.hasValue()) height = other.height; @@ -66,7 +61,7 @@ void mergeWithDefault(TitleOptions defaultOptions) { if (!text.hasValue()) text = defaultOptions.text; if (!color.hasValue()) color = defaultOptions.color; if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize; - if (fontFamily == null) fontFamily = defaultOptions.fontFamily; + font.mergeWithDefault(defaultOptions.font); if (alignment == Alignment.Default) alignment = defaultOptions.alignment; component.mergeWithDefault(defaultOptions.component); if (!height.hasValue()) height = defaultOptions.height; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java index 4b17bd3ec34..08e2ab75439 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/TopBarButtons.java @@ -2,15 +2,15 @@ import android.content.Context; -import androidx.annotation.Nullable; - -import com.reactnativenavigation.utils.CollectionUtils; import com.reactnativenavigation.options.parsers.TypefaceLoader; +import com.reactnativenavigation.utils.CollectionUtils; import org.json.JSONObject; import java.util.ArrayList; +import androidx.annotation.Nullable; + public class TopBarButtons { public static TopBarButtons parse(Context context, TypefaceLoader typefaceLoader, JSONObject json) { @@ -26,7 +26,7 @@ public static TopBarButtons parse(Context context, TypefaceLoader typefaceLoader @Nullable private static ArrayList parseButtons(Context context, TypefaceLoader typefaceLoader, JSONObject json, String buttons) { - return ButtonOptions.parse(context, json, buttons, typefaceLoader); + return ButtonOptions.parse(context, json, buttons); } public BackButton back = new BackButton(); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/FontParser.kt b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/FontParser.kt new file mode 100644 index 00000000000..2bde41f2862 --- /dev/null +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/FontParser.kt @@ -0,0 +1,17 @@ +package com.reactnativenavigation.options.parsers + +import com.reactnativenavigation.options.FontOptions +import org.json.JSONObject + +class FontParser { + companion object { + @JvmStatic + fun parse(title: JSONObject): FontOptions { + return FontOptions().apply { + fontFamily = TextParser.parse(title, "fontFamily") + fontStyle = TextParser.parse(title, "fontStyle") + fontWeight = TextParser.parse(title, "fontWeight") + } + } + } +} \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/TypefaceLoader.java b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/TypefaceLoader.java deleted file mode 100644 index e8befd604e6..00000000000 --- a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/TypefaceLoader.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.reactnativenavigation.options.parsers; - -import android.content.Context; -import android.content.res.AssetManager; -import android.graphics.Typeface; -import android.text.TextUtils; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import androidx.annotation.Nullable; - -import com.facebook.react.views.text.ReactTypefaceUtils; - -public class TypefaceLoader { - - private Context context; - - public TypefaceLoader(Context context) { - this.context = context; - } - - @Nullable - public Typeface getTypeFace(String fontFamilyName, String fontStyle, String fontWeight) { - if (TextUtils.isEmpty(fontFamilyName)) return null; - return ReactTypefaceUtils.applyStyles( - null, - ReactTypefaceUtils.parseFontStyle(fontStyle), - ReactTypefaceUtils.parseFontWeight(fontWeight), - fontFamilyName, - context.getAssets() - ); - } - -} - diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/TypefaceLoader.kt b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/TypefaceLoader.kt new file mode 100644 index 00000000000..e147c62bb3d --- /dev/null +++ b/lib/android/app/src/main/java/com/reactnativenavigation/options/parsers/TypefaceLoader.kt @@ -0,0 +1,23 @@ +package com.reactnativenavigation.options.parsers + +import android.content.Context +import android.graphics.Typeface +import android.text.TextUtils +import com.facebook.react.views.text.ReactTypefaceUtils + +open class TypefaceLoader(private val context: Context) { + @JvmOverloads open fun getTypeFace( + fontFamilyName: String?, + fontStyle: String?, + fontWeight: String?, + defaultTypeFace: Typeface? = null + ): Typeface? { + return ReactTypefaceUtils.applyStyles( + defaultTypeFace, + ReactTypefaceUtils.parseFontStyle(fontStyle), + ReactTypefaceUtils.parseFontWeight(fontWeight), + fontFamilyName, + context.assets + ) + } +} \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenter.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenter.java index 25663dee12d..a639c021f20 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenter.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenter.java @@ -1,6 +1,7 @@ package com.reactnativenavigation.viewcontrollers.bottomtabs; import android.content.Context; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import com.aurelhubert.ahbottomnavigation.notification.AHNotification; @@ -8,6 +9,7 @@ import com.reactnativenavigation.options.DotIndicatorOptions; import com.reactnativenavigation.options.Options; import com.reactnativenavigation.options.params.Param; +import com.reactnativenavigation.options.parsers.TypefaceLoader; import com.reactnativenavigation.utils.ImageLoader; import com.reactnativenavigation.utils.ImageLoadingListenerAdapter; import com.reactnativenavigation.utils.LateInit; @@ -24,17 +26,19 @@ public class BottomTabPresenter { private final Context context; private ImageLoader imageLoader; + private TypefaceLoader typefaceLoader; private Options defaultOptions; private final BottomTabFinder bottomTabFinder; private LateInit bottomTabs = new LateInit<>(); private final List tabs; private final int defaultDotIndicatorSize; - public BottomTabPresenter(Context context, List tabs, ImageLoader imageLoader, Options defaultOptions) { + public BottomTabPresenter(Context context, List tabs, ImageLoader imageLoader, TypefaceLoader typefaceLoader, Options defaultOptions) { this.tabs = tabs; this.context = context; this.bottomTabFinder = new BottomTabFinder(tabs); this.imageLoader = imageLoader; + this.typefaceLoader = typefaceLoader; this.defaultOptions = defaultOptions; defaultDotIndicatorSize = dpToPx(context, 6); } @@ -51,7 +55,7 @@ public void applyOptions() { bottomTabs.perform(bottomTabs -> { for (int i = 0; i < tabs.size(); i++) { BottomTabOptions tab = tabs.get(i).resolveCurrentOptions(defaultOptions).bottomTabOptions; - bottomTabs.setTitleTypeface(i, tab.fontFamily); + bottomTabs.setTitleTypeface(i, tab.font.getTypeface(typefaceLoader, Typeface.DEFAULT)); if (tab.selectedIconColor.canApplyValue()) bottomTabs.setIconActiveColor(i, tab.selectedIconColor.get(null)); if (tab.iconColor.canApplyValue()) bottomTabs.setIconInactiveColor(i, tab.iconColor.get(null)); bottomTabs.setTitleActiveColor(i, tab.selectedTextColor.get(null)); @@ -77,7 +81,7 @@ public void mergeChildOptions(Options options, ViewController child) { int index = bottomTabFinder.findByControllerId(child.getId()); if (index >= 0) { BottomTabOptions tab = options.bottomTabOptions; - if (tab.fontFamily != null) bottomTabs.setTitleTypeface(index, tab.fontFamily); + if (tab.font.hasValue()) bottomTabs.setTitleTypeface(index, tab.font.getTypeface(typefaceLoader, Typeface.DEFAULT)); if (canMerge(tab.selectedIconColor)) bottomTabs.setIconActiveColor(index, tab.selectedIconColor.get()); if (canMerge(tab.iconColor)) bottomTabs.setIconInactiveColor(index, tab.iconColor.get()); if (tab.selectedTextColor.hasValue()) bottomTabs.setTitleActiveColor(index, tab.selectedTextColor.get()); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java index d215c3341ce..646842d4b13 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java @@ -20,6 +20,7 @@ import com.reactnativenavigation.options.TopTabsOptions; import com.reactnativenavigation.options.ButtonOptions; import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.parsers.TypefaceLoader; import com.reactnativenavigation.viewcontrollers.stack.topbar.button.ButtonPresenter; import com.reactnativenavigation.utils.RenderChecker; import com.reactnativenavigation.utils.CollectionUtils; @@ -78,12 +79,14 @@ public class StackPresenter { private Map> componentRightButtons = new HashMap(); private Map> componentLeftButtons = new HashMap(); private IconResolver iconResolver; + private TypefaceLoader typefaceLoader; public StackPresenter(Activity activity, TitleBarReactViewCreator titleViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TitleBarButtonCreator buttonCreator, IconResolver iconResolver, + TypefaceLoader typefaceLoader, RenderChecker renderChecker, Options defaultOptions) { this.activity = activity; @@ -91,6 +94,7 @@ public StackPresenter(Activity activity, this.topBarBackgroundViewCreator = topBarBackgroundViewCreator; this.buttonCreator = buttonCreator; this.iconResolver = iconResolver; + this.typefaceLoader = typefaceLoader; this.renderChecker = renderChecker; this.defaultOptions = defaultOptions; defaultTitleFontSize = 18; @@ -192,13 +196,13 @@ private void applyTopBarOptions(Options options, StackController stack, ViewCont topBar.setTitleFontSize(topBarOptions.title.fontSize.get(defaultTitleFontSize)); topBar.setTitleTextColor(topBarOptions.title.color.get(DEFAULT_TITLE_COLOR)); - topBar.setTitleTypeface(topBarOptions.title.fontFamily); + topBar.setTitleTypeface(typefaceLoader, topBarOptions.title.font); topBar.setTitleAlignment(topBarOptions.title.alignment); topBar.setSubtitle(topBarOptions.subtitle.text.get("")); topBar.setSubtitleFontSize(topBarOptions.subtitle.fontSize.get(defaultSubtitleFontSize)); topBar.setSubtitleColor(topBarOptions.subtitle.color.get(DEFAULT_SUBTITLE_COLOR)); - topBar.setSubtitleFontFamily(topBarOptions.subtitle.fontFamily); + topBar.setSubtitleTypeface(typefaceLoader, topBarOptions.subtitle.font); topBar.setSubtitleAlignment(topBarOptions.subtitle.alignment); topBar.setBorderHeight(topBarOptions.borderHeight.get(0d)); @@ -439,12 +443,12 @@ private void mergeTopBarOptions(Options options, StackController stack, ViewCont if (topBarOptions.title.color.hasValue()) topBar.setTitleTextColor(topBarOptions.title.color.get()); if (topBarOptions.title.fontSize.hasValue()) topBar.setTitleFontSize(topBarOptions.title.fontSize.get()); - if (topBarOptions.title.fontFamily != null) topBar.setTitleTypeface(topBarOptions.title.fontFamily); + if (topBarOptions.title.font.hasValue()) topBar.setTitleTypeface(typefaceLoader, topBarOptions.title.font); if (topBarOptions.subtitle.text.hasValue()) topBar.setSubtitle(topBarOptions.subtitle.text.get()); if (topBarOptions.subtitle.color.hasValue()) topBar.setSubtitleColor(topBarOptions.subtitle.color.get()); if (topBarOptions.subtitle.fontSize.hasValue()) topBar.setSubtitleFontSize(topBarOptions.subtitle.fontSize.get()); - if (topBarOptions.subtitle.fontFamily != null) topBar.setSubtitleFontFamily(topBarOptions.subtitle.fontFamily); + if (topBarOptions.subtitle.font.hasValue()) topBar.setSubtitleTypeface(typefaceLoader, topBarOptions.subtitle.font); if (topBarOptions.background.color.hasValue()) topBar.setBackgroundColor(topBarOptions.background.color.get()); diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt index dd83fc949d8..edbce88fd3a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonController.kt @@ -19,6 +19,7 @@ class ButtonController(activity: Activity, val button: ButtonOptions, private val viewCreator: TitleBarButtonCreator, private val onPressListener: OnClickListener) : ViewController(activity, button.id, YellowBoxDelegate(activity), Options(), ViewControllerOverlay(activity)), MenuItem.OnMenuItemClickListener { + private var menuItem: MenuItem? = null interface OnClickListener { @@ -83,5 +84,10 @@ class ButtonController(activity: Activity, } } - fun createAndAddButtonToTitleBar(titleBar: TitleBar, order: Int): MenuItem = titleBar.menu.add(Menu.NONE, button.intId, order, presenter.styledText) + fun createAndAddButtonToTitleBar(titleBar: TitleBar, order: Int): MenuItem = titleBar.menu.add( + Menu.NONE, + button.intId, + order, + presenter.styledText + ) } \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonSpan.kt b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonSpan.kt index 1449390382f..b1e6cda7374 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonSpan.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonSpan.kt @@ -7,20 +7,26 @@ import android.graphics.Typeface import android.text.TextPaint import android.text.style.MetricAffectingSpan import com.reactnativenavigation.options.ButtonOptions +import com.reactnativenavigation.options.parsers.TypefaceLoader import com.reactnativenavigation.utils.UiUtils -class ButtonSpan(private val context: Context, private val button: ButtonOptions) : MetricAffectingSpan() { +class ButtonSpan( + private val context: Context, + private val button: ButtonOptions, + private val typefaceLoader: TypefaceLoader = TypefaceLoader(context) +) : MetricAffectingSpan() { override fun updateDrawState(drawState: TextPaint) = apply(drawState) override fun updateMeasureState(paint: TextPaint) = apply(paint) fun apply(paint: Paint) { - with(button) { - val fakeStyle = (paint.typeface?.style ?: 0) and (fontFamily?.style?.inv() ?: 1) + with(button.font) { + val typeface = getTypeface(typefaceLoader, Typeface.DEFAULT) + val fakeStyle = (paint.typeface?.style ?: 0) and (typeface?.style?.inv() ?: 1) if (fakeStyle and Typeface.BOLD != 0) paint.isFakeBoldText = true if (fakeStyle and Typeface.ITALIC != 0) paint.textSkewX = -0.25f - if (fontSize.hasValue()) paint.textSize = UiUtils.dpToPx(context, fontSize.get().toFloat()) - paint.typeface = fontFamily + if (button.fontSize.hasValue()) paint.textSize = UiUtils.dpToPx(context, button.fontSize.get().toFloat()) + paint.typeface = typeface } } } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/TopBar.java b/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/TopBar.java index 94bde99efa7..5da767e9498 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/TopBar.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/TopBar.java @@ -15,6 +15,8 @@ import com.google.android.material.appbar.AppBarLayout; import com.reactnativenavigation.R; +import com.reactnativenavigation.options.FontOptions; +import com.reactnativenavigation.options.parsers.TypefaceLoader; import com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarCollapseBehavior; import com.reactnativenavigation.viewcontrollers.viewcontroller.ScrollEventListener; import com.reactnativenavigation.options.Alignment; @@ -141,8 +143,8 @@ public void setSubtitleColor(@ColorInt int color) { titleBar.setSubtitleTextColor(color); } - public void setSubtitleFontFamily(Typeface fontFamily) { - titleBar.setSubtitleTypeface(fontFamily); + public void setSubtitleTypeface(TypefaceLoader typefaceLoader, FontOptions font) { + titleBar.setSubtitleTypeface(typefaceLoader, font); } public void setSubtitleFontSize(double size) { @@ -165,8 +167,8 @@ public void setTitleFontSize(double size) { titleBar.setTitleFontSize(size); } - public void setTitleTypeface(Typeface typeface) { - titleBar.setTitleTypeface(typeface); + public void setTitleTypeface(TypefaceLoader typefaceLoader, FontOptions font) { + titleBar.setTitleTypeface(typefaceLoader, font); } public void setTitleAlignment(Alignment alignment) { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/titlebar/TitleBar.java b/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/titlebar/TitleBar.java index 2d0dee0f74c..c813925f0ae 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/titlebar/TitleBar.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/views/stack/topbar/titlebar/TitleBar.java @@ -4,7 +4,6 @@ import android.content.Context; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; -import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.util.Log; import android.util.TypedValue; @@ -14,7 +13,9 @@ import android.widget.TextView; import com.reactnativenavigation.options.Alignment; +import com.reactnativenavigation.options.FontOptions; import com.reactnativenavigation.options.params.Colour; +import com.reactnativenavigation.options.parsers.TypefaceLoader; import com.reactnativenavigation.utils.StringUtils; import com.reactnativenavigation.utils.UiUtils; import com.reactnativenavigation.utils.ViewUtils; @@ -105,18 +106,18 @@ public void setTitleFontSize(double size) { if (titleTextView != null) titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, (float) size); } - public void setTitleTypeface(Typeface typeface) { + public void setTitleTypeface(TypefaceLoader typefaceLoader, FontOptions font) { TextView titleTextView = findTitleTextView(); - if (titleTextView != null) titleTextView.setTypeface(typeface); + if (titleTextView != null) titleTextView.setTypeface(font.getTypeface(typefaceLoader, titleTextView.getTypeface())); } public void setTitleAlignment(Alignment alignment) { titleAlignment = alignment; } - public void setSubtitleTypeface(Typeface typeface) { + public void setSubtitleTypeface(TypefaceLoader typefaceLoader, FontOptions font) { TextView subtitleTextView = findSubtitleTextView(); - if (subtitleTextView != null) subtitleTextView.setTypeface(typeface); + if (subtitleTextView != null) subtitleTextView.setTypeface(font.getTypeface(typefaceLoader, subtitleTextView.getTypeface())); } public void setSubtitleFontSize(double size) { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java b/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java index 7241703566a..700bbc05e1a 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java @@ -8,6 +8,7 @@ import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock; import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock; import com.reactnativenavigation.mocks.TitleBarButtonCreatorMock; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.Options; import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.utils.RenderChecker; @@ -40,7 +41,7 @@ protected TopBar createTopBar(Context context, StackLayout stackLayout) { .setId("stack" + CompatUtils.generateViewId()) .setChildRegistry(new ChildControllersRegistry()) .setTopBarController(topBarController) - .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TitleBarButtonCreatorMock(), new IconResolver(activity, new ImageLoader()), new RenderChecker(), new Options())) + .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TitleBarButtonCreatorMock(), new IconResolver(activity, new ImageLoader()), new TypefaceLoaderMock(), new RenderChecker(), new Options())) .setInitialOptions(new Options()); } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TypefaceLoaderMock.java b/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TypefaceLoaderMock.java index 65bfb57c7d9..9afb3fdeb61 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TypefaceLoaderMock.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/mocks/TypefaceLoaderMock.java @@ -1,10 +1,14 @@ package com.reactnativenavigation.mocks; +import android.content.Context; + import com.reactnativenavigation.options.parsers.TypefaceLoader; +import org.mockito.Mockito; + public class TypefaceLoaderMock extends TypefaceLoader { public TypefaceLoaderMock() { - super(null); + super(Mockito.mock(Context.class)); } } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java index 14dd37fe68f..655b2a90614 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/options/OptionsTest.java @@ -2,10 +2,8 @@ import android.graphics.Color; import android.graphics.Typeface; -import androidx.annotation.NonNull; import com.reactnativenavigation.BaseTest; -import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.NullText; @@ -19,6 +17,8 @@ import org.mockito.Mockito; import org.mockito.stubbing.Answer; +import androidx.annotation.NonNull; + import static org.assertj.core.api.Java6Assertions.assertThat; import static org.mockito.Mockito.when; @@ -57,11 +57,11 @@ public class OptionsTest extends BaseTest { @Override public void beforeEach() { - mockLoader = Mockito.mock(TypefaceLoaderMock.class); - when(mockLoader.getTypeFace("HelveticaNeue-Condensed", null, null)).then((Answer) invocation -> SUBTITLE_TYPEFACE); - when(mockLoader.getTypeFace("HelveticaNeue-CondensedBold", null, null)).then((Answer) invocation -> TOP_BAR_TYPEFACE); - Mockito.doReturn(TOP_BAR_TYPEFACE).when(mockLoader).getTypeFace(TOP_BAR_FONT_FAMILY, "", ""); - Mockito.doReturn(SUBTITLE_TYPEFACE).when(mockLoader).getTypeFace(SUBTITLE_FONT_FAMILY, "", ""); + mockLoader = Mockito.mock(TypefaceLoader.class); + when(mockLoader.getTypeFace("HelveticaNeue-Condensed", null, null, null)).then((Answer) invocation -> SUBTITLE_TYPEFACE); + when(mockLoader.getTypeFace("HelveticaNeue-CondensedBold", null, null, null)).then((Answer) invocation -> TOP_BAR_TYPEFACE); + Mockito.doReturn(TOP_BAR_TYPEFACE).when(mockLoader).getTypeFace(TOP_BAR_FONT_FAMILY, "", "", null); + Mockito.doReturn(SUBTITLE_TYPEFACE).when(mockLoader).getTypeFace(SUBTITLE_FONT_FAMILY, "", "", null); } @Test @@ -88,11 +88,11 @@ private void assertResult(Options result) { assertThat(result.topBar.title.height.get()).isEqualTo(TITLE_HEIGHT.get()); assertThat(result.topBar.title.color.get()).isEqualTo(TOP_BAR_TEXT_COLOR); assertThat(result.topBar.title.fontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE); - assertThat(result.topBar.title.fontFamily).isEqualTo(TOP_BAR_TYPEFACE); + assertThat(result.topBar.title.font.getTypeface(mockLoader)).isEqualTo(TOP_BAR_TYPEFACE); assertThat(result.topBar.subtitle.color.get()).isEqualTo(SUBTITLE_TEXT_COLOR); assertThat(result.topBar.subtitle.fontSize.get()).isEqualTo(SUBTITLE_FONT_SIZE); assertThat(result.topBar.subtitle.alignment).isEqualTo(Alignment.fromString(SUBTITLE_ALIGNMENT)); - assertThat(result.topBar.subtitle.fontFamily).isEqualTo(SUBTITLE_TYPEFACE); + assertThat(result.topBar.subtitle.font.getTypeface(mockLoader)).isEqualTo(SUBTITLE_TYPEFACE); assertThat(result.topBar.visible.get()).isEqualTo(TOP_BAR_VISIBLE.get()); assertThat(result.topBar.drawBehind.get()).isEqualTo(TOP_BAR_DRAW_BEHIND.get()); assertThat(result.topBar.hideOnScroll.get()).isEqualTo(TOP_BAR_HIDE_ON_SCROLL.get()); diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonSpanTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonSpanTest.java index 0e7e6aa95fa..bb2d979b65b 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonSpanTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonSpanTest.java @@ -5,6 +5,7 @@ import android.graphics.Paint; import com.reactnativenavigation.BaseTest; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.ButtonOptions; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.Fraction; @@ -26,7 +27,7 @@ public class ButtonSpanTest extends BaseTest { public void beforeEach() { button = createButton(); activity = newActivity(); - uut = new ButtonSpan(activity, button); + uut = new ButtonSpan(activity, button, new TypefaceLoaderMock()); } @Test diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenterTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenterTest.java index f4bac8aae58..3466ea98c8b 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenterTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabPresenterTest.java @@ -7,6 +7,7 @@ import com.reactnativenavigation.BaseTest; import com.reactnativenavigation.mocks.ImageLoaderMock; import com.reactnativenavigation.mocks.SimpleViewController; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.Options; import com.reactnativenavigation.options.params.Colour; import com.reactnativenavigation.options.params.DontApplyColour; @@ -51,7 +52,7 @@ public void beforeEach() { child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tab2Options)); child3 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options())); tabs = Arrays.asList(child1, child2, child3); - uut = new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options()); + uut = new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new TypefaceLoaderMock(), new Options()); uut.bindView(bottomTabs); uut.setDefaultOptions(new Options()); } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java index f7c0944c3bc..5247f5fc735 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java @@ -11,6 +11,7 @@ import com.reactnativenavigation.TestUtils; import com.reactnativenavigation.mocks.ImageLoaderMock; import com.reactnativenavigation.mocks.SimpleViewController; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.Options; import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Colour; @@ -283,7 +284,7 @@ public void applyChildOptions_resolvedOptionsAreUsed() { new Presenter(activity , new Options()), tabsAttacher, presenter, - new BottomTabPresenter(activity , tabs, ImageLoaderMock.mock(), new Options())) { + new BottomTabPresenter(activity , tabs, ImageLoaderMock.mock(), new TypefaceLoaderMock(), new Options())) { @Override public Options resolveCurrentOptions() { return resolvedOptions; @@ -409,7 +410,7 @@ public void superCreateItems() { createChildren(); tabs = Arrays.asList(child1, child2, child3, child4, child5); presenter = spy(new BottomTabsPresenter(tabs, Options.EMPTY)); - bottomTabPresenter = spy(new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), Options.EMPTY)); + bottomTabPresenter = spy(new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new TypefaceLoaderMock(), Options.EMPTY)); tabsAttacher = spy(new BottomTabsAttacher(tabs, presenter, Options.EMPTY)); uut = createBottomTabs(); diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java index 123343cc0a4..d8d622d5a9b 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java @@ -12,28 +12,29 @@ import com.reactnativenavigation.mocks.ImageLoaderMock; import com.reactnativenavigation.mocks.SimpleComponentViewController; import com.reactnativenavigation.mocks.SimpleViewController; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.Options; import com.reactnativenavigation.options.params.Bool; import com.reactnativenavigation.options.params.Text; -import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabPresenter; -import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter; -import com.reactnativenavigation.viewcontrollers.overlay.OverlayManager; -import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter; -import com.reactnativenavigation.viewcontrollers.viewcontroller.RootPresenter; -import com.reactnativenavigation.react.events.EventEmitter; import com.reactnativenavigation.react.CommandListener; import com.reactnativenavigation.react.CommandListenerAdapter; +import com.reactnativenavigation.react.events.EventEmitter; import com.reactnativenavigation.utils.CompatUtils; import com.reactnativenavigation.utils.ImageLoader; import com.reactnativenavigation.utils.OptionHelper; import com.reactnativenavigation.utils.ViewUtils; +import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabPresenter; +import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController; +import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter; +import com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.BottomTabsAttacher; import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry; import com.reactnativenavigation.viewcontrollers.component.ComponentViewController; -import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController; -import com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.BottomTabsAttacher; -import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController; import com.reactnativenavigation.viewcontrollers.modal.ModalStack; +import com.reactnativenavigation.viewcontrollers.overlay.OverlayManager; import com.reactnativenavigation.viewcontrollers.stack.StackController; +import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter; +import com.reactnativenavigation.viewcontrollers.viewcontroller.RootPresenter; +import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController; import com.reactnativenavigation.views.bottomtabs.BottomTabs; import org.junit.Test; @@ -389,7 +390,7 @@ public void mergeOptions_AffectsOnlyComponentViewControllers() { @NonNull private BottomTabsController newTabs(List tabs) { BottomTabsPresenter bottomTabsPresenter = new BottomTabsPresenter(tabs, new Options()); - return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options(), new Presenter(activity, new Options()), new BottomTabsAttacher(tabs, bottomTabsPresenter, Options.EMPTY), bottomTabsPresenter, new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options())) { + return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options(), new Presenter(activity, new Options()), new BottomTabsAttacher(tabs, bottomTabsPresenter, Options.EMPTY), bottomTabsPresenter, new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new TypefaceLoaderMock(), new Options())) { @NonNull @Override protected BottomTabs createBottomTabs() { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java index 471e5b2f4b6..ad929e4576a 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java @@ -14,6 +14,7 @@ import com.reactnativenavigation.mocks.TitleBarButtonCreatorMock; import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock; import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.AnimationOptions; import com.reactnativenavigation.options.NestedAnimationsOptions; import com.reactnativenavigation.options.Options; @@ -104,6 +105,7 @@ public void beforeEach() { new TopBarBackgroundViewCreatorMock(), new TitleBarButtonCreatorMock(), new IconResolver(activity, ImageLoaderMock.mock()), + new TypefaceLoaderMock(), new RenderChecker(), new Options() ) diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenterTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenterTest.java index 3ca0ba45d59..3768f836489 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenterTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenterTest.java @@ -3,7 +3,6 @@ import android.app.Activity; import android.content.Context; import android.graphics.Color; -import android.graphics.Typeface; import android.view.Gravity; import android.view.View; @@ -16,9 +15,11 @@ import com.reactnativenavigation.mocks.TitleBarButtonCreatorMock; import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock; import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock; +import com.reactnativenavigation.mocks.TypefaceLoaderMock; import com.reactnativenavigation.options.Alignment; import com.reactnativenavigation.options.ButtonOptions; import com.reactnativenavigation.options.ComponentOptions; +import com.reactnativenavigation.options.FontOptions; import com.reactnativenavigation.options.Options; import com.reactnativenavigation.options.OrientationOptions; import com.reactnativenavigation.options.SubtitleOptions; @@ -99,7 +100,7 @@ public TitleBarReactView create(Activity activity, String componentId, String co } }; renderChecker = spy(new RenderChecker()); - uut = spy(new StackPresenter(activity, titleViewCreator, new TopBarBackgroundViewCreatorMock(), new TitleBarButtonCreatorMock(), new IconResolver(activity, ImageLoaderMock.mock()), renderChecker, new Options())); + uut = spy(new StackPresenter(activity, titleViewCreator, new TopBarBackgroundViewCreatorMock(), new TitleBarButtonCreatorMock(), new IconResolver(activity, ImageLoaderMock.mock()), new TypefaceLoaderMock(), renderChecker, new Options())); createTopBarController(); parent = TestUtils.newStackController(activity) @@ -313,7 +314,8 @@ public void mergeTopBarOptions() { title.component.componentId = new Text("compId"); title.color = new Colour(0); title.fontSize = new Fraction(1.0f); - title.fontFamily = Typeface.DEFAULT_BOLD; + title.font = new FontOptions(); + title.font.setFontStyle(new Text("bold")); options.topBar.title = title; SubtitleOptions subtitleOptions = new SubtitleOptions(); subtitleOptions.text = new Text("Sub"); @@ -661,7 +663,7 @@ private void assertTopBarOptions(Options options, int t) { verify(topBar, times(t)).setBackgroundColor(anyInt()); verify(topBar, times(t)).setTitleTextColor(anyInt()); verify(topBar, times(t)).setTitleFontSize(anyDouble()); - verify(topBar, times(t)).setTitleTypeface(any()); + verify(topBar, times(t)).setTitleTypeface(any(), any()); verify(topBar, times(t)).setSubtitleColor(anyInt()); verify(topBar, times(t)).setTestId(any()); verify(topBarController, times(t)).hide();