Skip to content

Commit

Permalink
Added ability to set default font features on android
Browse files Browse the repository at this point in the history
  • Loading branch information
danilobuerger committed Sep 6, 2022
1 parent 56c4f27 commit bda3650
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ private static void apply(
@Nullable String family,
Context context) {
Typeface typeface = ReactTypefaceUtils.applyStyles(paint.getTypeface(), style, weight, family, context);
paint.setFontFeatureSettings(fontFeatureSettings);
String ffs = ReactTypefaceUtils.defaultFontFeatures;
if (fontFeatureSettings != null && fontFeatureSettings.trim().length() > 0) {
if (ffs != null && ffs.trim().length() > 0) {
ffs += ", " + fontFeatureSettings;
} else {
ffs = fontFeatureSettings;
}
}
paint.setFontFeatureSettings(ffs);
paint.setTypeface(typeface);
paint.setSubpixelText(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class ReactTypefaceUtils {

public static Typeface defaultTypeface = Typeface.DEFAULT;
public static @Nullable String defaultFontFeatures = null;

public static int parseFontWeight(@Nullable String fontWeightString) {
if (fontWeightString != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ public void setFontStyle(String fontStyleString) {
}

public void maybeUpdateTypeface() {
getPaint().setFontFeatureSettings(ReactTypefaceUtils.defaultFontFeatures);

if (!mTypefaceDirty) {
return;
}
Expand Down

0 comments on commit bda3650

Please sign in to comment.