Prism icon indicating copy to clipboard operation
Prism copied to clipboard

[XF] On IOS only NavigationService.GoBack from modal screen not getting OnNavigatedTo

Open lecnierfreeman opened this issue 10 years ago • 8 comments

Hi,

I updated Prism.Forms to the latest version: 6.1.0-pre4 with the idea of that would fix this bug, but maybe I'm doing something wrong, let me explain what I'm doing and the error:

On App opens: NavigationService.Navigate("MainPage");

MainPageViewModel: checks if User is authenticated, if it's: ResetNavToRoot("AppMasterDetail/HomePage")

    protected async Task ResetNavToRoot(string root)
    {
        var navResetStack = new Uri("http://tklabs.com/{0}".Fmt(root), UriKind.Absolute);
        await NavigationService.Navigate(navResetStack);
    } 

Now from HomePage: click a button and push the modal screen: NavigationService.Navigate("ModalPage", parameters, true);

Now in ModalPage after setting the parameters args, pop from the modal screen: NavigationService.GoBack(parameters, true);

Problem is I need to process: parameters in HomePageViewModel.OnNavigatedTo(NavigationParameters parameters)

But unfortunately it works on Android but not in IOS, I read the bug you submitted to Xamarin and they said they Fixed in : 2.2.0-pre1 and I'm using the latest one at this moment: Xamarin.Forms 2.2.0.4-pre1

and Prism versions:

Prism.Core 6.1.0
Prism.Forms 6.1.0-pre4
Prism.Unity 6.2.0-pre3

In one of the bugs posted I read something about EventAgreggators but don't know what is that,

Thank You, Great Library

lecnierfreeman avatar Apr 08 '16 15:04 lecnierfreeman

Can you run the code provided in the bug they fixed and see if the navigation stack counts match?

https://bugzilla.xamarin.com/show_bug.cgi?id=39104

If they don't match then Xamarin introduced a regression :(

Also, you'll want to start using the Prism.Unity.Forms package now. Because of UWP, we had to move to using a specific Unity package for XF.

brianlagunas avatar Apr 08 '16 15:04 brianlagunas

Wow quick answer, thank you. I'll test the code you provided there. So, Wich Package I have to replace with Prism.Unity.Forms ?

lecnierfreeman avatar Apr 08 '16 17:04 lecnierfreeman

Prism.Unity

brianlagunas avatar Apr 08 '16 17:04 brianlagunas

Running this code:

    public partial class App : PrismApplication
    {
        public static App Instance { get; private set; }

        public App()
        {
            InitializeComponent();
            Instance = this;

            // The root page of your application
            MainPage = new TestMainPage();
        }
        protected override void InitializeModules()
        {

        }
}

    class TestMainPage : ContentPage
    {
        public TestMainPage()
        {
            Title = "Main Page";

            var button = new Button() { Text = "Navigate to View A" };
            button.Clicked += (s, e) =>
            {
                Navigation.PushModalAsync(new ViewA());
            };

            Content = button;
        }
    }

    class ViewA : ContentPage
    {
        public ViewA()
        {
            Title = "View A";

            var button = new Button() { Text = "Navigate to View B" };
            button.Clicked += async (s, e) =>
            {
                await Navigation.PushModalAsync(new ViewB());
                System.Diagnostics.Debug.WriteLine("View A Modal Stack Count = {0}", Navigation.ModalStack.Count);

                System.Diagnostics.Debug.WriteLine("Pages on Modal Stack:");
                foreach (var view in Navigation.ModalStack)
                {
                    System.Diagnostics.Debug.WriteLine(view.Title);
                }
            };

            Content = button;
        }
    }

    class ViewB : ContentPage
    {
        public ViewB()
        {
            Title = "View B";
        }
    }

Getting (not expected) results:

Android: 04-08 15:11:56.236 I/mono-stdout( 3239): View A Modal Stack Count = 2 04-08 15:11:56.238 I/mono-stdout( 3239): Pages on Modal Stack: 04-08 15:11:56.242 I/mono-stdout( 3239): View A 04-08 15:11:56.245 I/mono-stdout( 3239): View B

IOS: 2016-04-08 15:20:36.733 View A Modal Stack Count = 2 2016-04-08 15:20:36.735 Pages on Modal Stack: 2016-04-08 15:20:36.737 View A 2016-04-08 15:20:36.743 View B

lecnierfreeman avatar Apr 08 '16 19:04 lecnierfreeman

So as a workaround I don't want to reset the navigation stack, so I added a loading content screen as mainPage and from there I pushed using modal the MasterDetailPage.

Thank You.

lecnierfreeman avatar Apr 08 '16 21:04 lecnierfreeman

This has been verified and reported to Xamarin as a regression. I'll update you when this has been fixed.

brianlagunas avatar Apr 13 '16 18:04 brianlagunas

This has been fixed

brianlagunas avatar Apr 27 '16 02:04 brianlagunas

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 31 '20 21:01 lock[bot]