From 03e5d83864d784870f29bb72b89da1826e9fecfc Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 13 Mar 2021 18:34:42 -0300 Subject: [PATCH 01/10] implemented font in editor --- .../src/Handlers/Editor/EditorHandler.Android.cs | 13 ++++++++++++- .../src/Handlers/Editor/EditorHandler.Standard.cs | 1 + src/Core/src/Handlers/Editor/EditorHandler.cs | 1 + src/Core/src/Handlers/Editor/EditorHandler.iOS.cs | 13 ++++++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs index a89d90e92dc4..d62745b8daf7 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs @@ -1,6 +1,8 @@ -using Android.Views; +using System; +using Android.Views; using Android.Views.InputMethods; using AndroidX.AppCompat.Widget; +using Microsoft.Extensions.DependencyInjection; namespace Microsoft.Maui.Handlers { @@ -40,5 +42,14 @@ public static void MapIsTextPredictionEnabled(EditorHandler handler, IEditor edi { handler.TypedNativeView?.UpdateIsTextPredictionEnabled(editor); } + + public static void MapFont(EditorHandler handler, IEditor editor) + { + var services = App.Current?.Services + ?? throw new InvalidOperationException($"Unable to find service provider, the App.Current.Services was null."); + var fontManager = services.GetRequiredService(); + + handler.TypedNativeView?.UpdateFont(editor, fontManager); + } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/Editor/EditorHandler.Standard.cs b/src/Core/src/Handlers/Editor/EditorHandler.Standard.cs index 2f3167ce2c7e..722548b603c2 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.Standard.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.Standard.cs @@ -10,5 +10,6 @@ public static void MapText(IViewHandler handler, IEditor editor) { } public static void MapCharacterSpacing(IViewHandler handler, IEditor editor) { } public static void MapMaxLength(IViewHandler handler, IEditor editor) { } public static void MapIsTextPredictionEnabled(EditorHandler handler, IEditor editor) { } + public static void MapFont(IViewHandler handler, IEditor editor) { } } } \ No newline at end of file diff --git a/src/Core/src/Handlers/Editor/EditorHandler.cs b/src/Core/src/Handlers/Editor/EditorHandler.cs index 25caa2becb3f..69c6b063c2bf 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.cs @@ -8,6 +8,7 @@ public partial class EditorHandler [nameof(IEditor.CharacterSpacing)] = MapCharacterSpacing, [nameof(IEditor.MaxLength)] = MapMaxLength, [nameof(IEditor.IsTextPredictionEnabled)] = MapIsTextPredictionEnabled + [nameof(ILabel.Font)] = MapFont }; public EditorHandler() : base(EditorMapper) diff --git a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs index 7faf1d38feb0..1bc42237448f 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs @@ -1,5 +1,7 @@ -using CoreGraphics; +using CoreGraphics; using Foundation; +using System; +using Microsoft.Extensions.DependencyInjection; using UIKit; namespace Microsoft.Maui.Handlers @@ -75,5 +77,14 @@ bool OnShouldChangeText(UITextView textView, NSRange range, string replacementSt return newLength <= VirtualView.MaxLength; } + + public static void MapFont(EditorHandler handler, IEditor editor) + { + var services = App.Current?.Services ?? + throw new InvalidOperationException($"Unable to find service provider, the App.Current.Services was null."); + var fontManager = services.GetRequiredService(); + + handler.TypedNativeView?.UpdateFont(editor, fontManager); + } } } \ No newline at end of file From 75824d796f3caf5048391d8e00819e0cd18d5224 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 13 Mar 2021 18:34:51 -0300 Subject: [PATCH 02/10] Added PortHandler attribute --- src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs | 1 + src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs index 17d2248a499d..d599b63b1466 100644 --- a/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/EditorRenderer.cs @@ -210,6 +210,7 @@ internal override void OnNativeFocusChanged(bool hasFocus) ElementController.SendCompleted(); } + [PortHandler] protected virtual void UpdateFont() { EditText.Typeface = Element.ToTypeface(); diff --git a/src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs index 400706464178..4c2e80ff2935 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/EditorRenderer.cs @@ -300,6 +300,7 @@ void UpdateEditable() TextView.InputAccessoryView.Hidden = !Element.IsEnabled; } + [PortHandler] protected internal virtual void UpdateFont() { var font = Element.ToUIFont(); From c87ccf635c5b5729d34860dc4aa7a5c5b6b6bd96 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 13 Mar 2021 18:56:11 -0300 Subject: [PATCH 03/10] added tests --- .../Editor/EditorHandlerTests.Android.cs | 29 +++++++++++++++++++ .../Handlers/Editor/EditorHandlerTests.iOS.cs | 26 +++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs index e48bc251bf1d..6fd1d5921696 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Android.Text; using AndroidX.AppCompat.Widget; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Handlers; using Xunit; @@ -34,6 +35,33 @@ public async Task CharacterSpacingInitializesCorrectly() Assert.Equal(xplatCharacterSpacing, values.ViewValue); Assert.Equal(expectedValue, values.NativeViewValue, EmCoefficientPrecision); } + + [Theory(DisplayName = "Font Family Initializes Correctly")] + [InlineData(null)] + [InlineData("monospace")] + [InlineData("Dokdo")] + public async Task FontFamilyInitializesCorrectly(string family) + { + var label = new EditorStub() + { + Text = "Test", + Font = Font.OfSize(family, 10) + }; + + var handler = await CreateHandlerAsync(label); + var nativeEditor = GetNativeEditor(handler); + + var fontManager = App.Services.GetRequiredService(); + + var nativeFont = fontManager.GetTypeface(Font.OfSize(family, 0.0)); + + Assert.Equal(nativeFont, nativeEditor.Typeface); + + if (string.IsNullOrEmpty(family)) + Assert.Equal(fontManager.DefaultTypeface, nativeEditor.Typeface); + else + Assert.NotEqual(fontManager.DefaultTypeface, nativeEditor.Typeface); + } AppCompatEditText GetNativeEditor(EditorHandler editorHandler) => (AppCompatEditText)editorHandler.View; @@ -55,5 +83,6 @@ double GetNativeCharacterSpacing(EditorHandler editorHandler) return -1; } + } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs index 87c308462b38..1246cf7efc03 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Handlers; using UIKit; @@ -33,6 +34,31 @@ public async Task CharacterSpacingInitializesCorrectly() Assert.Equal(xplatCharacterSpacing, values.NativeViewValue); } + [Theory(DisplayName = "Font Family Initializes Correctly")] + [InlineData(null)] + [InlineData("Times New Roman")] + [InlineData("Dokdo")] + public async Task FontFamilyInitializesCorrectly(string family) + { + var editor = new EditorStub() + { + Text = "Test", + Font = Font.OfSize(family, 10) + }; + + var nativeFont = await GetValueAsync(editor, handler => GetNativeEditor(handler).Font); + + var fontManager = App.Services.GetRequiredService(); + + var expectedNativeFont = fontManager.GetFont(Font.OfSize(family, 0.0)); + + Assert.Equal(expectedNativeFont.FamilyName, nativeFont.FamilyName); + if (string.IsNullOrEmpty(family)) + Assert.Equal(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName); + else + Assert.NotEqual(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName); + } + UITextView GetNativeEditor(EditorHandler editorHandler) => (UITextView)editorHandler.View; From 07af564c4a4aaf8dbd473e4bd88623d14469c1f5 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sun, 14 Mar 2021 14:35:09 -0300 Subject: [PATCH 04/10] Added font size test --- .../Editor/EditorHandlerTests.Android.cs | 5 +++++ .../Handlers/Editor/EditorHandlerTests.cs | 16 ++++++++++++++++ .../Handlers/Editor/EditorHandlerTests.iOS.cs | 3 +++ 3 files changed, 24 insertions(+) diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs index 6fd1d5921696..7cedce062c8f 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs @@ -84,5 +84,10 @@ double GetNativeCharacterSpacing(EditorHandler editorHandler) return -1; } + double GetNativeUnscaledFontSize(EditorHandler editorHandler) + { + var textView = GetNativeEditor(editorHandler); + return textView.TextSize / textView.Resources.DisplayMetrics.Density; + } } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs index 6a39eb71b892..2b622af3f9ce 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs @@ -121,5 +121,21 @@ await ValidatePropertyUpdatesValue( setValue, unsetValue); } + + [Theory(DisplayName = "Font Size Initializes Correctly")] + [InlineData(1)] + [InlineData(10)] + [InlineData(20)] + [InlineData(100)] + public async Task FontSizeInitializesCorrectly(int fontSize) + { + var editor = new EditorStub() + { + Text = "Test", + Font = Font.OfSize("Arial", fontSize) + }; + + await ValidatePropertyInitValue(editor, () => editor.Font.FontSize, GetNativeUnscaledFontSize, editor.Font.FontSize); + } } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs index 1246cf7efc03..d7285002a352 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs @@ -73,5 +73,8 @@ double GetNativeCharacterSpacing(EditorHandler editorHandler) bool GetNativeIsTextPredictionEnabled(EditorHandler editorHandler) => GetNativeEditor(editorHandler).AutocorrectionType == UITextAutocorrectionType.Yes; + + double GetNativeUnscaledFontSize(EditorHandler editorHandler) => + GetNativeEditor(editorHandler).Font.PointSize; } } \ No newline at end of file From 5edae5741b3ef00a0265d59a00b3d9ca006ba81b Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sun, 14 Mar 2021 14:53:22 -0300 Subject: [PATCH 05/10] added editor into MainPage --- src/Controls/samples/Controls.Sample/Pages/MainPage.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controls/samples/Controls.Sample/Pages/MainPage.cs b/src/Controls/samples/Controls.Sample/Pages/MainPage.cs index 1d11beba2426..e0211b66a0dc 100644 --- a/src/Controls/samples/Controls.Sample/Pages/MainPage.cs +++ b/src/Controls/samples/Controls.Sample/Pages/MainPage.cs @@ -90,6 +90,7 @@ void SetupMauiLayout() verticalStack.Add(new Editor { Text = "Editor" }); verticalStack.Add(new Editor { Text = "Lorem ipsum dolor sit amet", MaxLength = 10 }); verticalStack.Add(new Editor { Text = "Predictive Text Off", IsTextPredictionEnabled = false }); + verticalStack.Add(new Editor { Text = "Lorem ipsum dolor sit amet", FontSize = 10, FontFamily = "dokdo_regular"}); var entry = new Entry(); entry.TextChanged += (sender, e) => From 1e10ae6bd287f4cd14c5373d4a1c2869d196a3f1 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 18 Mar 2021 19:13:55 -0300 Subject: [PATCH 06/10] code review --- src/Core/src/Handlers/Editor/EditorHandler.cs | 2 +- .../DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core/src/Handlers/Editor/EditorHandler.cs b/src/Core/src/Handlers/Editor/EditorHandler.cs index 69c6b063c2bf..e06b40e176bc 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.cs @@ -8,7 +8,7 @@ public partial class EditorHandler [nameof(IEditor.CharacterSpacing)] = MapCharacterSpacing, [nameof(IEditor.MaxLength)] = MapMaxLength, [nameof(IEditor.IsTextPredictionEnabled)] = MapIsTextPredictionEnabled - [nameof(ILabel.Font)] = MapFont + [nameof(IEditor.Font)] = MapFont }; public EditorHandler() : base(EditorMapper) diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs index 7cedce062c8f..e31014ac1767 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs @@ -42,13 +42,13 @@ public async Task CharacterSpacingInitializesCorrectly() [InlineData("Dokdo")] public async Task FontFamilyInitializesCorrectly(string family) { - var label = new EditorStub() + var editor = new EditorStub() { Text = "Test", Font = Font.OfSize(family, 10) }; - var handler = await CreateHandlerAsync(label); + var handler = await CreateHandlerAsync(editor); var nativeEditor = GetNativeEditor(handler); var fontManager = App.Services.GetRequiredService(); From 7bc4a7768c46d2644103380960e72f1007ef9608 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 18 Mar 2021 23:34:33 -0300 Subject: [PATCH 07/10] fixed merge conflicts --- src/Core/src/Platform/Android/EditTextExtensions.cs | 11 +++++++++++ src/Core/src/Platform/iOS/TextViewExtensions.cs | 6 ++++++ .../Handlers/Editor/EditorHandlerTests.Android.cs | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Android/EditTextExtensions.cs b/src/Core/src/Platform/Android/EditTextExtensions.cs index 30a2d53db260..aa05e90df8b7 100644 --- a/src/Core/src/Platform/Android/EditTextExtensions.cs +++ b/src/Core/src/Platform/Android/EditTextExtensions.cs @@ -121,6 +121,17 @@ public static void UpdateReturnType(this AppCompatEditText editText, IEntry entr editText.ImeOptions = entry.ReturnType.ToNative(); } + public static void UpdateFont(this AppCompatEditText editText, IEditor editor, IFontManager fontManager) + { + var font = editor.Font; + + var tf = fontManager.GetTypeface(font); + editText.Typeface = tf; + + var sp = fontManager.GetScaledPixel(font); + editText.SetTextSize(Android.Util.ComplexUnitType.Sp, sp); + } + internal static void SetInputType(this AppCompatEditText editText, IEntry entry) { editText.InputType = InputTypes.ClassText; diff --git a/src/Core/src/Platform/iOS/TextViewExtensions.cs b/src/Core/src/Platform/iOS/TextViewExtensions.cs index fbb54e953ddf..84e91d6abf73 100644 --- a/src/Core/src/Platform/iOS/TextViewExtensions.cs +++ b/src/Core/src/Platform/iOS/TextViewExtensions.cs @@ -37,5 +37,11 @@ public static void UpdatePredictiveText(this UITextView textView, IEditor editor textView.AutocorrectionType = editor.IsTextPredictionEnabled ? UITextAutocorrectionType.Yes : UITextAutocorrectionType.No; } + + public static void UpdateFont(this UITextView textView, IEditor editor, IFontManager fontManager) + { + var uiFont = fontManager.GetFont(editor.Font); + textView.Font = uiFont; + } } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs index e31014ac1767..af2f834b6cd5 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs @@ -35,7 +35,7 @@ public async Task CharacterSpacingInitializesCorrectly() Assert.Equal(xplatCharacterSpacing, values.ViewValue); Assert.Equal(expectedValue, values.NativeViewValue, EmCoefficientPrecision); } - + [Theory(DisplayName = "Font Family Initializes Correctly")] [InlineData(null)] [InlineData("monospace")] @@ -90,4 +90,4 @@ double GetNativeUnscaledFontSize(EditorHandler editorHandler) return textView.TextSize / textView.Resources.DisplayMetrics.Density; } } -} \ No newline at end of file +} From 4be75d397ad27bc83e795bdceaf569774926d579 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 24 Mar 2021 15:31:13 +0000 Subject: [PATCH 08/10] Fix rebase --- src/Core/src/Handlers/Editor/EditorHandler.Android.cs | 2 +- src/Core/src/Handlers/Editor/EditorHandler.cs | 2 +- src/Core/src/Handlers/Editor/EditorHandler.iOS.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs index d62745b8daf7..fd222bf41211 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs @@ -45,7 +45,7 @@ public static void MapIsTextPredictionEnabled(EditorHandler handler, IEditor edi public static void MapFont(EditorHandler handler, IEditor editor) { - var services = App.Current?.Services + var services = handler.Services ?? throw new InvalidOperationException($"Unable to find service provider, the App.Current.Services was null."); var fontManager = services.GetRequiredService(); diff --git a/src/Core/src/Handlers/Editor/EditorHandler.cs b/src/Core/src/Handlers/Editor/EditorHandler.cs index e06b40e176bc..b0fb4d9be7b2 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.cs @@ -7,7 +7,7 @@ public partial class EditorHandler [nameof(IEditor.Text)] = MapText, [nameof(IEditor.CharacterSpacing)] = MapCharacterSpacing, [nameof(IEditor.MaxLength)] = MapMaxLength, - [nameof(IEditor.IsTextPredictionEnabled)] = MapIsTextPredictionEnabled + [nameof(IEditor.IsTextPredictionEnabled)] = MapIsTextPredictionEnabled, [nameof(IEditor.Font)] = MapFont }; diff --git a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs index 1bc42237448f..d2726d8db69b 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs @@ -80,7 +80,7 @@ bool OnShouldChangeText(UITextView textView, NSRange range, string replacementSt public static void MapFont(EditorHandler handler, IEditor editor) { - var services = App.Current?.Services ?? + var services = handler.Services ?? throw new InvalidOperationException($"Unable to find service provider, the App.Current.Services was null."); var fontManager = services.GetRequiredService(); From 68a1f473e30e24379dd31c7570bb7189f017d12b Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 24 Mar 2021 16:55:35 +0000 Subject: [PATCH 09/10] Fix tests --- .../DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs | 2 +- .../DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs index af2f834b6cd5..a57ffc3b6ea9 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.Android.cs @@ -51,7 +51,7 @@ public async Task FontFamilyInitializesCorrectly(string family) var handler = await CreateHandlerAsync(editor); var nativeEditor = GetNativeEditor(handler); - var fontManager = App.Services.GetRequiredService(); + var fontManager = handler.Services.GetRequiredService(); var nativeFont = fontManager.GetTypeface(Font.OfSize(family, 0.0)); diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs index d7285002a352..c481264375c3 100644 --- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.iOS.cs @@ -46,9 +46,10 @@ public async Task FontFamilyInitializesCorrectly(string family) Font = Font.OfSize(family, 10) }; + var handler = await CreateHandlerAsync(editor); var nativeFont = await GetValueAsync(editor, handler => GetNativeEditor(handler).Font); - var fontManager = App.Services.GetRequiredService(); + var fontManager = handler.Services.GetRequiredService(); var expectedNativeFont = fontManager.GetFont(Font.OfSize(family, 0.0)); From fb024ccaee508a33196d6fea8aeaf0d8b1d5f555 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 24 Mar 2021 17:03:29 +0000 Subject: [PATCH 10/10] Fix message when getting handler.Services --- src/Core/src/Handlers/Editor/EditorHandler.Android.cs | 2 +- src/Core/src/Handlers/Editor/EditorHandler.iOS.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs index fd222bf41211..8f0e58914989 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs @@ -46,7 +46,7 @@ public static void MapIsTextPredictionEnabled(EditorHandler handler, IEditor edi public static void MapFont(EditorHandler handler, IEditor editor) { var services = handler.Services - ?? throw new InvalidOperationException($"Unable to find service provider, the App.Current.Services was null."); + ?? throw new InvalidOperationException($"Unable to find service provider, the handler.Services was null."); var fontManager = services.GetRequiredService(); handler.TypedNativeView?.UpdateFont(editor, fontManager); diff --git a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs index d2726d8db69b..bd9bc039d2a8 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs @@ -81,7 +81,7 @@ bool OnShouldChangeText(UITextView textView, NSRange range, string replacementSt public static void MapFont(EditorHandler handler, IEditor editor) { var services = handler.Services ?? - throw new InvalidOperationException($"Unable to find service provider, the App.Current.Services was null."); + throw new InvalidOperationException($"Unable to find service provider, the handler.Services was null."); var fontManager = services.GetRequiredService(); handler.TypedNativeView?.UpdateFont(editor, fontManager);