Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .ado/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
}
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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;
Expand Down Expand Up @@ -41,7 +42,7 @@ public class ReactFontManager {
private static ReactFontManager sReactFontManagerInstance;

final private Map<String, FontFamily> mFontCache;
final private Map<String, Typeface> mCustomTypefaceCache;
final private Map<Pair<String, Integer>, Typeface> mCustomTypefaceCache;

private ReactFontManager() {
mFontCache = new HashMap<>();
Expand All @@ -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, null);
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);
Expand Down Expand Up @@ -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, null), typeface);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down