From db9ed5f14b5e98129b7cdefc4a061aba80f2f0f1 Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Mon, 21 Oct 2019 14:16:50 -0700 Subject: [PATCH 1/6] Add support for registering custom fonts by family+weight --- .ado/publish.js | 4 ++ .../react/views/text/ReactFontManager.java | 43 +++++++++++++++---- package.json | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.ado/publish.js b/.ado/publish.js index dbac3c731f723a..e5ca0b9641a85e 100644 --- a/.ado/publish.js +++ b/.ado/publish.js @@ -128,8 +128,12 @@ function doPublish() { } console.log("Created GitHub Release: " + JSON.stringify(body, null, 2)); + if (body.id) { uploadReleaseAssetUrl = assetUpdateUrl.replace(/{id}/, body.id); uploadTarBallToRelease(); + } else { + console.warn('Unable to find release to upload tar...skipping custom tar for release.') + } } ); } 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 0ad8bff3a6d35b..0dc21ef06f5971 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 @@ -8,6 +8,7 @@ package com.facebook.react.views.text; import java.util.HashMap; +import java.util.Pair; import java.util.Map; import android.content.Context; @@ -41,7 +42,7 @@ public class ReactFontManager { private static ReactFontManager sReactFontManagerInstance; final private Map mFontCache; - final private Map mCustomTypefaceCache; + final private Map, Typeface> mCustomTypefaceCache; private ReactFontManager() { mFontCache = new HashMap<>(); @@ -67,12 +68,18 @@ public static ReactFontManager getInstance() { 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); + Pair key = Pair.create(fontFamilyName, weight); + if(mCustomTypefaceCache.containsKey(key) { + return Typeface.create(mCustomTypefaceCache.get(key), style); + } else { + key = Pair.create(fontFamilyName, -1); + if(mCustomTypefaceCache.containsKey(key) { + Typeface typeface = mCustomTypefaceCache.get(key); + 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); } - return Typeface.create(typeface, style); } FontFamily fontFamily = mFontCache.get(fontFamilyName); @@ -106,8 +113,28 @@ public void addCustomFont(@NonNull Context context, @NonNull String fontFamily, } } - public void addCustomFont(@NonNull String fontFamily, @NonNull Typeface font) { - mCustomTypefaceCache.put(fontFamily, font); +/* + * This method allows you to load custom fonts from a custom Typeface object and register it as a specific + * fontFamily and weight. This can be used when fonts are delivered during runtime and cannot be included in + * the standard app resources. Typeface's registered using a specific weight will take priority over ones + * registered without a specific weight. + * + * ReactFontManager.getInstance().addCustomFont("Srisakdi", 600, typeface); + */ + public void addCustomFont(@NonNull String fontFamily, int weight, @NonNull Typeface typeface) { + mCustomTypefaceCache.put(Pair.create(fontFamily, weight), typeface); + } + + /* + * This method allows you to load custom fonts from a custom Typeface object and register it as a specific + * fontFamily. This can be used when fonts are delivered during runtime and cannot be included in + * the standard app resources. Typeface's registered using a specific weight will take priority over ones + * registered without a specific weight. + * + * ReactFontManager.getInstance().addCustomFont("Srisakdi", typeface); + */ + public void addCustomFont(@NonNull String fontFamily, @NonNull Typeface typeface) { + mCustomTypefaceCache.put(Pair.create(fontFamily, -1), typeface); } /** diff --git a/package.json b/package.json index bc7208fca163cd..f8d6ef14bac7a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native", - "version": "0.60.0-microsoft.8", + "version": "0.60.0-microsoft.9", "description": "[Microsoft Fork] A framework for building native apps using React", "license": "MIT", "repository": { From dfdda47226c2bcbf83a41e443b5557172fcf23c5 Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Mon, 21 Oct 2019 14:26:49 -0700 Subject: [PATCH 2/6] build fix --- .../java/com/facebook/react/views/text/ReactFontManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0dc21ef06f5971..a310acb1c057e8 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 @@ -69,11 +69,11 @@ public static ReactFontManager getInstance() { int weight, AssetManager assetManager) { Pair key = Pair.create(fontFamilyName, weight); - if(mCustomTypefaceCache.containsKey(key) { + if(mCustomTypefaceCache.containsKey(key)) { return Typeface.create(mCustomTypefaceCache.get(key), style); } else { key = Pair.create(fontFamilyName, -1); - if(mCustomTypefaceCache.containsKey(key) { + if(mCustomTypefaceCache.containsKey(key)) { Typeface typeface = mCustomTypefaceCache.get(key); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && weight >= 100 && weight <= 1000) { return Typeface.create(typeface, weight, (style & Typeface.ITALIC) != 0); From fba612b398390ee5b00b2d0e01b0424c8673f028 Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Mon, 21 Oct 2019 15:05:34 -0700 Subject: [PATCH 3/6] build fix --- .../java/com/facebook/react/views/text/ReactFontManager.java | 1 + 1 file changed, 1 insertion(+) 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 a310acb1c057e8..51b7d80d292cb0 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 @@ -15,6 +15,7 @@ import android.content.res.AssetManager; import android.graphics.Typeface; import android.os.Build; +import android.util.Pair; import android.util.SparseArray; import androidx.annotation.NonNull; From e5392d77318a3a3b3f7046363b54deec4cf7a14d Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Mon, 21 Oct 2019 15:13:22 -0700 Subject: [PATCH 4/6] fix build --- .../java/com/facebook/react/views/text/ReactFontManager.java | 1 - 1 file changed, 1 deletion(-) 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 51b7d80d292cb0..c4f947f50ea378 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 @@ -8,7 +8,6 @@ package com.facebook.react.views.text; import java.util.HashMap; -import java.util.Pair; import java.util.Map; import android.content.Context; From 2b340db5dd5abf79c967517e88775507dcad8cfe Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Mon, 21 Oct 2019 15:55:38 -0700 Subject: [PATCH 5/6] fix build --- .../java/com/facebook/react/views/text/ReactFontManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c4f947f50ea378..01eb27a3bfd909 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 @@ -42,7 +42,7 @@ public class ReactFontManager { private static ReactFontManager sReactFontManagerInstance; final private Map mFontCache; - final private Map, Typeface> mCustomTypefaceCache; + final private Map, Typeface> mCustomTypefaceCache; private ReactFontManager() { mFontCache = new HashMap<>(); From ab9ca710cb8f1426a0d78e7581ceb6cfd395ffb2 Mon Sep 17 00:00:00 2001 From: "REDMOND\\acoates" Date: Mon, 21 Oct 2019 16:26:54 -0700 Subject: [PATCH 6/6] opt --- .../java/com/facebook/react/views/text/ReactFontManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 01eb27a3bfd909..5bc87a3c478244 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 @@ -72,7 +72,7 @@ public static ReactFontManager getInstance() { if(mCustomTypefaceCache.containsKey(key)) { return Typeface.create(mCustomTypefaceCache.get(key), style); } else { - key = Pair.create(fontFamilyName, -1); + key = Pair.create(fontFamilyName, null); if(mCustomTypefaceCache.containsKey(key)) { Typeface typeface = mCustomTypefaceCache.get(key); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && weight >= 100 && weight <= 1000) { @@ -134,7 +134,7 @@ public void addCustomFont(@NonNull String fontFamily, int weight, @NonNull Typef * ReactFontManager.getInstance().addCustomFont("Srisakdi", typeface); */ public void addCustomFont(@NonNull String fontFamily, @NonNull Typeface typeface) { - mCustomTypefaceCache.put(Pair.create(fontFamily, -1), typeface); + mCustomTypefaceCache.put(Pair.create(fontFamily, null), typeface); } /**