Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class FontOptions {

@JvmOverloads fun getTypeface(typefaceLoader: TypefaceLoader, defaultTypeface: Typeface? = null): Typeface? {
if (isDirty) {
_typeface = typefaceLoader.getTypeFace(fontFamily.get(""), fontStyle.get(""), fontWeight.get(""))
_typeface = typefaceLoader.getTypeFace(fontFamily.get(null), fontStyle.get(""), fontWeight.get(""), defaultTypeface)
isDirty = false
}
return _typeface
?: defaultTypeface?.let { typefaceLoader.getTypeFace(fontFamily.get(""), fontStyle.get(""), fontWeight.get(""), it) }
?: defaultTypeface?.let { typefaceLoader.getTypeFace(fontFamily.get(null), fontStyle.get(""), fontWeight.get(""), it) }
}

fun mergeWith(other: FontOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ package com.reactnativenavigation.options.parsers

import android.content.Context
import android.graphics.Typeface
import com.aurelhubert.ahbottomnavigation.AHTextView
import com.reactnativenavigation.utils.ReactTypefaceUtils

open class TypefaceLoader(private val context: Context) {
@JvmOverloads open fun getTypeFace(
fontFamilyName: String?,
fontStyle: String?,
fontWeight: String?,
defaultTypeFace: Typeface? = null
val defaultTypeFace: Typeface by lazy {
AHTextView(context).typeface ?: Typeface.DEFAULT
}

@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
defaultTypeFace,
ReactTypefaceUtils.parseFontStyle(fontStyle),
ReactTypefaceUtils.parseFontWeight(fontWeight),
fontFamilyName,
context.assets
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import androidx.annotation.NonNull;

import com.aurelhubert.ahbottomnavigation.AHTextView;
import com.aurelhubert.ahbottomnavigation.notification.AHNotification;
import com.reactnativenavigation.options.BottomTabOptions;
import com.reactnativenavigation.options.DotIndicatorOptions;
Expand All @@ -27,6 +28,7 @@ public class BottomTabPresenter {
private final Context context;
private final ImageLoader imageLoader;
private final TypefaceLoader typefaceLoader;
private final Typeface defaultTypeface;
private Options defaultOptions;
private final BottomTabFinder bottomTabFinder;
private final LateInit<BottomTabs> bottomTabs = new LateInit<>();
Expand All @@ -39,6 +41,7 @@ public BottomTabPresenter(Context context, List<ViewController<?>> tabs, ImageLo
this.bottomTabFinder = new BottomTabFinder(tabs);
this.imageLoader = imageLoader;
this.typefaceLoader = typefaceLoader;
this.defaultTypeface = typefaceLoader.getDefaultTypeFace();
this.defaultOptions = defaultOptions;
defaultDotIndicatorSize = dpToPx(context, 6);
}
Expand All @@ -57,7 +60,7 @@ public void applyOptions() {
BottomTabOptions tab = tabs.get(i).resolveCurrentOptions(defaultOptions).bottomTabOptions;
bottomTabs.setIconWidth(i, tab.iconWidth.get(null));
bottomTabs.setIconHeight(i, tab.iconHeight.get(null));
bottomTabs.setTitleTypeface(i, tab.font.getTypeface(typefaceLoader, Typeface.DEFAULT));
bottomTabs.setTitleTypeface(i, tab.font.getTypeface(typefaceLoader, defaultTypeface));
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));
Expand Down Expand Up @@ -86,7 +89,7 @@ public void mergeChildOptions(Options options, ViewController<?> child) {
BottomTabOptions tab = options.bottomTabOptions;
if (tab.iconWidth.hasValue()) bottomTabs.setIconWidth(index, tab.iconWidth.get(null));
if (tab.iconHeight.hasValue()) bottomTabs.setIconHeight(index, tab.iconHeight.get(null));
if (tab.font.hasValue()) bottomTabs.setTitleTypeface(index, tab.font.getTypeface(typefaceLoader, Typeface.DEFAULT));
if (tab.font.hasValue()) bottomTabs.setTitleTypeface(index, tab.font.getTypeface(typefaceLoader, defaultTypeface));
if (canMergeColor(tab.selectedIconColor)) bottomTabs.setIconActiveColor(index, tab.selectedIconColor.get());
if (canMergeColor(tab.iconColor)) bottomTabs.setIconInactiveColor(index, tab.iconColor.get());
if (tab.selectedTextColor.hasValue()) bottomTabs.setTitleActiveColor(index, tab.selectedTextColor.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ButtonSpan(

fun apply(paint: Paint) {
with(button.font) {
val typeface = getTypeface(typefaceLoader, Typeface.DEFAULT)
val typeface = getTypeface(typefaceLoader, paint.typeface)
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
Expand Down