Repository navigation
fix(ios): resolve input heading weight within a custom font family - #1163
Open
wildseansy wants to merge 1 commit into
Open
wildseansy wants to merge 1 commit into
wildseansy wants to merge 1 commit into
Conversation
headingFontForLevel: added the weight trait to the base font's descriptor, which still carries the font-name attribute. For a custom font the name pins the exact face (e.g. regular), so the weight trait was ignored and headings rendered at regular weight. Also resolve by family plus weight trait and keep whichever face is closer to the requested weight, so a custom family picks its own nearest face. System fonts keep the previous result. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MRyUZFqR1H4uhUJg6hkeci
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What/Why?
Follow-up to #586. With a custom editor font (a bundled family with separate regular and bold faces),
EnrichedMarkdownTextInputheadings on iOS still render at regular weight, even though the heading weight is bold by default. Inline bold in the same editor is correct.headingFontForLevel:builds the heading font from[_baseFont.fontDescriptor fontDescriptorByAddingAttributes:{UIFontDescriptorTraitsAttribute: {UIFontWeightTrait: weight}}]. That descriptor still carries the font-name attribute, and for a custom font the name pins the exact face (for example the regular one), so the weight trait is ignored. System fonts are not affected, which is why this works with the default font. Inline bold works because the formatter goes throughfontDescriptorWithSymbolicTraits:, which re-matches within the family.This change also resolves the font by family name plus the weight trait (no name attribute), the way React Native's
RCTFontresolves a weight inside a family, and keeps whichever result's weight trait is closer to the requested weight. The result is cached in_headingFontCacheas before. Two properties follow from comparing the two candidates:600when only regular and bold exist) resolves to the nearest face inside the family, instead of falling back to a different font.This is the same direction as the review on #586 (resolve weights within the family, keep iOS consistent with Android and the preview).
Context from #586: its first commit derived the bold face with
fontDescriptorWithSymbolicTraits:(which does re-match within a custom family), and the review replaced that with the single weight-trait path for every weight, so bold and the other weights share one code path. That is the path this PR builds on. It keeps the weight-trait approach and the shared weight table, and adds the family lookup so a custom font whose descriptor pins its face still resolves every weight inside the family. It does not go back to special-casing bold.Testing
fontFamily: "Avenir Next"on the editor, on an iPhone simulator running iOS 27 (also checked with a bundled custom family in a separate app).Screenshots
Example app,
EnrichedMarkdownTextInputwithfontFamily: "Avenir Next", iPhone simulator on iOS 27. Same content in both; the inline bold is unchanged, only the headings differ.PR Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01MRyUZFqR1H4uhUJg6hkeci