From bda365068bcde7420b29959c1ac1223d4ffb28ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20B=C3=BCrger?= Date: Mon, 14 Mar 2022 11:30:04 +0100 Subject: [PATCH] Added ability to set default font features on android --- .../com/facebook/react/views/text/CustomStyleSpan.java | 10 +++++++++- .../facebook/react/views/text/ReactTypefaceUtils.java | 1 + .../facebook/react/views/textinput/ReactEditText.java | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java index 937fcb734d9005..9ca5217fc82fe4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomStyleSpan.java @@ -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); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java index 30a5261b29fece..d13f36db7f62c2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTypefaceUtils.java @@ -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) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 34ac48a49235fd..b941e2f09ff489 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -483,6 +483,8 @@ public void setFontStyle(String fontStyleString) { } public void maybeUpdateTypeface() { + getPaint().setFontFeatureSettings(ReactTypefaceUtils.defaultFontFeatures); + if (!mTypefaceDirty) { return; }