Enable Swipe Gesture in XF for iOS when Navigation Bar hidden

Background

Recently I got one case from customer to resolve the below issue:

If we set NavigationBar to hidden status in Xamarin.Forms, then iOS gesture for return will also be disabled.

Code as below:

1
NavigationPage.SetHasNavigationBar(this, false);

Solution

In native iOS application, we can call the below function to make sure the Swipe gesture always be available to use:

1
[self.navigationController.interactivePopGestureRecognizer setDelegate:nil];

This is obviously a platform-specific code, so it’s also quite straightforward to think about the solution in Xamarin.Forms.
We will rewrite the PageRenderer to achieve:

1
2
3
4
5
6
7
8
9
public class BaseCoreRenderer: PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewDidAppear(animated);
ViewController.NavigationController.InteractivePopGestureRecognizer.Enabled = true;
ViewController.NavigationController.InteractivePopGestureRecognizer.Delegate = new UIGestureRecognizerDelegate();
}
}

After testing, this can resolve the issue as expected.

Troubleshooting for Xamarin.Android binding project
You need to set install_url to use ShareThis. Please set it in _config.yml.

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×