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 Oct 29, 2023
1 parent b27c06f commit 90ad4b5
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 @@ -83,7 +83,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 @@ -599,6 +599,8 @@ public void setFontFeatureSettings(String fontFeatureSettings) {
}

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

if (!mTypefaceDirty) {
return;
}
Expand Down

0 comments on commit 90ad4b5

Please sign in to comment.