-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathexpo-font+14.0.10.patch
More file actions
38 lines (37 loc) · 2.03 KB
/
Copy pathexpo-font+14.0.10.patch
File metadata and controls
38 lines (37 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
diff --git a/node_modules/expo-font/android/src/main/java/expo/modules/font/FontLoaderModule.kt b/node_modules/expo-font/android/src/main/java/expo/modules/font/FontLoaderModule.kt
index 2cd51dc..db368ff 100644
--- a/node_modules/expo-font/android/src/main/java/expo/modules/font/FontLoaderModule.kt
+++ b/node_modules/expo-font/android/src/main/java/expo/modules/font/FontLoaderModule.kt
@@ -5,6 +5,7 @@ package expo.modules.font
import android.content.Context
import android.graphics.Typeface
import android.net.Uri
+import android.os.Build
import com.facebook.react.common.assets.ReactFontManager
import expo.modules.kotlin.exception.CodedException
import expo.modules.kotlin.exception.Exceptions
@@ -34,6 +35,25 @@ open class FontLoaderModule : Module() {
AsyncFunction("loadAsync") { fontFamilyName: String, localUri: String ->
val context = appContext.reactContext ?: throw Exceptions.ReactContextLost()
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) {
+ // Only run this if it's a raw asset name (no protocol, not absolute)
+ if (!localUri.contains(":") && !localUri.startsWith("/")) {
+ val assetCandidates = listOf(
+ if (localUri.startsWith("fonts/")) localUri else "fonts/$localUri",
+ localUri.removePrefix("fonts/")
+ ).distinct()
+
+ for (candidate in assetCandidates) {
+ val typeface = runCatching { Typeface.createFromAsset(context.assets, candidate) }.getOrNull()
+ if (typeface != null) {
+ ReactFontManager.getInstance().setTypeface(fontFamilyName, Typeface.NORMAL, typeface)
+ loadedFonts = loadedFonts.toMutableSet().apply { add(fontFamilyName) }.toList()
+ return@AsyncFunction // Exit early if we successfully loaded the font
+ }
+ }
+ }
+ }
+
// TODO(nikki): make sure path is in experience's scope
val typeface: Typeface = if (localUri.startsWith(ASSET_SCHEME)) {
Typeface.createFromAsset(