Skip to content

Commit

Permalink
unsubscribe android back handler when toplevel is disposed (#13831)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmauss authored Dec 6, 2023
1 parent 47fb1d9 commit a028347
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

namespace Avalonia.Android.Platform
{
internal class AndroidSystemNavigationManagerImpl : ISystemNavigationManagerImpl
internal class AndroidSystemNavigationManagerImpl : ISystemNavigationManagerImpl, IDisposable
{
private readonly IActivityNavigationService? _navigationService;

public event EventHandler<RoutedEventArgs>? BackRequested;

public AndroidSystemNavigationManagerImpl(IActivityNavigationService? navigationService)
Expand All @@ -16,6 +18,7 @@ public AndroidSystemNavigationManagerImpl(IActivityNavigationService? navigation
{
navigationService.BackRequested += OnBackRequested;
}
_navigationService = navigationService;
}

private void OnBackRequested(object? sender, AndroidBackRequestedEventArgs e)
Expand All @@ -26,5 +29,13 @@ private void OnBackRequested(object? sender, AndroidBackRequestedEventArgs e)

e.Handled = routedEventArgs.Handled;
}

public void Dispose()
{
if (_navigationService != null)
{
_navigationService.BackRequested -= OnBackRequested;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TopLevelImpl : IAndroidView, ITopLevelImpl, EglGlPlatformSurface.IEglWindo
private readonly AndroidInputMethod<ViewImpl> _textInputMethod;
private readonly INativeControlHostImpl _nativeControlHost;
private readonly IStorageProvider _storageProvider;
private readonly ISystemNavigationManagerImpl _systemNavigationManager;
private readonly AndroidSystemNavigationManagerImpl _systemNavigationManager;
private readonly AndroidInsetsManager _insetsManager;
private readonly ClipboardImpl _clipboard;
private ViewImpl _view;
Expand Down Expand Up @@ -155,6 +155,7 @@ void Draw()

public virtual void Dispose()
{
_systemNavigationManager.Dispose();
_view.Dispose();
_view = null;
}
Expand Down

0 comments on commit a028347

Please sign in to comment.