Scale Rich Text message typography with the Text Size setting - #2330
Open
Recluse wants to merge 1 commit into
Open
Scale Rich Text message typography with the Text Size setting#2330Recluse wants to merge 1 commit into
Recluse wants to merge 1 commit into
Conversation
ChatMessageRichDataBubbleContentNode built its InstantPageTextCategories from nine hardcoded point sizes, so Rich Text / Extended Markdown messages did not follow Settings > Appearance > Text Size. An ordinary bubble uses ChatPresentationData.messageFont, i.e. Font.regular(fontSize.baseDisplaySize). The .regular step is 17pt, exactly the hardcoded paragraph size, so the two paths agree there and diverge at every other step. Scale the finished theme through the existing public helper InstantPageTheme.withUpdatedFontStyles by baseDisplaySize / 17.0 instead of adding a second set of constants. lineSpacingFactor: 1.0 keeps each category's own factor (the helper multiplies rather than replaces it) and forceSerif: false keeps the sans/serif split the theme already declares. Also scale the "show more" link, which was fixed at Font.regular(17.0), and add the base font size to the currentPageLayout cache key: that key held the bounding width and the theme object identity but no font size, so a Text Size change that did not also replace the PresentationTheme object would have reused a stale layout. At the .regular step the multiplier is 1, so rendering there is unchanged.
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.
Problem
Rich Text / Extended Markdown messages ignore Settings → Appearance → Text Size.
ChatMessageRichDataBubbleContentNodebuilds itsInstantPageTextCategoriesfrom ninehardcoded point sizes:
None of them consults the user's setting, while an ordinary bubble uses
ChatPresentationData.messageFont, i.e.Font.regular(fontSize.baseDisplaySize).baseDisplaySizeruns 14 / 15 / 16 / 17 / 19 / 23 / 26 for.extraSmall … .extraLargeX2.The
.regularstep is 17pt — exactly the hardcodedparagraphsize — so the two paths agreethere and diverge everywhere else. At the smallest step an ordinary message renders at 14pt
next to rich text still at 17pt in the same chat; at the largest steps the mismatch runs the
other way, with ordinary text at 26pt and rich text unchanged.
The
show morelink for truncated rich text is fixed atFont.regular(17.0)for the samereason.
Change
InstantPageThemealready exposes the right tool:so the bubble theme is scaled by
baseDisplaySize / 17.0rather than growing a second set ofsize constants.
lineSpacingFactor: 1.0is passed because the helper multiplies rather thanreplaces it, preserving the per-category factors (0.685 for headings, 1.0 for body), and
forceSerif: falsepreserves the sans/serif split the theme already declares.Three call sites:
Font.regular(17.0)on theshow morelink becomes the user's base size;baseFontSizejoins thecurrentPageLayoutcache key.Point 3 matters: that key holds the bounding width, the theme object identity, expanded
details, message stable version, pending edit key, page key and the show-more flag, but no font
size. Once the theme depends on the font size, a Text Size change that does not also replace
the
PresentationThemeobject would otherwise reuse a stale layout.Testing
baseDisplaySize→ resulting sizes, against the constants being replaced:.regular)At the
.regularstep the multiplier is17/17 = 1, so that row is identical to the currentconstants and rendering there is unchanged. Note that the shipped default is
useSystemFont: true, so which step a given user is actually on comes from the iOS DynamicType body size via
PresentationFontSize(systemFontSize:), not from a stored.regular.At the smallest step
subheaderandparagraphboth land on 14pt, becausewithUpdatedFontStylesfloors the scaled size. That is the helper's existing rounding, sharedwith the full-screen Instant Page theme factory, so this change does not introduce a new
rounding policy — but if you would rather keep subheadings distinct at that step, that is the
place to adjust.
Not addressed
InstantPageV2Layout.swiftpushes a fixed.fontSize(15.0)onto the style stack inlayoutCodeBlockand inlayoutQuoteText, immediately aftersetupStyleStackhas applied thetheme. So after this change the following still do not scale:
layoutBlockQuote.Block quotes with more than one child block do not take that path and scale normally, so the
inconsistency is only within the quote family. That file is shared with the other InstantPage
V2 consumers, so the right treatment there seemed like a maintainer decision rather than
something to fold into this change.