expo-font 12.0.8 → 12.0.9

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,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 12.0.9 — 2024-07-16
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - On `iOS`, fix issues where fonts were removed when the app is backgrounded. ([#30400](https://github.com/expo/expo/pull/30400) by [@alanjhughes](https://github.com/alanjhughes))
18
+
13
19
  ## 12.0.8 — 2024-07-11
14
20
 
15
21
  ### 🎉 New features
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '12.0.8'
4
+ version = '12.0.9'
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.8"
17
+ versionName "12.0.9"
18
18
  }
19
19
  }
@@ -17,3 +17,9 @@ internal final class FontRegistrationFailedException: GenericException<CFError>
17
17
  "Registering '\(param)' font failed with message: '\(param.localizedDescription)'"
18
18
  }
19
19
  }
20
+
21
+ internal final class UnregisteringFontFailedException: GenericException<CFError> {
22
+ override var reason: String {
23
+ "Unregistering '\(param)' font failed with message: '\(param.localizedDescription)'"
24
+ }
25
+ }
@@ -25,9 +25,9 @@ internal struct FontFamilyAliasManager {
25
25
  Sets the alias for the given family name.
26
26
  If the alias has already been set, its family name will be overriden.
27
27
  */
28
- internal static func setAlias(_ familyNameAlias: String, forFamilyName familyName: String) {
28
+ internal static func setAlias(_ familyNameAlias: String, forFont font: String) {
29
29
  maybeSwizzleUIFont()
30
- fontFamilyAliases[familyNameAlias] = familyName
30
+ fontFamilyAliases[familyNameAlias] = font
31
31
  }
32
32
 
33
33
  /**
@@ -9,24 +9,23 @@ public final class FontLoaderModule: Module {
9
9
  }
10
10
 
11
11
  AsyncFunction("loadAsync") { (fontFamilyAlias: String, localUri: URL) in
12
- // If the font was already registered, unregister it first. Otherwise CTFontManagerRegisterGraphicsFont
12
+ let fontUrl = localUri as CFURL
13
+ // If the font was already registered, unregister it first. Otherwise CTFontManagerRegisterFontsForURL
13
14
  // would fail because of a duplicated font name when the app reloads or someone wants to override a font.
14
- if let familyName = FontFamilyAliasManager.familyName(forAlias: fontFamilyAlias) {
15
- guard try unregisterFont(named: familyName) else {
15
+ if FontFamilyAliasManager.familyName(forAlias: fontFamilyAlias) != nil {
16
+ guard try unregisterFont(url: fontUrl) else {
16
17
  return
17
18
  }
18
19
  }
19
20
 
20
- // Create a font object from the given file
21
- let font = try loadFont(fromPath: localUri.path, alias: fontFamilyAlias)
22
-
23
21
  // Register the font
24
- try registerFont(font)
22
+ try registerFont(fontUrl)
23
+
24
+ // Create a font object from the given URL
25
+ let font = try loadFont(fromUrl: fontUrl, alias: fontFamilyAlias)
25
26
 
26
- // The real font name might be different than it's been requested by the user,
27
- // so we save the provided name as an alias.
28
27
  if let postScriptName = font.postScriptName as? String {
29
- FontFamilyAliasManager.setAlias(fontFamilyAlias, forFamilyName: postScriptName)
28
+ FontFamilyAliasManager.setAlias(fontFamilyAlias, forFont: postScriptName)
30
29
  }
31
30
  }
32
31
  }
@@ -31,25 +31,24 @@ internal func queryCustomNativeFonts() -> [String] {
31
31
  }
32
32
 
33
33
  /**
34
- Loads the font from the given path and returns it as ``CGFont``.
34
+ Loads the font from the given url and returns it as ``CGFont``.
35
35
  */
36
- internal func loadFont(fromPath path: String, alias: String) throws -> CGFont {
37
- guard let data = FileManager.default.contents(atPath: path) else {
38
- throw FontFileNotFoundException(path)
39
- }
40
- guard let provider = CGDataProvider(data: data as CFData), let font = CGFont(provider) else {
36
+ internal func loadFont(fromUrl url: CFURL, alias: String) throws -> CGFont {
37
+ guard let provider = CGDataProvider(url: url),
38
+ let cgFont = CGFont(provider) else {
41
39
  throw FontCreationFailedException(alias)
42
40
  }
43
- return font
41
+
42
+ return cgFont
44
43
  }
45
44
 
46
45
  /**
47
46
  Registers the given font to make it discoverable through font descriptor matching.
48
47
  */
49
- internal func registerFont(_ font: CGFont) throws {
48
+ internal func registerFont(_ fontUrl: CFURL) throws {
50
49
  var error: Unmanaged<CFError>?
51
50
 
52
- if !CTFontManagerRegisterGraphicsFont(font, &error), let error = error?.takeRetainedValue() {
51
+ if !CTFontManagerRegisterFontsForURL(fontUrl, .process, &error), let error = error?.takeRetainedValue() {
53
52
  let fontError = CTFontManagerError(rawValue: CFErrorGetCode(error))
54
53
 
55
54
  switch fontError {
@@ -68,10 +67,10 @@ internal func registerFont(_ font: CGFont) throws {
68
67
  Unregisters the given font, so the app will no longer be able to render it.
69
68
  Returns a boolean indicating if the font is successfully unregistered after this function completes.
70
69
  */
71
- internal func unregisterFont(_ font: CGFont) throws -> Bool {
70
+ internal func unregisterFont(url: CFURL) throws -> Bool {
72
71
  var error: Unmanaged<CFError>?
73
72
 
74
- if !CTFontManagerUnregisterGraphicsFont(font, &error), let error = error?.takeRetainedValue() {
73
+ if !CTFontManagerUnregisterFontsForURL(url, .process, &error), let error = error?.takeRetainedValue() {
75
74
  if let ctFontManagerError = CTFontManagerError(rawValue: CFErrorGetCode(error as CFError)) {
76
75
  switch ctFontManagerError {
77
76
  case .systemRequired, .inUse:
@@ -79,20 +78,9 @@ internal func unregisterFont(_ font: CGFont) throws -> Bool {
79
78
  case .notRegistered:
80
79
  return true
81
80
  default:
82
- throw FontRegistrationFailedException(error)
81
+ throw UnregisteringFontFailedException(error)
83
82
  }
84
83
  }
85
84
  }
86
85
  return true
87
86
  }
88
-
89
- /**
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.
92
- */
93
- internal func unregisterFont(named fontName: String) throws -> Bool {
94
- if let font = CGFont(fontName as CFString) {
95
- return try unregisterFont(font)
96
- }
97
- return true
98
- }
@@ -11,16 +11,17 @@ public extension UIFont {
11
11
  let fontNames = UIFont._expo_fontNames(forFamilyName: familyName)
12
12
 
13
13
  // If no font names were found, let's try with the alias.
14
- if fontNames.isEmpty, let aliasedFamilyName = FontFamilyAliasManager.familyName(forAlias: familyName) {
15
- let fontNames = UIFont._expo_fontNames(forFamilyName: aliasedFamilyName)
14
+ if fontNames.isEmpty, let postScriptName = FontFamilyAliasManager.familyName(forAlias: familyName) {
15
+ let fontNames = UIFont._expo_fontNames(forFamilyName: postScriptName)
16
16
 
17
17
  // If we still don't find any font names, we can assume it was not a family name but a font name.
18
18
  // In that case we can safely return the original font name.
19
19
  if fontNames.isEmpty {
20
- return [aliasedFamilyName]
20
+ return [postScriptName]
21
21
  }
22
22
  return fontNames
23
23
  }
24
+
24
25
  return fontNames
25
26
  }
26
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-font",
3
- "version": "12.0.8",
3
+ "version": "12.0.9",
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": "48f1ec9d91c5c38c7684cb98a314e443cbeb2185"
45
+ "gitHead": "b62618a8f99582621e1252c7a8013c62e1c6e013"
46
46
  }