Skip to content

Commit 12da927

Browse files
committed
chore: prevent double Detach calls
1 parent 3aec4d2 commit 12da927

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ internal override void LeaveImpl(LeaveParams @params)
925925
{
926926
base.LeaveImpl(@params);
927927

928-
if (IsNativeHost && _nativeElementAttached)
928+
if (IsNativeHost)
929929
{
930930
DetachNativeElement(Content);
931931
}

src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.skia.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ partial void AttachNativeElement()
9090
partial void DetachNativeElement(object content)
9191
{
9292
#if DEBUG
93-
global::System.Diagnostics.Debug.Assert(IsNativeHost && _nativeElementAttached);
94-
_nativeElementAttached = false;
93+
global::System.Diagnostics.Debug.Assert(IsNativeHost);
9594
#endif
9695
_lastNativeArrangeArgs = null;
9796
_nativeHosts.Remove(this);
98-
_nativeElementHostingExtension.Value!.DetachNativeElement(content);
97+
if (_nativeElementAttached)
98+
{
99+
_nativeElementAttached = false;
100+
_nativeElementHostingExtension.Value!.DetachNativeElement(content);
101+
}
99102
}
100103

101104
private Size MeasureNativeElement(Size childMeasuredSize, Size availableSize)
@@ -153,6 +156,7 @@ internal static void OnNativeHostsRenderOrderChanged(List<Visual> nativeVisualsI
153156
// We're detaching the native element as it's no longer in view, but conceptually, it's still in the tree, so IsNativeHost is still true
154157
Debug.Assert(host.IsNativeHost);
155158
host._nativeElementAttached = false;
159+
host._lastNativeArrangeArgs = null;
156160
host._nativeElementHostingExtension.Value!.DetachNativeElement(host.Content);
157161
}
158162
else if (host._nativeElementAttached)

0 commit comments

Comments
 (0)