Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/Controls/src/Core/Label/Label.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected override Size ArrangeOverride(Rect bounds)
{
var size = base.ArrangeOverride(bounds);

RecalculateSpanPositions();
RecalculateSpanPositions(size);

return size;
}
Expand Down Expand Up @@ -51,14 +51,14 @@ static void MapFormatting(ILabelHandler handler, Label label)
LabelHandler.MapFormatting(handler, label);
}

void RecalculateSpanPositions()
void RecalculateSpanPositions(Size size)
{
if (Handler is LabelHandler labelHandler)
{
if (labelHandler.PlatformView is not UILabel platformView || labelHandler.VirtualView is not Label virtualView)
return;

platformView.RecalculateSpanPositions(virtualView);
platformView.RecalculateSpanPositions(virtualView, size);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static NSAttributedString ToNSAttributedString(
return attrString;
}

internal static void RecalculateSpanPositions(this UILabel control, Label element)
internal static void RecalculateSpanPositions(this UILabel control, Label element, Size size)
{
if (element is null)
{
Expand All @@ -149,7 +149,7 @@ internal static void RecalculateSpanPositions(this UILabel control, Label elemen
return;
}

var finalSize = control.Bounds;
var finalSize = size;
Copy link

Copilot AI Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider updating the XML documentation for RecalculateSpanPositions to document the new 'size' parameter and its role in reflecting the arranged bounds from LabelHandler. This will help maintain clarity for future developers maintaining this internal method.

Copilot uses AI. Check for mistakes.

if (finalSize.Width <= 0 || finalSize.Height <= 0)
{
Expand Down
56 changes: 56 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28949.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28949, "On iOS GestureRecognizers don't work on Span in a Label, which doesn't get IsVisible (=true) update from its parent", PlatformAffected.iOS)]
public class Issue28949 : ContentPage
{
public Issue28949()
{
var toggleButton = new Button
{
Text = "Toggle Visibility",
AutomationId = "ToggleButton"
};
var formattedString = new FormattedString();
var label = new Label
{
FormattedText = formattedString,
BackgroundColor = Colors.Transparent,
AutomationId = "Label"
};
var grid = new Grid
{
BackgroundColor = Colors.Yellow
};

var span = new Span
{
Text = "Click me",
TextColor = Colors.Pink
};
var tapGesture = new TapGestureRecognizer();
tapGesture.Tapped += (s, e) =>
{
span.Text = "Success";
span.TextColor = Colors.Green;
};
span.GestureRecognizers.Add(tapGesture);
formattedString.Spans.Add(span);

toggleButton.Clicked += (s, e) =>
{
grid.IsVisible = !grid.IsVisible;
};
grid.IsVisible = false;
grid.Children.Add(label);
var stackLayout = new StackLayout
{
Children =
{
toggleButton,
grid
}
};
Content = stackLayout;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue28949 : _IssuesUITest
{
public Issue28949(TestDevice device) : base(device)
{
}

public override string Issue => "On iOS GestureRecognizers don't work on Span in a Label, which doesn't get IsVisible (=true) update from its parent";

[Test]
[Category(UITestCategories.Label)]
public void GestureRecognizersOnLabelSpanShouldWork()
{
App.WaitForElement("ToggleButton");
App.Tap("ToggleButton");
var spanRect = App.WaitForElement("Label").GetRect();
App.TapCoordinates(spanRect.X + 5, spanRect.Y + 5);
App.WaitForElement("Success");
}
}
Loading