-
Couldn't load subscription status.
- Fork 1.9k
Fixed Rectangle appears blurred on iOS and macOS when its bounds are changed at runtime #32140
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| using Microsoft.Maui.Controls.Shapes; | ||
| using Microsoft.Maui.Layouts; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 32042, "Rectangle appears blurred on iOS and macOS when its bounds are changed at runtime within an AbsoluteLayout", PlatformAffected.iOS | PlatformAffected.macOS)] | ||
| public class Issue32042 : ContentPage | ||
| { | ||
| AbsoluteLayout absoluteLayout; | ||
| Rectangle rectangle; | ||
| Button changeBoundsButton; | ||
|
|
||
| public Issue32042() | ||
| { | ||
| // Create the AbsoluteLayout | ||
| absoluteLayout = new AbsoluteLayout | ||
| { | ||
| BackgroundColor = Colors.LightGray | ||
| }; | ||
|
|
||
| // Create the Rectangle | ||
| rectangle = new Rectangle | ||
| { | ||
| BackgroundColor = Colors.Green, | ||
| }; | ||
|
|
||
| // Create the description label | ||
| Label label = new Label | ||
| { | ||
| Text = "The green square must remain sharp after its bounds are updated at runtime; otherwise test failed.", | ||
| LineBreakMode = LineBreakMode.WordWrap, | ||
| MaximumWidthRequest = 300, | ||
| }; | ||
|
|
||
| // Position the label at the top | ||
| AbsoluteLayout.SetLayoutBounds(label, new Rect(0.5, 0, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); | ||
| AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.PositionProportional); | ||
|
|
||
| // Initially set Rectangle position below the label | ||
| AbsoluteLayout.SetLayoutBounds(rectangle, new Rect(0.5, 0.3, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); | ||
| AbsoluteLayout.SetLayoutFlags(rectangle, AbsoluteLayoutFlags.PositionProportional); | ||
|
|
||
| // Create the Button | ||
| changeBoundsButton = new Button | ||
| { | ||
| Text = "Change Bounds", | ||
| AutomationId = "Issue32042Button" | ||
| }; | ||
|
|
||
| AbsoluteLayout.SetLayoutBounds(changeBoundsButton, new Rect(0.5, 0.9, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); | ||
| AbsoluteLayout.SetLayoutFlags(changeBoundsButton, AbsoluteLayoutFlags.PositionProportional); | ||
|
|
||
| // Attach click event | ||
| changeBoundsButton.Clicked += OnChangeBoundsClicked; | ||
|
|
||
| // Add children to layout - order matters for z-index | ||
| absoluteLayout.Children.Add(label); | ||
| absoluteLayout.Children.Add(rectangle); | ||
| absoluteLayout.Children.Add(changeBoundsButton); | ||
|
|
||
| // Set the Content of the page | ||
| Content = absoluteLayout; | ||
| } | ||
|
|
||
| void OnChangeBoundsClicked(object sender, EventArgs e) | ||
| { | ||
| AbsoluteLayout.SetLayoutBounds(rectangle, new Rect(0.5, 0.5, 100, 100)); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32042.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,22 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue32042 : _IssuesUITest | ||
| { | ||
| public Issue32042(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
| public override string Issue => "Rectangle appears blurred on iOS and macOS when its bounds are changed at runtime within an AbsoluteLayout"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Shape)] | ||
| public void RectangleShouldNotBeBlurredAfterBoundsChange() | ||
| { | ||
| App.WaitForElement("Issue32042Button"); | ||
| App.Tap("Issue32042Button"); | ||
| VerifyScreenshot(); | ||
| } | ||
| } |
Binary file added
BIN
+45.3 KB
...tCases.iOS.Tests/snapshots/ios/RectangleShouldNotBeBlurredAfterBoundsChange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.
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.
Mnnn,
UIViewContentMode.RedrawtriggersDraw(CGRect)every time bounds change, including:Shape rendering is already expensive:
For complex shapes (Polygon, Path with many points), this could cause performance issues. The key question is do all shapes have this blurring issue? If is only Rectangle, can move the fix to the Rectangle.
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.
After reviewing the performance impact feedback, I’ve analyzed the issue further. The blurring occurs specifically for the Rectangle shape when its bounds are updated at runtime. To avoid performance overhead from using UIViewContentMode.Redraw, the fix has been moved out, and a workaround has been suggested in the issue report instead.
Workaround: link