-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix crash in Label FormattedText span position recalculation with MaxLines/TailTruncation #35964
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
Merged
Merged
[Android] Fix crash in Label FormattedText span position recalculation with MaxLines/TailTruncation #35964
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 35755, "IndexOutOfBoundsException in RecalculateSpanPositions when a Label uses FormattedText, MaxLines, and TailTruncation", PlatformAffected.Android)] | ||
| public class Issue35755 : ContentPage | ||
| { | ||
| readonly string _paragraphA = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eleifend, augue nec aliquam interdum, massa nisl viverra orci, non interdum risus arcu id lorem. Curabitur accumsan, urna eu tempor tincidunt, purus neque feugiat tortor, sed tristique nibh nunc et augue."; | ||
| readonly string _paragraphB = "Aliquam erat volutpat. Quisque a mi lacus. Integer vitae malesuada sem. Nunc id dui nec lacus feugiat volutpat. Morbi et sollicitudin erat. Sed varius felis id dignissim facilisis. Vivamus vulputate, augue sed finibus laoreet, enim neque tristique odio, id rhoncus elit purus a turpis."; | ||
| readonly string _paragraphC = "Praesent in lectus non mauris mattis ultrices. Donec non justo ac nunc porta pellentesque. Integer euismod, velit in posuere iaculis, lorem nunc commodo libero, nec interdum lorem nibh ut turpis. Phasellus gravida tristique tortor, id posuere turpis sodales in."; | ||
|
|
||
| Label _crashTargetLabel; | ||
|
|
||
| public Issue35755() | ||
| { | ||
| _crashTargetLabel = new Label | ||
| { | ||
| AutomationId = "CrashTargetLabel", | ||
| MaxLines = 4, | ||
| LineBreakMode = LineBreakMode.TailTruncation, | ||
| FontSize = 14 | ||
| }; | ||
|
|
||
| var resultLabel = new Label | ||
| { | ||
| AutomationId = "ResultLabel", | ||
| Text = "Waiting for trigger..." | ||
| }; | ||
|
|
||
| var triggerButton = new Button | ||
| { | ||
| AutomationId = "TriggerButton", | ||
| Text = "Trigger FormattedText" | ||
| }; | ||
|
|
||
| triggerButton.Clicked += (s, e) => | ||
| { | ||
| _crashTargetLabel.FormattedText = BuildFormattedText(); | ||
| resultLabel.Text = "Success"; | ||
| }; | ||
|
|
||
| Content = new ScrollView | ||
| { | ||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = new Thickness(24), | ||
| Spacing = 16, | ||
| Children = | ||
| { | ||
| triggerButton, | ||
| resultLabel, | ||
| _crashTargetLabel | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| FormattedString BuildFormattedText() | ||
| { | ||
| var fs = new FormattedString(); | ||
| fs.Spans.Add(new Span | ||
| { | ||
| Text = "Content: ", | ||
| FontAttributes = FontAttributes.Bold, | ||
| TextColor = Colors.DarkRed | ||
| }); | ||
| fs.Spans.Add(new Span { Text = _paragraphA + "\n\n", TextColor = Colors.Black }); | ||
| fs.Spans.Add(new Span { Text = _paragraphB + "\n\n", TextColor = Colors.DarkBlue }); | ||
| fs.Spans.Add(new Span { Text = _paragraphC, TextColor = Colors.DarkGreen }); | ||
| return fs; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35755.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue35755 : _IssuesUITest | ||
| { | ||
| public Issue35755(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "IndexOutOfBoundsException in RecalculateSpanPositions when a Label uses FormattedText, MaxLines, and TailTruncation"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Label)] | ||
| public void FormattedTextWithMaxLinesAndTailTruncationShouldNotCrash() | ||
| { | ||
| App.WaitForElement("TriggerButton"); | ||
| App.Tap("TriggerButton"); | ||
|
|
||
| App.WaitForElement("ResultLabel"); | ||
| var resultText = App.FindElement("ResultLabel").GetText(); | ||
| Assert.That(resultText, Is.EqualTo("Success"), "Label should display truncated FormattedText without crashing."); | ||
| App.WaitForElement("CrashTargetLabel"); | ||
|
Shalini-Ashokan marked this conversation as resolved.
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.