Skip to content

Commit

Permalink
fix(commandbar): Removed potential memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed Oct 16, 2020
1 parent 1029dd5 commit 753616a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Uno.UI/Controls/NativeCommandBarPresenter.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class NativeCommandBarPresenter : ContentPresenter
{
private readonly SerialDisposable _statusBarSubscription = new SerialDisposable();
private readonly SerialDisposable _orientationSubscription = new SerialDisposable();
private CommandBar? _commandBar;
private WeakReference<CommandBar?>? _commandBar;

private UINavigationBar? _navigationBar;
private readonly bool _isPhone = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone;
Expand All @@ -33,14 +33,19 @@ private protected override void OnLoaded()

// TODO: Find a proper way to decide whether a CommandBar exists on canvas (within Page), or is mapped to the UINavigationController's NavigationBar.

if (_commandBar == null)
var commandBar = _commandBar?.Target;

if (commandBar == null)
{
_commandBar = TemplatedParent as CommandBar;
_navigationBar = _commandBar?.GetRenderer(RendererFactory).Native;
commandBar = TemplatedParent as CommandBar;
_commandBar = new WeakReference<CommandBar?>(commandBar);

_navigationBar = commandBar?.GetRenderer(RendererFactory).Native;

}
else
{
_navigationBar = _commandBar?.ResetRenderer(RendererFactory).Native;
_navigationBar = commandBar?.ResetRenderer(RendererFactory).Native;
}

if (_navigationBar == null)
Expand Down Expand Up @@ -75,7 +80,7 @@ void OnStatusBarChanged(StatusBar sender, object args)
}
}

CommandBarRenderer RendererFactory() => new CommandBarRenderer(_commandBar!);
CommandBarRenderer RendererFactory() => new CommandBarRenderer(_commandBar?.Target);

protected override Size MeasureOverride(Size size)
{
Expand Down

0 comments on commit 753616a

Please sign in to comment.