C
C#3mo ago
Nedo | Lukas

(Maui) Native swipe back on iOS

hey, i want to implement the native swipe back into my .Net Maui App for iOS. But the only thing i found, is the way via ShellNavigation. But in my project i use Application.Current.MainPage.Navigation.PopAsync(true); and await Application.Current.MainPage.Navigation.PushAsync(page, animated); for the navigation. Is there anyone who can help me with this
1 Reply
Nedo | Lukas
Nedo | Lukas3mo ago
I have now found a solution. The Maui NavigationBar is not required and can be completely hidden. Step 1: Write a CustomHandler. The file can be created for example in the Platforms/IOS folder with the following content: namespace YOURNAMESPACE.Platforms.iOS; public class ContentPageHandler : Microsoft.Maui.Handlers.PageHandler { protected override void ConnectHandler(Microsoft.Maui.Platform.ContentView nativeView) { base.ConnectHandler(nativeView); ContentPage.Loaded += OnLoaded; } protected override void DisconnectHandler(Microsoft.Maui.Platform.ContentView nativeView) { ContentPage.Loaded -= OnLoaded; base.DisconnectHandler(nativeView); } ContentPage ContentPage => VirtualView as ContentPage; void OnLoaded(object sender, EventArgs e) => ConfigureInteractivePopGesture(); void ConfigureInteractivePopGesture() { if (this is IPlatformViewHandler handler && handler.ViewController?.ParentViewController?.NavigationController is UIKit.UINavigationController navControler) { navControler.NavigationBarHidden = true; navControler.InteractivePopGestureRecognizer.Delegate = new GestureRecognizerDelegate(); navControler.InteractivePopGestureRecognizer.Enabled = true; } } } public class GestureRecognizerDelegate : Foundation.NSObject, UIKit.IUIGestureRecognizerDelegate { } Step 2: Register the handler Simply register the new handler in MauiProgram.cs like here: [...] #if IOS .ConfigureMauiHandlers(handlers => { handlers.AddHandler(typeof(ContentPage), typeof(YOURNAMESPACE.Platforms.iOS.ContentPageHandler)); }) #endif [...]