Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Controls/src/Core/Entry/Entry.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class Entry
EntryHandler.Mapper.ReplaceMapping<Entry, IEntryHandler>(PlatformConfiguration.iOSSpecific.Entry.AdjustsFontSizeToFitWidthProperty.PropertyName, MapAdjustsFontSizeToFitWidth);
#endif
EntryHandler.Mapper.ReplaceMapping<Entry, IEntryHandler>(nameof(Text), MapText);
EntryHandler.Mapper.ReplaceMapping<Entry, IEntryHandler>(nameof(TextTransform), MapText);
EntryHandler.Mapper.ReplaceMapping<Entry, IEntryHandler>(nameof(TextTransform), MapTextTransform);

#if IOS || ANDROID
EntryHandler.Mapper.AppendToMapping(nameof(VisualElement.IsFocused), InputView.MapIsFocused);
Expand All @@ -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);
}
}
}
9 changes: 8 additions & 1 deletion src/Controls/src/Core/Entry/Entry.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
12 changes: 9 additions & 3 deletions src/Controls/src/Core/Label/Label.Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -139,9 +142,12 @@ static void MapFont(ILabelHandler handler, Label label, Action<IElementHandler,
{
if (label.HasFormattedTextSpans)
{
// if there is formatted text,
// then we re-apply the whole formatted text
handler.UpdateValue(nameof(FormattedText));
if (!handler.IsConnectingHandler())
{
// if there is formatted text,
// then we re-apply the whole formatted text
handler.UpdateValue(nameof(FormattedText));
}
}
else if (label.TextType == TextType.Text || !IsDefaultFont(label))
{
Expand Down
7 changes: 5 additions & 2 deletions src/Controls/src/Core/Label/Label.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using System;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using UIKit;
Expand All @@ -23,7 +22,11 @@ public static void MapText(ILabelHandler handler, Label label)
{
Platform.LabelExtensions.UpdateText(handler.PlatformView, label);

MapFormatting(handler, label);
if (!handler.IsConnectingHandler())
{
// Any text update requires that we update any attributed string formatting
MapFormatting(handler, label);
}
}

public static void MapLineBreakMode(ILabelHandler handler, Label label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@
</Button>

<Label Grid.Row="1"
Text="Clicked Event: "/>
Text="Clicked Event: "
AutomationId="MainLabel">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="MainLabel_Tapped"/>
</Label.GestureRecognizers>
</Label>
<Label Grid.Row="1"
Grid.Column="1"
x:Name="ClickedEventLabel"
AutomationId="ClickedEventLabel"/>

<Label Grid.Row="2"
Text="Pressed Event: "/>
<Label Grid.Row="2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample;

public class ButtonControlPage : NavigationPage
Expand Down Expand Up @@ -52,4 +54,17 @@ public void OnButtonReleased(object sender, EventArgs e)
ReleasedEventLabel.Text = "Released Event Executed";
}
}

void MainLabel_Tapped(object sender, TappedEventArgs e)
{
// Recreate the page to verify initial mappers
ToolbarItems.Clear();
Content = new ContentView();
INameScope scope = this;
scope.UnregisterName("ClickedEventLabel");
scope.UnregisterName("ReleasedEventLabel");
scope.UnregisterName("PressedEventLabel");
scope.UnregisterName("ButtonShadow");
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
<VerticalStackLayout Padding="20"
Spacing="8">
<Label Text="Entry Control"
AutomationId="MainLabel"
FontSize="20"
Margin="0,0,0,50"
HorizontalOptions="Center"/>

HorizontalOptions="Center">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="MainLabel_Tapped"/>
</Label.GestureRecognizers>
</Label>
<local:UITestEntry x:Name="EntryControl"
IsCursorVisible="False"
Text="{Binding Text}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample;

Expand Down Expand Up @@ -122,4 +123,20 @@ private void EntryControl_Unfocused(object sender, FocusEventArgs e)
vm.UnfocusedText = eventInfo;
}
}

void MainLabel_Tapped(object sender, TappedEventArgs e)
{
// Recreate the page to verify initial mappers
ToolbarItems.Clear();
Content = new ContentView();
INameScope scope = this;
scope.UnregisterName("EntryControl");
scope.UnregisterName("TextChangedLabel");
scope.UnregisterName("SelectionLengthEntry");
scope.UnregisterName("CursorPositionEntry");
scope.UnregisterName("CompletedLabel");
scope.UnregisterName("FocusedLabel");
scope.UnregisterName("UnfocusedLabel");
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
Clicked="HorizontalAlignmentButton_Clicked"/>
<Button Text="End"
AutomationId="HEnd"
FontSize="10"
Clicked="HorizontalAlignmentButton_Clicked"/>
</HorizontalStackLayout>
<!-- Vertical Alignment -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
TextType="{Binding TextType}"
VerticalTextAlignment="{Binding VerticalTextAlignment}"
BackgroundColor="LightGray"
AutomationId="MainLabel"/>
AutomationId="MainLabel">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="MainLabel_Tapped"/>
</Label.GestureRecognizers>
</Label>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
BindingContext = _viewModel = new LabelViewModel();
await Navigation.PushAsync(new LabelOptionsPage(_viewModel));
}

void MainLabel_Tapped(object sender, TappedEventArgs e)
{
// Recreate the page to verify initial mappers
ToolbarItems.Clear();
Content = new ContentView();
InitializeComponent();
}
}
Loading
Loading