diff --git a/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java b/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java
index b003fb1d3a2..a6601115ad9 100644
--- a/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java
+++ b/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java
@@ -47,7 +47,7 @@ public class RNTesterApplication extends Application implements ReactApplication
@Override
public void onCreate() {
- ReactFontManager.getInstance().addCustomFont(this, "Srisakdi", R.font.srisakdi);
+ ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik);
super.onCreate();
}
diff --git a/RNTester/android/app/src/main/res/font/rubik.xml b/RNTester/android/app/src/main/res/font/rubik.xml
new file mode 100644
index 00000000000..e850a0bc78a
--- /dev/null
+++ b/RNTester/android/app/src/main/res/font/rubik.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/RNTester/android/app/src/main/res/font/rubik_bold.ttf b/RNTester/android/app/src/main/res/font/rubik_bold.ttf
new file mode 100755
index 00000000000..9b947dbf9df
Binary files /dev/null and b/RNTester/android/app/src/main/res/font/rubik_bold.ttf differ
diff --git a/RNTester/android/app/src/main/res/font/rubik_light.ttf b/RNTester/android/app/src/main/res/font/rubik_light.ttf
new file mode 100755
index 00000000000..1adb7d5815e
Binary files /dev/null and b/RNTester/android/app/src/main/res/font/rubik_light.ttf differ
diff --git a/RNTester/android/app/src/main/res/font/rubik_medium.ttf b/RNTester/android/app/src/main/res/font/rubik_medium.ttf
new file mode 100755
index 00000000000..24519e56fd4
Binary files /dev/null and b/RNTester/android/app/src/main/res/font/rubik_medium.ttf differ
diff --git a/RNTester/android/app/src/main/res/font/rubik_medium_italic.ttf b/RNTester/android/app/src/main/res/font/rubik_medium_italic.ttf
new file mode 100755
index 00000000000..8a8c7fc6c6c
Binary files /dev/null and b/RNTester/android/app/src/main/res/font/rubik_medium_italic.ttf differ
diff --git a/RNTester/android/app/src/main/res/font/rubik_regular.ttf b/RNTester/android/app/src/main/res/font/rubik_regular.ttf
new file mode 100755
index 00000000000..f99fe158743
Binary files /dev/null and b/RNTester/android/app/src/main/res/font/rubik_regular.ttf differ
diff --git a/RNTester/android/app/src/main/res/font/srisakdi.xml b/RNTester/android/app/src/main/res/font/srisakdi.xml
deleted file mode 100644
index c38d8f34a0e..00000000000
--- a/RNTester/android/app/src/main/res/font/srisakdi.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/RNTester/android/app/src/main/res/font/srisakdi_bold.ttf b/RNTester/android/app/src/main/res/font/srisakdi_bold.ttf
deleted file mode 100755
index 01a5bcb5d30..00000000000
Binary files a/RNTester/android/app/src/main/res/font/srisakdi_bold.ttf and /dev/null differ
diff --git a/RNTester/android/app/src/main/res/font/srisakdi_regular.ttf b/RNTester/android/app/src/main/res/font/srisakdi_regular.ttf
deleted file mode 100755
index 4db47aaad38..00000000000
Binary files a/RNTester/android/app/src/main/res/font/srisakdi_regular.ttf and /dev/null differ
diff --git a/RNTester/js/examples/Text/TextExample.android.js b/RNTester/js/examples/Text/TextExample.android.js
index 85fb52c96e9..dbded71f36a 100644
--- a/RNTester/js/examples/Text/TextExample.android.js
+++ b/RNTester/js/examples/Text/TextExample.android.js
@@ -181,13 +181,41 @@ class TextExample extends React.Component<{}> {
NotoSerif Italic (Missing Font file)
- Srisakdi Regular
- Srisakdi Bold
+ Rubik Regular
+
+
+ Rubik Light
+
+
+ Rubik Bold
+
+
+ Rubik Medium
+
+
+ Rubik Medium Italic
@@ -203,15 +231,15 @@ class TextExample extends React.Component<{}> {
Move fast and be bold
- Move fast and be bold
+ Move fast and be normal
- Move fast and be bold
- Move fast and be bold
+ Move fast and be italic
+ Move fast and be normal
- Move fast and be bold
+ Move fast and be both bold and italic
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 c3cc40afea4..347b0c98b97 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
@@ -104,7 +104,7 @@ public class CustomStyleSpan extends MetricAffectingSpan implements ReactSpan {
}
if (family != null) {
- typeface = ReactFontManager.getInstance().getTypeface(family, want, assetManager);
+ typeface = ReactFontManager.getInstance().getTypeface(family, want, weight, assetManager);
} else if (typeface != null) {
// TODO(t9055065): Fix custom fonts getting applied to text children with different style
typeface = Typeface.create(typeface, want);
diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java
index 7bfc0ae496c..015d4f72ced 100644
--- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java
+++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java
@@ -309,7 +309,7 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
&& fontWeightString.charAt(0) <= '9'
&& fontWeightString.charAt(0) >= '1'
? 100 * (fontWeightString.charAt(0) - '0')
- : -1;
+ : UNSET;
}
protected TextAttributes mTextAttributes;
@@ -487,14 +487,12 @@ public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
@ReactProp(name = ViewProps.FONT_WEIGHT)
public void setFontWeight(@Nullable String fontWeightString) {
int fontWeightNumeric =
- fontWeightString != null ? parseNumericFontWeight(fontWeightString) : -1;
- int fontWeight = UNSET;
- if (fontWeightNumeric >= 500 || "bold".equals(fontWeightString)) {
- fontWeight = Typeface.BOLD;
- } else if ("normal".equals(fontWeightString)
- || (fontWeightNumeric != -1 && fontWeightNumeric < 500)) {
- fontWeight = Typeface.NORMAL;
- }
+ fontWeightString != null ? parseNumericFontWeight(fontWeightString) : UNSET;
+ int fontWeight = fontWeightNumeric != UNSET ? fontWeightNumeric : Typeface.NORMAL;
+
+ if (fontWeight == 700 || "bold".equals(fontWeightString)) fontWeight = Typeface.BOLD;
+ else if (fontWeight == 400 || "normal".equals(fontWeightString)) fontWeight = Typeface.NORMAL;
+
if (fontWeight != mFontWeight) {
mFontWeight = fontWeight;
markUpdated();
diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java
index 66017625138..21d4c175380 100644
--- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java
+++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactFontManager.java
@@ -13,6 +13,7 @@ import java.util.Map;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Typeface;
+import android.os.Build;
import android.util.SparseArray;
import androidx.annotation.NonNull;
@@ -54,23 +55,32 @@ public class ReactFontManager {
return sReactFontManagerInstance;
}
+ public @Nullable Typeface getTypeface(
+ String fontFamilyName,
+ int style,
+ AssetManager assetManager) {
+ return getTypeface(fontFamilyName, style, 0, assetManager);
+ }
+
public @Nullable Typeface getTypeface(
String fontFamilyName,
int style,
+ int weight,
AssetManager assetManager) {
+ if(mCustomTypefaceCache.containsKey(fontFamilyName)) {
+ Typeface typeface = mCustomTypefaceCache.get(fontFamilyName);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && weight >= 100 && weight <= 1000) {
+ return Typeface.create(typeface, weight, (style & Typeface.ITALIC) != 0);
+ }
+ return Typeface.create(typeface, style);
+ }
+
FontFamily fontFamily = mFontCache.get(fontFamilyName);
if (fontFamily == null) {
fontFamily = new FontFamily();
mFontCache.put(fontFamilyName, fontFamily);
}
- if(mCustomTypefaceCache.containsKey(fontFamilyName)) {
- return Typeface.create(
- mCustomTypefaceCache.get(fontFamilyName),
- style
- );
- }
-
Typeface typeface = fontFamily.getTypeface(style);
if (typeface == null) {
typeface = createTypeface(fontFamilyName, style, assetManager);