Make android back button work for navigation properly
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using Android.App;
|
using System;
|
||||||
|
using Android.App;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Android;
|
using Avalonia.Android;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
|
||||||
namespace CritterFolio.Android;
|
namespace CritterFolio.Android;
|
||||||
|
|
||||||
@@ -18,4 +20,22 @@ public class MainActivity : AvaloniaMainActivity<App>
|
|||||||
return base.CustomizeAppBuilder(builder)
|
return base.CustomizeAppBuilder(builder)
|
||||||
.WithInterFont();
|
.WithInterFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void OnBackPressed()
|
||||||
|
{
|
||||||
|
if (Sys.Navigation != null && Sys.Navigation.IsLastPage())
|
||||||
|
{
|
||||||
|
if (Avalonia.Application.Current?.ApplicationLifetime is ISingleViewApplicationLifetime lifetime)
|
||||||
|
{
|
||||||
|
//base.OnBackPressed();
|
||||||
|
// CA1422: This call site is reachable on: 'Android' 21.0 and later. 'AvaloniaActivity.OnBackPressed()' is obsoleted on: 'Android' 33.0 and later.
|
||||||
|
// Just call exit from Sytem.Environment for now which does not shutdown cleanly
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Sys.Navigation?.PopPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ public partial class Navigation : UserControl
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsLastPage()
|
||||||
|
{
|
||||||
|
return _pageStack.Count == 1;
|
||||||
|
}
|
||||||
|
|
||||||
public void Init(ContentControl pageContainer)
|
public void Init(ContentControl pageContainer)
|
||||||
{
|
{
|
||||||
_pageContainer = pageContainer;
|
_pageContainer = pageContainer;
|
||||||
@@ -79,6 +84,7 @@ public partial class Navigation : UserControl
|
|||||||
|
|
||||||
public void PopPage()
|
public void PopPage()
|
||||||
{
|
{
|
||||||
|
if (_pageStack.Count == 1) return;
|
||||||
Console.WriteLine($"Removing page {CurrentPage?.Title ?? "??"} from the page stack");
|
Console.WriteLine($"Removing page {CurrentPage?.Title ?? "??"} from the page stack");
|
||||||
_pageStack.Pop();
|
_pageStack.Pop();
|
||||||
RefreshPage();
|
RefreshPage();
|
||||||
|
|||||||
Reference in New Issue
Block a user