I'm quite a newbie with MAUI and Mobile Apps development and I'm facing a forced migration from Xamarin.Forms to MAUI after recent iOS updates. The problem is that modal navigation with MAUI doesn't work as I would expect. The piece of code is this:
private async void btnSend_Tapped(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//MainPage/TakePicture/SendPicture/OtpCheck");
if (Variables.CurrentPicture.Otp == 0)
{
....
}
await Shell.Current.Navigation.PopToRootAsync();
in the xaml of OtpCheck page I set:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
...
x:Class="SkyObservers.Pages.OtpCheck"
Shell.PresentationMode="Modal">
I would expect that "if(Variables..." would be reached only when OtpCheck page is closed, but it doesn't work like this. The page is loaded and then suddenly disappears, because "PopToRootAsync" is immediately reached. In Xamarin.Forms didn't work like that, so I tried also
await Navigation.PushModalAsync(new OtpCheck());
instead of
await Shell.Current.GoToAsync("//MainPage/TakePicture/SendPicture/OtpCheck");
but the result is the same.
P.S. The route of the page is (hopefully) correctly registered in AppShell.xaml:
<ShellContent Title="SkyObservers" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />
<ShellContent Title="Take New Picture" ContentTemplate="{DataTemplate pages:TakePicture}" Route="MainPage/TakePicture" />
<ShellContent Title="Send Picture" ContentTemplate="{DataTemplate pages:SendPicture}" Route="MainPage/TakePicture/SendPicture" />
<ShellContent Title="Check OTP" ContentTemplate="{DataTemplate pages:OtpCheck}" Route="MainPage/TakePicture/SendPicture/OtpCheck" />
and in AppShell.xaml.cs
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute("MainPage/TakePicture", typeof(TakePicture));
Routing.RegisterRoute("MainPage/TakePicture/SendPicture", typeof(SendPicture));
Routing.RegisterRoute("MainPage/TakePicture/SendPicture/OtpCheck", typeof(OtpCheck));
}
I have solved the problem by transforming OtpCheck page in a CommunityToolkit.Maui.Views.Popup and waiting the result. Xaml code of the page:
CodeBehind for opening and waiting popup's result: