expo-font 12.0.4 → 12.0.6

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,18 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 12.0.6 — 2024-05-29
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [iOS] Fix font registration failing when font was in use. ([#28989](https://github.com/expo/expo/pull/28989) by [@aleqsio](https://github.com/aleqsio))
18
+
19
+ ## 12.0.5 — 2024-05-10
20
+
21
+ ### 🐛 Bug fixes
22
+
23
+ - Fixed some vector icons not rendering correctly. ([#28747](https://github.com/expo/expo/pull/28747) by [@tsapeta](https://github.com/tsapeta))
24
+
13
25
  ## 12.0.4 — 2024-04-24
14
26
 
15
27
  _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.4'
4
+ version = '12.0.6'
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.4"
17
+ versionName "12.0.6"
18
18
  }
19
19
  }
@@ -39,15 +39,9 @@ internal struct FontFamilyAliasManager {
39
39
  }
40
40
 
41
41
  /**
42
- Swizzles ``UIFont.fontNames(forFamilyName:)`` and ``UIFont(name:size:)`` to support font family aliases.
42
+ Swizzles ``UIFont.fontNames(forFamilyName:)`` 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.
51
45
  */
52
46
  private func maybeSwizzleUIFont() {
53
47
  if hasSwizzled {
@@ -61,13 +55,5 @@ private func maybeSwizzleUIFont() {
61
55
  } else {
62
56
  log.error("expo-font is unable to swizzle `UIFont.fontNames(forFamilyName:)`")
63
57
  }
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
- }
72
58
  hasSwizzled = true
73
59
  }
@@ -12,7 +12,9 @@ public final class FontLoaderModule: Module {
12
12
  // If the font was already registered, unregister it first. Otherwise CTFontManagerRegisterGraphicsFont
13
13
  // would fail because of a duplicated font name when the app reloads or someone wants to override a font.
14
14
  if let familyName = FontFamilyAliasManager.familyName(forAlias: fontFamilyAlias) {
15
- try unregisterFont(named: familyName)
15
+ guard try unregisterFont(named: familyName) else {
16
+ return
17
+ }
16
18
  }
17
19
 
18
20
  // Create a font object from the given file
@@ -66,20 +66,33 @@ internal func registerFont(_ font: CGFont) throws {
66
66
 
67
67
  /**
68
68
  Unregisters the given font, so the app will no longer be able to render it.
69
+ Returns a boolean indicating if the font is successfully unregistered after this function completes.
69
70
  */
70
- internal func unregisterFont(_ font: CGFont) throws {
71
+ internal func unregisterFont(_ font: CGFont) throws -> Bool {
71
72
  var error: Unmanaged<CFError>?
72
73
 
73
74
  if !CTFontManagerUnregisterGraphicsFont(font, &error), let error = error?.takeRetainedValue() {
74
- throw FontRegistrationFailedException(error)
75
+ if let ctFontManagerError = CTFontManagerError(rawValue: CFErrorGetCode(error as CFError)) {
76
+ switch ctFontManagerError {
77
+ case .systemRequired, .inUse:
78
+ return false
79
+ case .notRegistered:
80
+ return true
81
+ default:
82
+ throw FontRegistrationFailedException(error)
83
+ }
84
+ }
75
85
  }
86
+ return true
76
87
  }
77
88
 
78
89
  /**
79
90
  Unregisters a font with the given name, so the app will no longer be able to render it.
91
+ Returns a boolean indicating if the font is successfully unregistered after this function completes.
80
92
  */
81
- internal func unregisterFont(named fontName: String) throws {
93
+ internal func unregisterFont(named fontName: String) throws -> Bool {
82
94
  if let font = CGFont(fontName as CFString) {
83
- try unregisterFont(font)
95
+ return try unregisterFont(font)
84
96
  }
97
+ return true
85
98
  }
@@ -7,21 +7,20 @@ public extension UIFont {
7
7
  */
8
8
  @objc
9
9
  static dynamic func _expo_fontNames(forFamilyName familyName: String) -> [String] {
10
+ // Get font names from the original function.
10
11
  let fontNames = UIFont._expo_fontNames(forFamilyName: familyName)
11
12
 
13
+ // If no font names were found, let's try with the alias.
12
14
  if fontNames.isEmpty, let aliasedFamilyName = FontFamilyAliasManager.familyName(forAlias: familyName) {
13
- // Note that this actually calls the original method implementation (if swizzled).
14
- return UIFont._expo_fontNames(forFamilyName: aliasedFamilyName)
15
- }
16
- return fontNames
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)
15
+ let fontNames = UIFont._expo_fontNames(forFamilyName: aliasedFamilyName)
21
16
 
22
- if let aliasedFamilyName = FontFamilyAliasManager.familyName(forAlias: fontName) {
23
- return UIFont._expo_init(name: aliasedFamilyName, size: fontSize)
17
+ // If we still don't find any font names, we can assume it was not a family name but a font name.
18
+ // In that case we can safely return the original font name.
19
+ if fontNames.isEmpty {
20
+ return [aliasedFamilyName]
21
+ }
22
+ return fontNames
24
23
  }
25
- return font
24
+ return fontNames
26
25
  }
27
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-font",
3
- "version": "12.0.4",
3
+ "version": "12.0.6",
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": "8b4cb45563b85c2ec91b1b249d136661bf6e8981"
45
+ "gitHead": "979e9f1fc3cfa9c827700dcf99992e671cfdf63e"
46
46
  }