Skip to content

Commit 97694b0

Browse files
Address AI concern
1 parent 501eb46 commit 97694b0

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/Core/src/Fonts/FontManager.iOS.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System;
22
using System.Collections.Concurrent;
3+
using Foundation;
34
using Microsoft.Extensions.Logging;
45
using UIKit;
56

67
namespace Microsoft.Maui
78
{
89
/// <inheritdoc/>
9-
public class FontManager : IFontManager
10+
public class FontManager : IFontManager, IDisposable
1011
{
1112
// UIFontWeight[Constant] is internal in Xamarin.iOS but the convertion from
1213
// the public (int-based) enum is not helpful in this case.
@@ -28,6 +29,7 @@ public class FontManager : IFontManager
2829
readonly IFontRegistrar _fontRegistrar;
2930
readonly IServiceProvider? _serviceProvider;
3031

32+
NSObject? _contentSizeCategoryObserver;
3133
UIFont? _defaultFont;
3234

3335
/// <summary>
@@ -44,7 +46,7 @@ public FontManager(IFontRegistrar fontRegistrar, IServiceProvider? serviceProvid
4446
// When the preferred content size category changes (Dynamic Type),
4547
// clear the font cache so subsequent requests create new fonts
4648
// with the current content size category scaling.
47-
UIApplication.Notifications.ObserveContentSizeCategoryChanged((sender, args) => _fonts.Clear());
49+
_contentSizeCategoryObserver = UIApplication.Notifications.ObserveContentSizeCategoryChanged((sender, args) => _fonts.Clear());
4850
}
4951

5052
/// <inheritdoc/>
@@ -188,6 +190,12 @@ UIFont ApplyScaling(Font font, UIFont uiFont)
188190
}
189191
}
190192

193+
public void Dispose()
194+
{
195+
_contentSizeCategoryObserver?.Dispose();
196+
_contentSizeCategoryObserver = null;
197+
}
198+
191199
string? CleanseFontName(string fontName)
192200
{
193201
// First check Alias
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
#nullable enable
1+
#nullable enable
2+
Microsoft.Maui.FontManager.Dispose() -> void
23
override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#nullable enable
2+
Microsoft.Maui.FontManager.Dispose() -> void
23
override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void

0 commit comments

Comments
 (0)