-
Notifications
You must be signed in to change notification settings - Fork 2k
[iOS] Fix ObjectDisposedException in ContentView.RemoveContentMask #34680
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
Changes from 1 commit
40ba4ce
f81081f
0dc556e
ca92cef
d83c425
ee4ad08
0dcd181
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,10 @@ | ||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||
| using System; | ||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||
| using CoreAnimation; | ||||||||||||||||||||||
| using CoreGraphics; | ||||||||||||||||||||||
| using Microsoft.Maui.DeviceTests.Stubs; | ||||||||||||||||||||||
| using Microsoft.Maui.Graphics; | ||||||||||||||||||||||
| using Microsoft.Maui.Platform; | ||||||||||||||||||||||
| using UIKit; | ||||||||||||||||||||||
| using Xunit; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -105,5 +110,61 @@ public async Task DoesNotPropagateToContentWithExplicitFlowDirection() | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| Assert.Equal(UIUserInterfaceLayoutDirection.LeftToRight, labelFlowDirection); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||
| public async Task RemoveContentMaskDoesNotThrowWhenDisposed() | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| // Verify that removing a subview with an active clip mask does not throw | ||||||||||||||||||||||
| // ObjectDisposedException when the underlying CAShapeLayer is already disposed. | ||||||||||||||||||||||
| // Regression test for https://github.com/FFIDX-Success/ATP-Support/issues/561 | ||||||||||||||||||||||
| await InvokeOnMainThreadAsync(() => | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| var contentView = new Microsoft.Maui.Platform.ContentView(); | ||||||||||||||||||||||
| contentView.Frame = new CGRect(0, 0, 200, 200); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var content = new UIView { Tag = Microsoft.Maui.Platform.ContentView.ContentTag }; | ||||||||||||||||||||||
| content.Frame = new CGRect(0, 0, 200, 200); | ||||||||||||||||||||||
| contentView.AddSubview(content); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Set a clip to trigger _contentMask creation via UpdateClip | ||||||||||||||||||||||
| contentView.Clip = new BorderStrokeStub(); | ||||||||||||||||||||||
| contentView.LayoutSubviews(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Dispose the content mask's native handle (simulating iOS deallocating the layer) | ||||||||||||||||||||||
| if (content.Layer.Mask is CAShapeLayer mask) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| mask.Dispose(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Oxymoron290 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // This should not throw ObjectDisposedException | ||||||||||||||||||||||
| var ex = Record.Exception(() => content.RemoveFromSuperview()); | ||||||||||||||||||||||
| Assert.Null(ex); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||
| /// Minimal IBorderStroke stub for testing clip mask creation. | ||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||
| class BorderStrokeStub : IBorderStroke | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| public IShape Shape { get; set; } = new RectangleShape(); | ||||||||||||||||||||||
| public Paint Stroke { get; set; } | ||||||||||||||||||||||
| public double StrokeThickness { get; set; } = 1; | ||||||||||||||||||||||
| public LineCap StrokeLineCap { get; set; } | ||||||||||||||||||||||
| public LineJoin StrokeLineJoin { get; set; } | ||||||||||||||||||||||
| public float[] StrokeDashPattern { get; set; } | ||||||||||||||||||||||
|
Comment on lines
+168
to
+172
|
||||||||||||||||||||||
| public Paint Stroke { get; set; } | |
| public double StrokeThickness { get; set; } = 1; | |
| public LineCap StrokeLineCap { get; set; } | |
| public LineJoin StrokeLineJoin { get; set; } | |
| public float[] StrokeDashPattern { get; set; } | |
| public Paint? Stroke { get; set; } | |
| public double StrokeThickness { get; set; } = 1; | |
| public LineCap StrokeLineCap { get; set; } | |
| public LineJoin StrokeLineJoin { get; set; } | |
| public float[]? StrokeDashPattern { get; set; } |
Uh oh!
There was an error while loading. Please reload this page.