Repository navigation
feat(mobile): customize fonts, reply emphasis, and message sizes #21987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jakeleventhal
wants to merge
12
commits into
pingdotgg:main
Choose a base branch
from
jakeleventhal:t3/mobile-custom-fonts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,085
−93
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a3d3d3c
feat(mobile): customize fonts and message text sizes
jakeleventhal a69c654
fix(mobile): resolve imported composer fonts and isolate import failures
jakeleventhal d66e431
feat(mobile): choose installed iOS font families instead of importing…
jakeleventhal e2866f3
fix(mobile): isolate native font picker callbacks on the main actor
jakeleventhal 7d8a2fb
feat(mobile): choose reply emphasis weight per font
jakeleventhal acd0f7e
perf(mobile): retain unchanged fonts on foreground refresh
jakeleventhal df8691e
fix(mobile): recompute composer line height when its font changes
jakeleventhal 05836a8
fix: preserve feature behavior after upstream rebase
jakeleventhal 2f3717f
fix: preserve feature behavior on current upstream
jakeleventhal 5bf1064
Merge remote-tracking branch 'github/main' into HEAD
maria-rcks 0532566
fix(mobile): preserve bold headings and update preview test fonts
maria-rcks d60d528
merge: sync mobile fonts with main
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
apps/mobile/modules/t3-native-controls/ios/T3InstalledFonts.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import CoreText | ||
| import UIKit | ||
|
|
||
| @MainActor | ||
| enum T3InstalledFonts { | ||
| static func describe(_ font: UIFont, name: String? = nil) -> [String: Any] { | ||
| func variant(_ weight: UIFont.Weight) -> String { | ||
| let descriptor = UIFontDescriptor(fontAttributes: [ | ||
| .family: font.familyName, | ||
| .traits: [UIFontDescriptor.TraitKey.weight: weight], | ||
| ]) | ||
| let candidate = UIFont(descriptor: descriptor, size: font.pointSize) | ||
| return candidate.familyName == font.familyName ? candidate.fontName : font.fontName | ||
| } | ||
| // CoreText reports medium as 0.20 while UIKit requests 0.23. | ||
| var emphasisFaces: [String: String] = [:] | ||
| for (key, weight) in [("500", UIFont.Weight.medium), ("600", .semibold), ("700", .bold)] { | ||
| let name = variant(weight) | ||
| guard let candidate = UIFont(name: name, size: font.pointSize), | ||
| let traits = candidate.fontDescriptor.object(forKey: .traits) as? [UIFontDescriptor.TraitKey: Any], | ||
| let actual = traits[.weight] as? NSNumber, | ||
| abs(actual.doubleValue - Double(weight.rawValue)) < 0.04 else { continue } | ||
| emphasisFaces[key] = name | ||
| } | ||
| return [ | ||
| "name": name ?? font.fontName, | ||
| "label": font.familyName, | ||
| "regular": font.fontName, | ||
| "medium": variant(.medium), | ||
| "bold": variant(.bold), | ||
| "emphasisFaces": emphasisFaces, | ||
| ] | ||
| } | ||
|
|
||
| static func resolve(_ names: [String], completion: @escaping ([[String: Any]]) -> Void) { | ||
| guard !names.isEmpty else { completion([]); return } | ||
| // Provider fonts must be requested again for each process. Persist names, | ||
| // not file URLs: iOS owns the files and the picker grants family access. | ||
| let descriptors = names.map { CTFontDescriptorCreateWithAttributes([kCTFontNameAttribute: $0] as CFDictionary) } | ||
| CTFontManagerRequestFonts(descriptors as CFArray) { _ in | ||
| DispatchQueue.main.async { | ||
| completion(names.compactMap { name in | ||
| guard let font = UIFont(name: name, size: 16) else { return nil } | ||
| return describe(font, name: name) | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @MainActor | ||
| final class T3FontPickerPresentation: NSObject, UIFontPickerViewControllerDelegate, UIAdaptivePresentationControllerDelegate { | ||
| private let completion: ([String: Any]?) -> Void | ||
| private var picker: UIFontPickerViewController? | ||
| private var finished = false | ||
|
|
||
| init(completion: @escaping ([String: Any]?) -> Void) { | ||
| self.completion = completion | ||
| } | ||
|
|
||
| func present(from presenter: UIViewController, selectedName: String?) { | ||
| let configuration = UIFontPickerViewController.Configuration() | ||
| configuration.includeFaces = false | ||
| let picker = UIFontPickerViewController(configuration: configuration) | ||
| if let selectedName, let font = UIFont(name: selectedName, size: 16) { | ||
| picker.selectedFontDescriptor = font.fontDescriptor | ||
| } | ||
| picker.delegate = self | ||
| self.picker = picker | ||
| presenter.present(picker, animated: true) | ||
| picker.presentationController?.delegate = self | ||
| } | ||
|
|
||
| func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) { | ||
| guard let descriptor = viewController.selectedFontDescriptor else { dismiss(); return } | ||
| let result = T3InstalledFonts.describe(UIFont(descriptor: descriptor, size: 16)) | ||
| viewController.dismiss(animated: true) { self.finish(result) } | ||
| } | ||
|
|
||
| func fontPickerViewControllerDidCancel(_ viewController: UIFontPickerViewController) { | ||
| dismiss() | ||
| } | ||
|
|
||
| func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { | ||
| finish(nil) | ||
| } | ||
|
|
||
| func dismiss() { | ||
| guard let picker else { finish(nil); return } | ||
| picker.dismiss(animated: true) { self.finish(nil) } | ||
| } | ||
|
|
||
| private func finish(_ result: [String: Any]?) { | ||
| guard !finished else { return } | ||
| finished = true | ||
| picker?.delegate = nil | ||
| picker = nil | ||
| completion(result) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.