Skip to content

Commit

Permalink
fix(ContentDialog): [iOS] Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Sep 29, 2020
1 parent c85f2a3 commit 623c02d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/ContentDialog/ContentDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.System;
using Uno.UI.DataBinding;

namespace Windows.UI.Xaml.Controls
{
Expand All @@ -31,10 +32,15 @@ public ContentDialog() : base()
ResourceResolver.ApplyResource(_popup, Popup.LightDismissOverlayBackgroundProperty, "ContentDialogLightDismissOverlayBackground", isThemeResourceExtension: true);

_popup.PopupPanel = new ContentDialogPopupPanel(this);

var thisRef = (this as IWeakReferenceProvider).WeakReference;
_popup.Opened += (s, e) =>
{
Opened?.Invoke(this, new ContentDialogOpenedEventArgs());
VisualStateManager.GoToState(this, "DialogShowing", true);
if (thisRef.Target is ContentDialog that)
{
that.Opened?.Invoke(that, new ContentDialogOpenedEventArgs());
VisualStateManager.GoToState(that, "DialogShowing", true);
}
};
this.KeyDown += OnPopupKeyDown;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Logging;
using Uno.Extensions;
using Uno.UI;
using Uno.UI.DataBinding;
using Windows.Foundation;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml.Controls.Primitives;
Expand All @@ -13,11 +16,8 @@ namespace Windows.UI.Xaml.Controls
{
internal partial class ContentDialogPopupPanel : PopupPanel
{
private readonly ContentDialog _dialog;

public ContentDialogPopupPanel(ContentDialog dialog) : base(dialog._popup)
{
_dialog = dialog;
}

protected override Size ArrangeOverride(Size finalSize)
Expand Down

0 comments on commit 623c02d

Please sign in to comment.