From a5f3531aa7acbfe641b1f22e62de96095a6292a7 Mon Sep 17 00:00:00 2001 From: Alberto Aldegheri Date: Sat, 9 Aug 2025 18:00:34 +0200 Subject: [PATCH] Improve label/entry/button mapping perf --- src/Controls/src/Core/Entry/Entry.Mapper.cs | 13 +- src/Controls/src/Core/Entry/Entry.iOS.cs | 9 +- src/Controls/src/Core/Label/Label.Mapper.cs | 12 +- src/Controls/src/Core/Label/Label.iOS.cs | 7 +- .../Button/ButtonControlPage.xaml | 9 +- .../Button/ButtonControlPage.xaml.cs | 15 ++ .../EntryControl/EntryControlPage.xaml | 8 +- .../EntryControl/EntryControlPage.xaml.cs | 17 +++ .../EntryControl/EntryOptionsPage.xaml | 1 + .../FeatureMatrix/Label/LabelControlPage.xaml | 6 +- .../Label/LabelControlPage.xaml.cs | 8 ++ .../Tests/FeatureMatrix/ButtonFeatureTests.cs | 41 ++++++ .../Tests/FeatureMatrix/EntryFeatureTests.cs | 111 +++++++++++++++ .../Tests/FeatureMatrix/LabelFeatureTests.cs | 134 ++++++++++++++++++ src/Core/src/Handlers/Button/ButtonHandler.cs | 2 +- .../src/Handlers/Button/ButtonHandler.iOS.cs | 7 +- src/Core/src/Handlers/Entry/EntryHandler.cs | 22 +-- .../src/Handlers/Entry/EntryHandler.iOS.cs | 15 +- src/Core/src/Handlers/Label/LabelHandler.cs | 26 ++-- .../src/Handlers/Label/LabelHandler.iOS.cs | 7 +- 20 files changed, 430 insertions(+), 40 deletions(-) diff --git a/src/Controls/src/Core/Entry/Entry.Mapper.cs b/src/Controls/src/Core/Entry/Entry.Mapper.cs index 413f01b94078..6dec362d909f 100644 --- a/src/Controls/src/Core/Entry/Entry.Mapper.cs +++ b/src/Controls/src/Core/Entry/Entry.Mapper.cs @@ -18,7 +18,7 @@ public partial class Entry EntryHandler.Mapper.ReplaceMapping(PlatformConfiguration.iOSSpecific.Entry.AdjustsFontSizeToFitWidthProperty.PropertyName, MapAdjustsFontSizeToFitWidth); #endif EntryHandler.Mapper.ReplaceMapping(nameof(Text), MapText); - EntryHandler.Mapper.ReplaceMapping(nameof(TextTransform), MapText); + EntryHandler.Mapper.ReplaceMapping(nameof(TextTransform), MapTextTransform); #if IOS || ANDROID EntryHandler.Mapper.AppendToMapping(nameof(VisualElement.IsFocused), InputView.MapIsFocused); @@ -28,5 +28,16 @@ public partial class Entry EntryHandler.CommandMapper.PrependToMapping(nameof(IEntry.Focus), InputView.MapFocus); #endif } + + static void MapTextTransform(IEntryHandler handler, Entry label) + { + if (label.IsConnectingHandler()) + { + // If we're connecting the handler, we don't want to map the text multiple times. + return; + } + + MapText(handler, label); + } } } diff --git a/src/Controls/src/Core/Entry/Entry.iOS.cs b/src/Controls/src/Core/Entry/Entry.iOS.cs index 25a6281483a1..20407ae151b3 100644 --- a/src/Controls/src/Core/Entry/Entry.iOS.cs +++ b/src/Controls/src/Core/Entry/Entry.iOS.cs @@ -16,7 +16,14 @@ public static void MapAdjustsFontSizeToFitWidth(IEntryHandler handler, Entry ent public static void MapText(IEntryHandler handler, Entry entry) { Platform.TextExtensions.UpdateText(handler.PlatformView, entry); - EntryHandler.MapFormatting(handler, entry); + + if (!handler.IsConnectingHandler()) + { + // If we're not connecting the handler, we need to update the text formatting + // This is because the text may have changed, and we need to ensure that + // any attributed string formatting is applied correctly. + EntryHandler.MapFormatting(handler, entry); + } } public static void MapCursorColor(EntryHandler handler, Entry entry) => diff --git a/src/Controls/src/Core/Label/Label.Mapper.cs b/src/Controls/src/Core/Label/Label.Mapper.cs index fdc6a046daea..3057ce3cf6d2 100644 --- a/src/Controls/src/Core/Label/Label.Mapper.cs +++ b/src/Controls/src/Core/Label/Label.Mapper.cs @@ -57,7 +57,10 @@ static void MapTextTransform(ILabelHandler handler, Label label) => static void MapFormattedText(ILabelHandler handler, Label label) { if (label.IsConnectingHandler()) + { + // If we're connecting the handler, we don't want to map the text multiple times. return; + } MapText(handler, label); } @@ -139,9 +142,12 @@ static void MapFont(ILabelHandler handler, Label label, Action