-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Span's TapGestureRecognizer not working if text is truncated #22213
base: main
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -184,7 +184,7 @@ internal static void RecalculateSpanPositions(this UILabel control, Label elemen | |||
var yaxis = startRect.Top; | |||
var lineHeights = new List<double>(); | |||
|
|||
while ((endRect.Bottom - yaxis) > 0.001) | |||
while ((Math.Max(endRect.Bottom, finalSize.Bottom) - yaxis) > 0.001) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing InitialFormattedTextMatchesText
test is failing on macOS. Could you try the changes on Catalyst?
System.OutOfMemoryException : Out of memory
at System.Collections.Generic.List`1[[System.Double, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].set_Capacity(Int32 value)
at System.Collections.Generic.List`1[[System.Double, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Grow(Int32 capacity)
at System.Collections.Generic.List`1[[System.Double, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].AddWithResize(Double item)
at Microsoft.Maui.Controls.Platform.FormattedStringExtensions.RecalculateSpanPositions(UILabel control, Label element) in /Users/builder/azdo/_work/2/s/src/Controls/src/Core/Platform/iOS/Extensions/FormattedStringExtensions.cs:line 202
at Microsoft.Maui.Controls.Label.RecalculateSpanPositions() in /Users/builder/azdo/_work/2/s/src/Controls/src/Core/Label/Label.iOS.cs:line 61
at Microsoft.Maui.Controls.Label.ArrangeOverride(Rect bounds) in /Users/builder/azdo/_work/2/s/src/Controls/src/Core/Label/Label.iOS.cs:line 15
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange(Rect bounds) in /Users/builder/azdo/_work/2/s/src/Controls/src/Core/VisualElement/VisualElement.cs:line 1834
at Microsoft.Maui.DeviceTests.HandlerTestBasement.InitializeViewHandler(IElement element, IElementHandler handler, IMauiContext mauiContext) in /Users/builder/azdo/_work/2/s/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBasement.cs:line 136
at Microsoft.Maui.DeviceTests.HandlerTestBasement.CreateHandler[LabelHandler,LabelHandler](IElement element, IMauiContext mauiContext) in /Users/builder/azdo/_work/2/s/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBasement.cs:line 166
at Microsoft.Maui.DeviceTests.HandlerTestBasement.CreateHandler[LabelHandler](IElement view, IMauiContext mauiContext) in /Users/builder/azdo/_work/2/s/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBasement.cs:line 90
at Microsoft.Maui.DeviceTests.ControlsHandlerTestBase.CreateHandler[LabelHandler](IElement view) in /Users/builder/azdo/_work/2/s/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs:line 44
at Microsoft.Maui.DeviceTests.LabelTests.<>c__DisplayClass17_0.<<InitialFormattedTextMatchesText>b__0>d.MoveNext() in /Users/builder/azdo/_work/2/s/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs:line 472
--- End of stack trace from previous location ---
at Microsoft.Maui.Dispatching.DispatcherExtensions.<>c__DisplayClass3_0.<<DispatchAsync>b__0>d.MoveNext() in /Users/builder/azdo/_work/2/s/src/Core/src/Dispatching/DispatcherExtensions.cs:line 88
--- End of stack trace from previous location ---
at Microsoft.Maui.Dispatching.DispatcherExtensions.<>c__DisplayClass2_0`1.<<DispatchAsync>b__0>d[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() in /Users/builder/azdo/_work/2/s/src/Core/src/Dispatching/DispatcherExtensions.cs:line 67
--- End of stack trace from previous location ---
at Microsoft.Maui.DeviceTests.LabelTests.InitialFormattedTextMatchesText(Double fontSize) in /Users/builder/azdo/_work/2/s/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs:line 470
--- End of stack trace from previous location ---
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz it should work now
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is in the right direction and definitely when there is truncation, this is not working correctly because it is looking for the rect around the last character but that character is not rendered and get an empty rect.
The issue I see with using the finalSize.Bottom is when we have a frame that is longer than the span we'd like, there is extra space being added to the 'hitbox' area of the span that we do not want.
Screen.Recording.2024-07-11.at.5.08.17.PM.mov
<Label AutomationId="label7" HorizontalOptions="Start" MaxLines="5" BackgroundColor="LightGoldenrodYellow" WidthRequest="200" HeightRequest="400">
<Label.FormattedText>
<FormattedString>
<Span Text="Only our MaxLines differ. Otherwise we're the same. Please tap us!">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Span.GestureRecognizers>
</Span>
</FormattedString>
</Label.FormattedText>
</Label>
This is a great idea though and maybe it can be tweaked to find a good middle ground
Perhaps something like a check if the endRect is the empty rect and the startRect is not the empty rect, then maybe that is enough to assume there is truncation going on and we can use the finalSize? |
Issues Fixed
Windows is not working either, but I have no machine to work on it
Fixes #21837
Screen.Recording.2024-05-05.at.20.33.23.mov
Screen.Recording.2024-05-05.at.20.31.50.mov