Repository navigation
[iOS] Fix Font autoscaling does not work in realtime - #34445
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34445Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34445" |
|
/azp run maui-pr-uitests,maui-pr-devicetests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Fixes iOS (and MacCatalyst) Dynamic Type changes not being reflected at runtime for explicitly-sized fonts by ensuring cached scaled fonts are invalidated and text elements are refreshed when the preferred content size category changes.
Changes:
- Clear the iOS
FontManagerfont cache whenContentSizeCategoryChangedis raised. - Detect preferred content size category changes in
PageViewController.TraitCollectionDidChangeand refresh fonts/measurements across the current visual tree for autoscaled text.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Core/src/Platform/iOS/PageViewController.cs | Refreshes autoscaled text fonts + invalidates measure when Dynamic Type category changes. |
| src/Core/src/Fonts/FontManager.iOS.cs | Clears the cached UIFont instances on Dynamic Type category change so new scaled fonts are generated. |
🤖 AI Summary📊 Expand Full Review —
|
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #34445 | Clear FontManager cache on ContentSizeCategoryChanged + recursively refresh autoscaled fonts in PageViewController.TraitCollectionDidChange | ⏳ PENDING (Gate) | FontManager.iOS.cs, PageViewController.cs |
Original PR |
🚦 Gate — Test Verification
Gate Result: ⚠️ SKIPPED
Platform: iOS
Mode: N/A — No tests found in PR
Reason: PR #34445 contains no test files. Files changed:
src/Core/src/Fonts/FontManager.iOS.cs(implementation only)src/Core/src/Platform/iOS/PageViewController.cs(implementation only)
No files exist in TestCases.HostApp or TestCases.Shared.Tests.
- Tests FAIL without fix:
⚠️ N/A (no tests to run) - Tests PASS with fix:
⚠️ N/A (no tests to run)
Recommendation: Use write-tests-agent to create UI tests for issue #34307 (Font autoscaling realtime update on iOS).
🔧 Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix (claude-sonnet-4.6) | Bypass cache for auto-scaled fonts (never cache them; check AutoScalingEnabled in GetFont and call factory directly) |
🚫 Blocked (no test) | FontManager.iOS.cs, PageViewController.cs |
Proactive approach; simpler than PR |
| 2 | try-fix (claude-opus-4.6) | Dual-cache (_fonts + _scaledFonts), add ClearScaledFontCache(), PageViewController calls via DI |
🚫 Blocked (no test) | FontManager.iOS.cs, PageViewController.cs |
No observer leak; selective invalidation |
| PR | PR #34445 | ObserveContentSizeCategoryChanged clears whole cache + recursive visual-tree refresh in PageViewController |
FontManager.iOS.cs, PageViewController.cs |
Has observer token leak issue |
Attempt 1 (claude-sonnet-4.6)
Approach: Bypass font cache for auto-scaled fonts proactively (no observer in FontManager)
Key Insight: Auto-scaled fonts call UIFontMetrics.DefaultMetrics.GetScaledFont(), whose output depends on UIContentSizeCategory. Caching them is semantically incorrect — they should be recreated fresh. The PR clears the cache reactively; this fix removes caching for auto-scaled fonts entirely.
Different from PR: PR uses ObserveContentSizeCategoryChanged to clear ALL cached fonts. This approach never caches auto-scaled fonts.
Result: 🚫 Blocked — No UI test available to empirically verify.
Attempt 2 (claude-opus-4.6)
Approach: Dual-cache architecture — split _fonts (non-scaled) and _scaledFonts (auto-scaled); add ClearScaledFontCache() on FontManager; PageViewController resolves FontManager via DI and calls it on trait change. No observer subscription.
Different from PR: No observer (eliminates leak), no full cache clear, selective invalidation of only auto-scaled fonts. Also different from Attempt 1 (still caches auto-scaled fonts between changes).
Result: 🚫 Blocked — No UI test available to empirically verify.
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| claude-sonnet-4.6 | 2 | Yes | Handler-level subscription: each handler (LabelHandler, EntryHandler etc.) subscribes to UIContentSizeCategoryDidChangeNotification directly and re-maps its own font property. No tree walk needed. |
| claude-opus-4.6 | 2 | Yes | Include UIApplication.SharedApplication.PreferredContentSizeCategory in font cache KEY — lookups naturally miss after Dynamic Type change; no observers, no clearing, no tree walks. |
Note: Both cross-pollination ideas were NOT separately implemented as try-fix attempts since all attempts result in Blocked (no test exists to verify). They are documented for informational purposes.
Exhausted: Yes (2 models × Round 1, cross-pollination complete)
Selected Fix: PR's Fix — it is the only empirically-tested candidate (the PR author tested on iOS). However, it has a known issue: the observer token from ObserveContentSizeCategoryChanged is not retained/disposed, creating a potential memory leak. Recommend REQUEST CHANGES to fix the observer token lifecycle.
📋 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Phase Status
| Phase | Status | Notes |
|---|---|---|
| Pre-Flight | ✅ COMPLETE | Issue #34307, 2 implementation files, 0 test files |
| Gate | No tests in PR — cannot verify bug is caught | |
| Try-Fix | ✅ COMPLETE | 2 attempts, 0 passing (all Blocked — no test available) |
| Report | ✅ COMPLETE |
Summary
PR #34445 fixes a real iOS bug where FontManager caches UIFont instances keyed by Font struct. When the user changes Dynamic Type at runtime, the cache key doesn't change, so the stale scaled font is returned until app restart. The PR correctly identifies and addresses this by:
- Registering a
ContentSizeCategoryChangedobserver inFontManagerto clear the cache - Detecting
PreferredContentSizeCategorychanges inPageViewController.TraitCollectionDidChange - Recursively invalidating auto-scaled text elements via
InvalidateFontsOnContentSizeChanged
The fix approach is sound and the PR author has manually tested on iOS. However, there is one confirmed code quality issue that needs to be addressed before merge.
Root Cause
FontManager.iOS.cs caches scaled UIFont instances in a ConcurrentDictionary<Font, UIFont>. The Font struct key does not include the current UIContentSizeCategory. When the user changes Dynamic Type, the Font key is unchanged, so _fonts.GetOrAdd(font, factory) returns the stale cached font instead of creating a new one with the updated scaling.
Fix Quality
What's Good:
- Correct two-pronged approach: clear stale cache + refresh live UI elements
- Uses
ITextStyle.Font.AutoScalingEnabledguard to avoid unnecessary updates - Recursive tree walk via
IVisualTreeElement.GetVisualChildren()is the right approach for pushing mapper updates - Correctly handles
previousTraitCollection is not nullguard
Issue That Requires Change:
Observer memory leak in FontManager.iOS.cs — UIApplication.Notifications.ObserveContentSizeCategoryChanged(...) returns a NSObject observer token. The PR discards this token (no variable assigned), which means:
- The observer is never unregistered
- The closure captures
_fonts(henceFontManagerinstance), preventing GC - In test environments that create
FontManagerdirectly, this leaks per-instance
Fix: Store the returned NSObject in an instance field, implement IDisposable, and call _contentSizeCategoryObserver?.Dispose() in Dispose().
Example:
// In class fields:
NSObject? _contentSizeCategoryObserver;
// In constructor:
_contentSizeCategoryObserver = UIApplication.Notifications.ObserveContentSizeCategoryChanged(
(sender, args) => _fonts.Clear());
// In Dispose():
_contentSizeCategoryObserver?.Dispose();
_contentSizeCategoryObserver = null;Minor Concern (non-blocking):
InvalidateFontsOnContentSizeChangedis called regardless of whetherCurrentViewitself has auto-scaled fonts at the top level. This is fine for correctness but slightly wasteful if the page has no auto-scaled fonts at all (the tree walk still occurs).
Alternative Approaches Found in Try-Fix
Two alternative approaches were explored (both Blocked due to no tests):
-
Bypass caching for auto-scaled fonts (Attempt 1): Never cache auto-scaled fonts at all — check
font.AutoScalingEnabledinGetFontand callfactory(font)directly. Semantically cleaner; eliminates the observer entirely. Downside: minor per-call overhead since auto-scaled fonts are never reused. -
Dual-cache + selective invalidation (Attempt 2): Split cache into
_fonts(non-scaled) and_scaledFonts(auto-scaled); addClearScaledFontCache()called fromPageViewControllervia DI. No observer, no global clear, selective invalidation only.
Cross-pollination surfaced two more ideas: handler-level subscription per-element, and including UIContentSizeCategory in the cache key. All alternatives avoid the observer token leak but none are implemented in the current PR.
Verdict
The PR's logic is correct and the approach is valid. The one required change is fixing the observer token lifecycle to prevent memory leaks. This is a straightforward fix. Once addressed, the PR is ready to merge.
Result: FontManager.iOS.cs (store and dispose the NSObject returned by ObserveContentSizeCategoryChanged).
📋 Expand PR Finalization Review
PR #34445 Finalization Review
PR: #34445 - [iOS] Fix Font autoscaling does not work in realtime
Author: HarishwaranVijayakumar
Labels: platform/ios, community ✨, area-controls-label, partner/syncfusion, s/agent-reviewed, s/agent-changes-requested, s/agent-gate-failed
Files Changed: 2 (FontManager.iOS.cs, PageViewController.cs)
Phase 1: Title & Description Review
Title: ⚠️ Minor Improvement Available
Current: [iOS] Fix Font autoscaling does not work in realtime
Assessment: The title is functional and has the correct platform prefix, but "does not work in realtime" reads like a bug description rather than a fix description. It's a bit verbose.
Recommended: [iOS] FontManager: Fix Dynamic Type font scaling not updating in realtime
Reasons:
- Adds
FontManager:component prefix for searchability in git history - "not updating" is more concise than "does not work"
- "Dynamic Type" is the Apple API term — helps future agents searching for Dynamic Type issues
Description: ✅ Good — Minor Addition Needed
Quality Assessment:
| Indicator | Assessment |
|---|---|
| NOTE block | ✅ Present at top |
| Root cause | ✅ Clear — cache key doesn't change, so stale UIFont is returned |
| Description of Change | ✅ Excellent — file-by-file breakdown with diffhunk links and specific details |
| Issues Fixed | ✅ Fixes #34307 present |
| Platforms Tested |
Platforms Tested Inconsistency:
The PR title says [iOS] and the fix is in iOS-specific files, yet Windows and Android are checked in the "Tested" section. The intent seems to be "verified no regression on those platforms" rather than "fix applies there." Consider clarifying this in the description. Also, issue #34307 mentions "iOS, Android" as affected platforms — but this PR only addresses iOS. The Android fix (if needed) would be separate.
Only addition needed:
- ✅ NOTE block is already present
⚠️ Clarify that Windows/Android checkmarks mean "no regression" not "fix applies"
Overall: The description is well-written with excellent technical depth. Keep it as-is with minor clarification.
Phase 2: Code Review
🔴 Critical Issues
Observer Token Not Retained or Disposed
- File:
src/Core/src/Fonts/FontManager.iOS.cs, line 47 - Problem:
UIApplication.Notifications.ObserveContentSizeCategoryChanged(...)returns anNSObjecttoken. This token must be stored and disposed/removed to avoid memory leaks. As currently written:- Every
FontManagerinstance registers a permanent observer - The closure captures
_fonts(which refers to theFontManagerinstance) — keeping theFontManageralive even after it should be eligible for GC FontManagerdoes not implementIDisposable, so there is no cleanup path- In tests that create
FontManagerdirectly, each test creates another leak
- Every
- This was already flagged by the automated Copilot reviewer (
copilot-pull-request-reviewercomment, unresolved) - Recommendation: Store the returned token in a field and dispose it. The cleanest approach is to implement
IDisposableonFontManager:
// Field:
NSObject? _contentSizeCategoryObserver;
// In constructor:
_contentSizeCategoryObserver = UIApplication.Notifications
.ObserveContentSizeCategoryChanged((sender, args) => _fonts.Clear());
// Add IDisposable and Dispose():
public void Dispose()
{
_contentSizeCategoryObserver?.Dispose();
_contentSizeCategoryObserver = null;
}Alternatively, if FontManager is always registered as a singleton in DI, the practical leak is bounded to one instance per app — but this still doesn't clean up on app shutdown and would break unit tests that instantiate FontManager directly.
🟡 Suggestions
TraitCollectionDidChange Notification vs. Direct Observer
The PR uses two mechanisms to handle content size category changes:
UIApplication.Notifications.ObserveContentSizeCategoryChangedinFontManager(clears cache)TraitCollectionDidChangeinPageViewController(re-applies fonts to views)
These work together correctly — the cache is cleared first (via the notification center callback), then trait collection change fires and re-fetches fonts from the now-empty cache. Both happen on the main thread, so ordering is reliable. This design is acceptable.
However, the redundancy should be noted: if only one PageViewController is active (most common case), this is fine. If multiple PageViewController instances are active simultaneously (e.g., multiple windows or split views), each will call InvalidateFontsOnContentSizeChanged independently — which is correct behavior (each window's view tree needs to be updated). ✅
Recursion Depth for InvalidateFontsOnContentSizeChanged
The method recurses through the entire visual tree. For deeply nested or very large view hierarchies, this could be slow — but this concern is no different from other visual tree traversals in MAUI (e.g., theme change propagation), and it only fires when the user explicitly changes system font size. Acceptable.
CurrentView as IView — Null Case
PageViewController calls InvalidateFontsOnContentSizeChanged(CurrentView as IView) — if CurrentView is not IView (which should be rare), it silently no-ops. The null guard at the top of InvalidateFontsOnContentSizeChanged handles this correctly. ✅
✅ Looks Good
static void InvalidateFontsOnContentSizeChangedis correctly markedstatic— it has no instance dependencies. ✅- The
ITextStyle { Font.AutoScalingEnabled: true }pattern check is precise — only views that opted into auto-scaling are updated, avoiding unnecessary mapper invocations. ✅ view.Handler.UpdateValue(nameof(ITextStyle.Font))correctly re-runs the font mapper. ✅view.InvalidateMeasure()ensures layout re-runs after font size change. ✅- The
previousTraitCollection.PreferredContentSizeCategory != TraitCollection.PreferredContentSizeCategoryguard correctly filtersTraitCollectionDidChangeto only act on content size category changes (not dark mode, display scale, etc.). ✅ if (previousTraitCollection is not null &&guard prevents NPE. ✅
Summary
| Category | Assessment |
|---|---|
| Title | |
| Description | ✅ Good quality — keep as-is with minor platform clarification |
| NOTE block | ✅ Present |
| Issue link | ✅ Fixes #34307 |
| Code quality | 🔴 Critical: observer token not disposed (already flagged) |
| Logic correctness | ✅ The fix logic is sound |
| Edge cases | ✅ Null guards in place |
Action Items Before Merge
- 🔴 Must Fix: Retain and dispose the
NSObjectreturned byObserveContentSizeCategoryChanged. The unresolvedcopilot-pull-request-reviewercomment on this is blocking. ⚠️ Recommend: Clarify in the description whether Windows/Android checkmarks mean "no regression" vs "fix applies."- Optional: Improve title to include
FontManager:component prefix for better git searchability.
kubaflo
left a comment
There was a problem hiding this comment.
Could you please apply the ai's suggestions?
Addressed the AI suggestion. |
This comment has been minimized.
This comment has been minimized.
kubaflo
left a comment
There was a problem hiding this comment.
Could you please apply the AI's suggestions?
This comment has been minimized.
This comment has been minimized.
I have reviewed and addressed the AI suggestion. |
|
/review -b feature/enhanced-reviewer |
|
/review -b feature/enhanced-reviewer -p ios |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please check the ai's suggestions?
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@HarishwaranVijayakumar — new AI review results are available based on this last commit:
58d55bf. To request a fresh review after new comments or commits, comment/review rerun.
🚀 Next Steps — alternative fix proposed (try-fix-1)
Automated review — alternative fix proposed
The expert-reviewer evaluation compared the PR fix against automatically generated candidates and selected try-fix-1 as the strongest fix.
Why: try-fix-1 wins because it is the only concrete, compile-validated candidate that avoids both the PR's notification-ordering race and the page-level visual-tree coverage gap for realized item-template text controls. The PR gate was inconclusive rather than failing, but the raw PR still has unresolved major review findings.
Please consider applying the candidate diff below (or use it as guidance). Once you push an update, this workflow will re-trigger and re-evaluate.
Candidate diff (try-fix-1)
diff --git a/src/Core/src/Fonts/FontManager.iOS.cs b/src/Core/src/Fonts/FontManager.iOS.cs
index 0bfd45a3e9..8d19afbfb1 100644
--- a/src/Core/src/Fonts/FontManager.iOS.cs
+++ b/src/Core/src/Fonts/FontManager.iOS.cs
@@ -75,6 +75,10 @@ namespace Microsoft.Maui
var size = GetFontSize(font, defaultFont);
if (size != font.Size)
font = font.WithSize(size);
+
+ if (font.AutoScalingEnabled)
+ return factory(font);
+
return _fonts.GetOrAdd(font, factory);
}
diff --git a/src/Core/src/Platform/iOS/LabelExtensions.cs b/src/Core/src/Platform/iOS/LabelExtensions.cs
index 65b531d63e..29c67762b6 100644
--- a/src/Core/src/Platform/iOS/LabelExtensions.cs
+++ b/src/Core/src/Platform/iOS/LabelExtensions.cs
@@ -29,6 +29,7 @@ namespace Microsoft.Maui.Platform
{
var uiFont = fontManager.GetFont(textStyle.Font, defaultSize);
platformLabel.Font = uiFont;
+ platformLabel.AdjustsFontForContentSizeCategory = textStyle.Font.AutoScalingEnabled;
}
public static void UpdateHorizontalTextAlignment(this UILabel platformLabel, ILabel label)
diff --git a/src/Core/src/Platform/iOS/TextFieldExtensions.cs b/src/Core/src/Platform/iOS/TextFieldExtensions.cs
index 107160fb73..89438c895c 100644
--- a/src/Core/src/Platform/iOS/TextFieldExtensions.cs
+++ b/src/Core/src/Platform/iOS/TextFieldExtensions.cs
@@ -121,6 +121,7 @@ namespace Microsoft.Maui.Platform
{
var uiFont = fontManager.GetFont(textStyle.Font, UIFont.LabelFontSize);
textField.Font = uiFont;
+ textField.AdjustsFontForContentSizeCategory = textStyle.Font.AutoScalingEnabled;
}
public static void UpdateReturnType(this UITextField textField, IEntry entry)
diff --git a/src/Core/src/Platform/iOS/TextViewExtensions.cs b/src/Core/src/Platform/iOS/TextViewExtensions.cs
index 5c9594fad5..7eaff1fb52 100644
--- a/src/Core/src/Platform/iOS/TextViewExtensions.cs
+++ b/src/Core/src/Platform/iOS/TextViewExtensions.cs
@@ -66,6 +66,7 @@ namespace Microsoft.Maui.Platform
var font = textStyle.Font;
var uiFont = fontManager.GetFont(font, UIFont.LabelFontSize);
textView.Font = uiFont;
+ textView.AdjustsFontForContentSizeCategory = font.AutoScalingEnabled;
}
public static void UpdateIsReadOnly(this UITextView textView, IEditor editor)
🗂️ Review Sessions — click to expand
🧪 Gate — Test Before & After Fix
Gate Result: ⚠️ INCONCLUSIVE
Platform: IOS
⚠️ verify-tests-fail.ps1exited before writing a verification report. Diagnostics below.
Exit code: 3
Likely cause:
- Test detection failed — no runnable tests were found in the PR diff.
Gate output log (last 60 lines)
📁 Output directory: CustomAgentLogsTmp/PRState/34445/PRAgent/gate/verify-tests-fail
🔍 Detecting base branch and merge point...
No PR detected, scanning remote branches for closest base...
✅ Base branch: main (via closest-merge-base)
✅ Merge base commit: 4567a055
(1 commits ahead of main)
╔═══════════════════════════════════════════════════════════╗
║ FULL VERIFICATION MODE ║
╠═══════════════════════════════════════════════════════════╣
║ Fix files detected - will verify: ║
║ 1. Tests FAIL without fix ║
║ 2. Tests PASS with fix ║
╚═══════════════════════════════════════════════════════════╝
✅ Fix files (4):
- src/Core/src/Fonts/FontManager.iOS.cs
- src/Core/src/Platform/iOS/PageViewController.cs
- src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
- src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt
🔍 Auto-detecting test filter from changed test files...
⚠️ No tests detected in this PR.
Searched for: UI tests, unit tests, XAML tests, device tests
Consider adding tests via write-tests-agent.
🛫 Pre-Flight — Context & Validation
Issue: #34307 - Font autoscaling does not work in realtime
PR: #34445 - [iOS] Fix Font autoscaling does not work in realtime
Platforms Affected: iOS, MacCatalyst by .iOS.cs compilation; issue was verified on iOS and not reproduced on Android.
Files Changed: 2 implementation, 0 test
Key Findings
- Numeric
FontSizevalues are scaled at app startup but do not update while the app remains running after iOS Dynamic Type/content-size-category changes. - Root cause is stale
UIFontcaching:FontManager.iOS.cscachesUIFontvalues byFont, but the key does not encode the current content-size category. - Current PR fix clears the iOS font cache via
ObserveContentSizeCategoryChangedand recursively refreshes autoscaledITextStyleviews fromPageViewController.TraitCollectionDidChange. - Prior expert review found unresolved risks: the visual-tree walk may miss realized CollectionView/ListView cells, and cache clearing relies on notification ordering before trait refresh.
- The PR adds no automated tests; the provided gate result is inconclusive due to environment/build issues and was not rerun.
Code Review Summary
Verdict: NEEDS_CHANGES
Confidence: medium
Errors: 2 | Warnings: 2 | Suggestions: 0
Key code review findings:
- ❌
PageViewController.cs:114visual-tree recursion can miss realized item-template text views such as CollectionView/ListView cells. - ❌
PageViewController.cs:83-86depends onFontManager.iOS.cs:49notification clearing cache before trait refresh. ⚠️ FontManager.iOS.cs:193exposes publicDispose()solely for observer cleanup.⚠️ No focused regression coverage for issue #34307.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #34445 | Clear FontManager cache on ContentSizeCategoryChanged + recursively refresh autoscaled fonts in PageViewController.TraitCollectionDidChange |
FontManager.iOS.cs, PageViewController.cs, PublicAPI |
Original PR; gate handled separately and not rerun. |
🔬 Code Review — Deep Analysis
Code Review — PR #34445
Independent Assessment
What this changes: The PR changes iOS/MacCatalyst font scaling behavior by clearing FontManager's cached UIFont instances when Dynamic Type changes and then walking the current page's MAUI visual tree from PageViewController.TraitCollectionDidChange to re-run ITextStyle.Font mappers and invalidate measure for autoscaled text views.
Inferred motivation: Numeric FontSize values are scaled correctly at startup but stale while the app remains running because FontManager caches scaled UIFont values under an unchanged Font key.
Reconciliation with PR Narrative
Author claims: PR #34445 fixes issue #34307, "Font autoscaling does not work in realtime", by clearing cached fonts on ContentSizeCategoryChanged and refreshing all autoscaled text elements during iOS trait changes.
Agreement/disagreement: The root cause matches the code: UIFontMetrics.DefaultMetrics.GetScaledFont() depends on the current content size category, while _fonts is keyed only by Font. The current PR approach is plausible for simple page hierarchies, but expert review found it relies on notification-before-trait ordering and can miss realized templated item views such as CollectionView/ListView cells.
Prior Review Reconciliation
| Prior ❌ Error Finding | Source | Status | Evidence |
|---|---|---|---|
Observer token from ObserveContentSizeCategoryChanged was not retained/disposed, leaking FontManager |
Copilot inline review | ✅ Fixed / transformed | Current PR stores _contentSizeCategoryObserver and disposes it, but exposes public Dispose() to do so. |
| Visual tree walk misses realized templated item views such as CollectionView/ListView cells | MauiBot inline review | ❌ Unresolved | Current PR still walks IVisualTreeElement.GetVisualChildren() from CurrentView; no handler/platform-view notification path was added. |
Trait callback may refresh before FontManager notification clears cache |
MauiBot inline review | ❌ Unresolved / disputed | Author reported current iOS notification ordering clears first, but current code still depends on separate callbacks firing in that order. |
| No automated regression coverage | MauiBot inline review | ❌ Unresolved | PR changes implementation and PublicAPI files only; no test files are present. |
Blast Radius Assessment
- Runs for all instances: Yes on iOS/MacCatalyst
FontManagerconstruction and everyPageViewController.TraitCollectionDidChangefor content-size changes. - Startup impact: Low direct startup impact, but the notification observer is registered for every iOS
FontManagerinstance. - Static/shared state: No new static state;
_fontscache behavior changes globally for iOS/MacCatalyst apps.
CI Status
- Required-check result: Undetermined locally;
ghCLI is unauthenticated in this environment, and the user-provided gate result was inconclusive due to build/environment error. - Classification: Undetermined; do not treat gate as a failing fix per prompt.
- Action taken: Confidence capped; code reviewed on merits and candidates were compile-validated with local iOS Core builds where possible.
Findings
❌ Error — Visual-tree refresh does not reach all live text handlers
PageViewController.cs:114 recurses through IVisualTreeElement.GetVisualChildren(), which can miss realized item-template views owned by native item controllers. A visible CollectionView cell containing a Label FontAutoScalingEnabled="True" FontSize="18" can keep the old font until recycled.
❌ Error — Cache refresh ordering depends on separate UIKit callbacks
PageViewController.cs:83-86 assumes FontManager.iOS.cs:49 has already cleared _fonts. If TraitCollectionDidChange wins the race, UpdateValue(nameof(ITextStyle.Font)) can retrieve a stale cached UIFont, and the later cache clear does not trigger a second mapper update.
⚠️ Warning — Public Dispose() exposes cleanup as public API
FontManager.iOS.cs:193 adds callable public API solely for observer disposal, requiring iOS/MacCatalyst PublicAPI entries. An explicit IDisposable.Dispose() or avoiding the observer entirely would keep cleanup internal.
⚠️ Warning — No automated regression coverage
The PR has no focused iOS regression test or test seam proving numeric FontSize values update without app restart after content-size-category changes.
Failure-Mode Probing
- CollectionView item template: Current PR likely misses visible realized cells because the recursive MAUI visual-tree walk does not enumerate every native realized cell handler.
- Trait/notification ordering inversion: Current PR can refresh views from stale
_fontsif trait propagation occurs before notification delivery. - Premature
FontManager.Dispose(): Public API allows app code to dispose the DI singleton and disable future cache invalidation without replacing the service. - Large page with many text elements: Current PR invalidates measure per text element, potentially causing a burst of layout invalidations.
Verdict: NEEDS_CHANGES
Confidence: medium
Summary: The current PR addresses the basic stale-font-cache root cause but leaves two correctness gaps: realized item-template handlers and cross-callback ordering. Candidate exploration found alternatives that avoid some or all of these issues.
🛠️ Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix-1 | Native UIKit AdjustsFontForContentSizeCategory on text controls + do not cache autoscaled fonts |
✅ PASS (iOS Core build) | 4 files | Best candidate: avoids observer lifecycle, ordering race, public API, and page tree coverage limits for live native controls; needs runtime/device validation for MAUI layout invalidation. |
| 2 | try-fix-2 | Add content-size category to autoscaled font cache key + page tree refresh | ✅ PASS (iOS Core build after one compile fix) | 2 files | Fixes cache-ordering and public API risks, but still misses realized item-template cells. |
| 3 | try-fix-3 | Synchronously clear autoscaled cache entries in TraitCollectionDidChange before page tree refresh |
✅ PASS (iOS Core build) | 2 files | Smallest PR-like alternative; fixes ordering/public API/broad-clear issues, but still misses realized item-template cells. |
| PR | PR #34445 | Notification clears whole font cache + PageViewController recursively refreshes autoscaled text views |
4 files | Original PR; unresolved concerns: callback ordering, visual-tree coverage, public Dispose(), no tests. |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| maui-expert-reviewer | 1 | Yes | Native adjustsFontForContentSizeCategory plus avoid caching autoscaled fonts. Implemented as candidate 1. |
| maui-expert-reviewer | 1 | Yes | Include current content-size category in cache key. Implemented as candidate 2. |
| maui-expert-reviewer | 1 | Yes | Single callback owns cache clear and view refresh. Implemented as candidate 3. |
| maui-expert-reviewer | 1 | Yes, not implemented | Per-handler subscriptions could cover realized cells, but it requires changing every iOS text handler and has higher lifecycle/leak risk than candidate 1. |
Exhausted: Yes — remaining meaningfully different approach is per-handler notification subscriptions, but it is a larger lifecycle-sensitive handler refactor and not preferable to candidate 1 without device tests.
Selected Fix: Candidate #1 — It is the only candidate that addresses the PR's two major correctness gaps together: no stale MAUI font cache and no reliance on a page-level MAUI visual-tree walk to reach live native text controls. It is compile-validated, but still needs runtime iOS device/simulator validation for layout invalidation behavior before it can be called fully verified.
📝 Recommended PR Title & Description
Assessment: ✏️ Recommend updating — the current description accurately explains the submitted PR, but the winning fix is try-fix-1, which removes the FontManager observer and PageViewController visual-tree refresh described in the current metadata.
Recommended title
[iOS] Fonts: Update autoscaled text when Dynamic Type changes
Recommended description
### Issue Details
- When `FontSize` is set on a control, font scaling is correctly applied at app startup based on the system font scaling setting. However, if the user changes the iOS Dynamic Type size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect.
### Root Cause of the issue
- `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.), which does not include the current iOS preferred content size category. Once cached, the same scaled `UIFont` can be returned after Dynamic Type changes.
### Description of Change
Dynamic Type font scaling improvements:
* `src/Core/src/Fonts/FontManager.iOS.cs`: Avoid caching autoscaled fonts so requests after a Dynamic Type change generate a `UIFont` using the current preferred content size category.
* `src/Core/src/Platform/iOS/LabelExtensions.cs`: Set `UILabel.AdjustsFontForContentSizeCategory` based on `Font.AutoScalingEnabled` so live labels participate in UIKit Dynamic Type updates.
* `src/Core/src/Platform/iOS/TextFieldExtensions.cs`: Set `UITextField.AdjustsFontForContentSizeCategory` based on `Font.AutoScalingEnabled`.
* `src/Core/src/Platform/iOS/TextViewExtensions.cs`: Set `UITextView.AdjustsFontForContentSizeCategory` based on `Font.AutoScalingEnabled`.
This avoids relying on a page-level visual-tree walk and reaches live native text controls, including controls hosted in realized item templates.
### Issues Fixed
Fixes #34307
### Tested the behaviour in the following platforms
- [ ] Windows
- [ ] Android
- [x] iOS
- [ ] Mac
| Before | After |
|----------|----------|
| <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> |
🏁 Report — Final Recommendation
Comparative Analysis — PR #34445
Candidates
| Rank | Candidate | Result | Assessment |
|---|---|---|---|
| 1 | try-fix-1 |
✅ PASS — iOS Core build | Best concrete fix. Avoids the PR's notification-ordering race by not caching autoscaled fonts, and uses UIKit's live Dynamic Type support on UILabel, UITextField, and UITextView, which is more likely to reach realized item-template cells than a page-level MAUI visual-tree walk. |
| 2 | pr-plus-reviewer |
✅ PASS by equivalent concrete implementation (try-fix-1) |
Applying reviewer feedback points to the same design as try-fix-1: avoid stale autoscaled cache entries and use a handler/native text-control path. It is ranked below try-fix-1 only because try-fix-1 is the concrete STEP 5a artifact with a recorded diff and build result. |
| 3 | try-fix-3 |
✅ PASS — iOS Core build | Smallest safe PR-like alternative. It fixes the callback-ordering issue and avoids new public Dispose() API by clearing autoscaled cache entries synchronously before the page walk, but it still has the same realized templated-cell coverage gap as the PR. |
| 4 | try-fix-2 |
✅ PASS — iOS Core build after compile fix | Improves cache correctness by adding content-size category to the autoscaled font cache key and avoids the observer/public API concern, but still depends on the page visual-tree walk and can miss realized item-template cells. |
| 5 | pr |
Addresses the basic stale cache root cause for simple page hierarchies, but expert review found two major correctness risks: separate notification/trait ordering and incomplete coverage for realized templated cells. |
No candidate failed regression tests. The submitted PR's gate was inconclusive because no runnable tests were detected/buildable in this environment; per instruction, that is not treated as a failing fix.
Key tradeoffs
try-fix-1 changes the fix from page-level refresh to native Dynamic Type participation for live iOS text controls. This avoids adding a public FontManager.Dispose() API, avoids observer lifecycle concerns, and avoids depending on UIKit callback ordering. Its remaining risk is runtime layout invalidation behavior for wrapping text and virtualized cells, which still needs simulator/device validation because the gate could not verify the scenario.
try-fix-2 and try-fix-3 are safer than the raw PR for cache invalidation, but both preserve the page-tree traversal and therefore remain vulnerable to the most important coverage gap. The raw PR ranks last because it has both the ordering dependency and the traversal limitation.
Winner
try-fix-1 is the single winning candidate. It is the only concrete, compile-validated candidate that addresses both major expert-review correctness findings instead of only improving the PR's cache invalidation mechanics.
|
Tested try-fix-1 approach — it causes text overlap because AdjustsFontForContentSizeCategory only updates the native font without triggering MAUI's layout system (InvalidateMeasure()). The current PR approach is correct because:
|
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - When the FontSize is set on a control, font scaling is correctly applied at app startup based on the system's font scaling setting. However, if the user changes the system font size while the app is running, the font does not dynamically update — the app must be killed and restarted for the new font size to take effect. ### Root Cause of the issue - `FontManager.iOS.cs` caches scaled `UIFont` instances in a `ConcurrentDictionary<Font, UIFont>`. The cache key is the `Font` struct (family, size, weight, etc.).Once cached, the same `UIFont` is returned on every subsequent request — even after the user changes the Dynamic Type size — because the `Font` struct key hasn't changed. ### Description of Change Dynamic Type font scaling improvements: * [`src/Core/src/Fonts/FontManager.iOS.cs`](diffhunk://#diff-a03afeb4430f582df766a7060aaba9ba77d714108485b81d726dec246706a65aR43-R47): Added an observer for `ContentSizeCategoryChanged` notifications to clear the font cache in `_fonts`, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R78-R87): In `TraitCollectionDidChange`, added logic to detect changes in the preferred content size category and call `InvalidateFontsOnContentSizeChanged` to update fonts across all text elements in the current view. * [`src/Core/src/Platform/iOS/PageViewController.cs`](diffhunk://#diff-2f30bb28cbc0173a8383e90a546fc0e8f3bc221659b547a4f57591ca5b6a0b83R100-R124): Introduced the `InvalidateFontsOnContentSizeChanged` method, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #34307 ### Tested the behaviour in the following platforms - [x] - Windows - [x] - Android - [x] - iOS - [ ] - Mac | Before | After | |----------|----------| | <video src="https://github.com/user-attachments/assets/e5908baa-dbc8-4b57-9f8b-15b2dbf7dcda"> | <video src="https://github.com/user-attachments/assets/2149acec-9961-45f6-81b0-d13771859304"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
Root Cause of the issue
FontManager.iOS.cscaches scaledUIFontinstances in aConcurrentDictionary<Font, UIFont>. The cache key is theFontstruct (family, size, weight, etc.).Once cached, the sameUIFontis returned on every subsequent request — even after the user changes the Dynamic Type size — because theFontstruct key hasn't changed.Description of Change
Dynamic Type font scaling improvements:
src/Core/src/Fonts/FontManager.iOS.cs: Added an observer forContentSizeCategoryChangednotifications to clear the font cache in_fonts, ensuring new fonts are generated with the correct scaling when the user's preferred content size category changes.src/Core/src/Platform/iOS/PageViewController.cs: InTraitCollectionDidChange, added logic to detect changes in the preferred content size category and callInvalidateFontsOnContentSizeChangedto update fonts across all text elements in the current view.src/Core/src/Platform/iOS/PageViewController.cs: Introduced theInvalidateFontsOnContentSizeChangedmethod, which recursively updates font values and invalidates measurements for all text elements with auto-scaling enabled, ensuring immediate UI updates.Issues Fixed
Fixes #34307
Tested the behaviour in the following platforms
Before.mov
After.mov