Skip to content

Commit

Permalink
Use function instead of callback
Browse files Browse the repository at this point in the history
  • Loading branch information
GregKWhite committed Jul 3, 2024
1 parent c13ad6d commit 5e54ee1
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@
import androidx.annotation.RequiresApi;
import androidx.core.content.res.ResourcesCompat;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.Callback;
import androidx.arch.core.util.Function;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class CreateTypefaceObject {
public String fontFamilyName;
public int style;
public AssetManager assetManager;

public CreateTypefaceObject(
String fontFamilyName, int style, AssetManager assetManager) {
this.fontFamilyName = fontFamilyName;
this.style = style;
this.assetManager = assetManager;
}
}

/**
* Responsible for loading and caching Typeface objects.
*
Expand All @@ -43,7 +56,7 @@
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
public class ReactFontManager {
public static Callback createAssetTypefaceOverride = null;
public static Function<CreateTypefaceObject, Typeface> createAssetTypefaceOverride = null;

// NOTE: Indices in `EXTENSIONS` correspond to the `TypeFace` style constants.
private static final String[] EXTENSIONS = {"", "_bold", "_italic", "_bold_italic"};
Expand Down Expand Up @@ -153,7 +166,9 @@ public void setTypeface(String fontFamilyName, int style, Typeface typeface) {
private static Typeface createAssetTypeface(
String fontFamilyName, int style, AssetManager assetManager) {
if (createAssetTypefaceOverride != null) {
return createAssetTypefaceOverride.invoke(fontFamilyName, style, assetManager);
return createAssetTypefaceOverride.apply(
new CreateTypefaceObject(fontFamilyName, style, assetManager)
);
}

String extension = EXTENSIONS[style];
Expand Down

0 comments on commit 5e54ee1

Please sign in to comment.