Xamarin.Forms Prism - Navigation stops working properly when you show Modal Page [iOS 13]

In iOS 13, when you Navigate to Modal Page, the Page is displayed like a card-like appearance.
You can close this Page by swipe down.
After such operation, NavigationService is not involved and NavigationStack is not cleared properly, so next navigation fails.

I tried to change this card-like appearance in PageRenderer but it doesn't work :disappointed:

    public class ModalPageRenderer : PageRenderer
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            parent.PresentationController.Delegate = new TestDelegate();
        }
     }

    public class TestDelegate : UIAdaptivePresentationControllerDelegate
    {
        [Export("presentationController:willPresentWithAdaptiveStyle:transitionCoordinator:")]
        public override void WillPresent(UIPresentationController presentationController, UIModalPresentationStyle style, IUIViewControllerTransitionCoordinator transitionCoordinator)
        {

        }

        [Foundation.Export("adaptivePresentationStyleForPresentationController:")]
        public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
        {
            return UIModalPresentationStyle.FullScreen;
        }

        [Foundation.Export("adaptivePresentationStyleForPresentationController:traitCollection:")]
        [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 8, 3, ObjCRuntime.PlatformArchitecture.All, null)]
        public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIKit.UIPresentationController controller, UIKit.UITraitCollection traitCollection)
        {
            return UIModalPresentationStyle.FullScreen;
        }
    }

Best Answer

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Handle the WillMoveToParentViewController event in your renderer:

    public class ModalPageRenderer : PageRenderer
    {
        public override void WillMoveToParentViewController(UIViewController parent)
        {
            base.WillMoveToParentViewController(parent);
    
            parent.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
        }
    }
    
  • SeRgI.8537SeRgI.8537 PLMember ✭✭

    It doesn't work in my case :disappointed:

  • LandLuLandLu Member, Xamarin Team Xamurai

    Try to change the SettingsMobilePage in the ExportRenderer to Xamarin.Forms.ContentPage.

  • SeRgI.8537SeRgI.8537 PLMember ✭✭

    I achieved exactly the same without Prism.
    No matter if I change to ContentPage or specific page, breakpoint stops in this method witch tells me that it is called but no matter what I set here, there is no effect.
    I have tested it on iPhone simulator - iPhone 11 iOS 13.0

    Test project is in the attachment.
    When you hit Go Back button on About page, everything is ok because Navigation stack is properly managed but if you dismiss modal Page by gesture swipe down, exception is thrown (in my product version with Prism, there is no exception but Navigation stack is broken and stops working).

  • SeRgI.8537SeRgI.8537 PLMember ✭✭

    @LandLu, I wanted to thank you for this solution.
    It works as expected.
    Unfortunately, I have noticed another issue regarding to iOS 13.0
    Just try to run this project which you attached in last post on iPad (9,7 inch) iOS 13.0
    You should see blank page.
    When you run this project for ex. on iPad (9,7 inch) iOS 10.2, everything is ok.
    I know that it is related with another issue but maybe you know what is wrong.

    Once again, thanks for solving my 1st issue :smile:

  • SeRgI.8537SeRgI.8537 PLMember ✭✭

    Hi @LandLu ,

    Can you take a look on my previous comment ?
    I have a problem with display MasterDetail (your solution) on iOS 13.0

Sign In or Register to comment.