expo-font 12.0.2 → 12.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,10 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 12.0.3 — 2024-04-24
14
+
15
+ _This version does not introduce any user-facing changes._
16
+
13
17
  ## 12.0.2 — 2024-04-23
14
18
 
15
19
  _This version does not introduce any user-facing changes._
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '12.0.2'
4
+ version = '12.0.3'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -14,6 +14,6 @@ android {
14
14
  namespace "expo.modules.font"
15
15
  defaultConfig {
16
16
  versionCode 29
17
- versionName "12.0.2"
17
+ versionName "12.0.3"
18
18
  }
19
19
  }
@@ -39,21 +39,35 @@ internal struct FontFamilyAliasManager {
39
39
  }
40
40
 
41
41
  /**
42
- Swizzles ``UIFont.fontNames(forFamilyName:)`` to support font family aliases.
42
+ Swizzles ``UIFont.fontNames(forFamilyName:)`` and ``UIFont(name:size:)`` to support font family aliases.
43
43
  This is necessary because the user provides a custom family name that is then used in stylesheets,
44
44
  however the font usually has a different name encoded in the binary, thus the system may use a different name.
45
+
46
+ ``UIFont(name:size:)`` covers cases where there the font family has variants. For example, the ``CGFont fullName``
47
+ value for "Helvetica-Light-Oblique.ttf" would be something like "Helvetica Light Oblique", which
48
+ ``UIFont.fullNames`` won't recognize, because that is a font name rather than a font family name. We have to use
49
+ ``UIFont(name:size:)`` instead, because it accepts a font name. React Native does this looking up / falling back
50
+ for us, we just need to ensure both methods are swizzled so they both support aliasing.
45
51
  */
46
52
  private func maybeSwizzleUIFont() {
47
53
  if hasSwizzled {
48
54
  return
49
55
  }
50
- let originalMethod = class_getClassMethod(UIFont.self, #selector(UIFont.fontNames(forFamilyName:)))
51
- let newMethod = class_getClassMethod(UIFont.self, #selector(UIFont._expo_fontNames(forFamilyName:)))
56
+ let originalFontNamesMethod = class_getClassMethod(UIFont.self, #selector(UIFont.fontNames(forFamilyName:)))
57
+ let newFontNamesMethod = class_getClassMethod(UIFont.self, #selector(UIFont._expo_fontNames(forFamilyName:)))
52
58
 
53
- if let originalMethod, let newMethod {
54
- method_exchangeImplementations(originalMethod, newMethod)
59
+ if let originalFontNamesMethod, let newFontNamesMethod {
60
+ method_exchangeImplementations(originalFontNamesMethod, newFontNamesMethod)
55
61
  } else {
56
62
  log.error("expo-font is unable to swizzle `UIFont.fontNames(forFamilyName:)`")
57
63
  }
64
+ let originalInitMethod = class_getClassMethod(UIFont.self, #selector(UIFont.init(name:size:)))
65
+ let newInitMethod = class_getClassMethod(UIFont.self, #selector(UIFont._expo_init(name:size:)))
66
+
67
+ if let originalInitMethod, let newInitMethod {
68
+ method_exchangeImplementations(originalInitMethod, newInitMethod)
69
+ } else {
70
+ log.error("expo-font is unable to swizzle `UIFont.init(name:size:)`")
71
+ }
58
72
  hasSwizzled = true
59
73
  }
@@ -15,4 +15,13 @@ public extension UIFont {
15
15
  }
16
16
  return fontNames
17
17
  }
18
+ @objc
19
+ static dynamic func _expo_init(name fontName: String, size fontSize: CGFloat) -> UIFont? {
20
+ let font = UIFont._expo_init(name: fontName, size: fontSize)
21
+
22
+ if let aliasedFamilyName = FontFamilyAliasManager.familyName(forAlias: fontName) {
23
+ return UIFont._expo_init(name: aliasedFamilyName, size: fontSize)
24
+ }
25
+ return font
26
+ }
18
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-font",
3
- "version": "12.0.2",
3
+ "version": "12.0.3",
4
4
  "description": "Load fonts at runtime and use them in React Native components.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,5 +42,5 @@
42
42
  "peerDependencies": {
43
43
  "expo": "*"
44
44
  },
45
- "gitHead": "ee4f30ef3b5fa567ad1bf94794197f7683fdd481"
45
+ "gitHead": "f8f9d041c6467f325b58c7913e0f5ed1af102e11"
46
46
  }