Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigationFrom not called when navigate to different Hamburger Menu Page #1353

Closed
SeRgI1982 opened this issue Jan 31, 2018 · 13 comments
Closed
Labels

Comments

@SeRgI1982
Copy link

Description

NavigationFrom is not called when navigating to a different Page related with menu item in HamburgerMenu (MasterDetail scenario).

Steps to Reproduce

All pages have ViewModels with INavigationAware implementation.
All ViewModels call OnNavigatedTo method when user navigates to them.

  1. Create MasterDetail Page with MenuPage as a Master.
    MenuPage has two buttons:

    • btn1 - navigates to PageA (NavigationService.NavigateAsync("Navigation/PageA")),
    • btn2 - navigates to PageB (NavigationService.NavigateAsync("Navigation/PageB")).
  2. PageA is a default page (after openning the app, user landing on PageA)

  3. Open MenuPage and hit btn2

Expected Behavior

PageAViewModel.OnNavigatedFrom - should be executed,
PageBViewModel.OnNavigatedTo - should be executed.

Actual Behavior

PageAViewModel.OnNavigatedFrom - is not executed,
PageBViewModel.OnNavigatedTo - is executed.

Basic Information

  • Version with issue: 7.0.0.336-pre
  • Last known good version:
  • Xamarin.Forms version: 2.5.0.121934
  • IDE: VS2017
@brianlagunas
Copy link
Member

Please provide a sample that reproduces this issue.

@SeRgI1982
Copy link
Author

SeRgI1982 commented Jan 31, 2018

Just open a HamburgerMenu Prism Sample and update to the latest version of Prism and Xamarin Forms. Override OnNavigatedFrom method in ViewAViewModel, ViewBViewModel and ViewCViewModel and put breakpoints.
When you switch between pages (A, B, C):

  • OnNavigatedTo - called always,
  • OnNavigatedFrom - never called :(

My case:

  1. On ViewA I start counting,
  2. Go to ViewB,
  3. Go back to ViewA - counting should be continued.

I wanted to use OnNavigatedFrom to save state of the working object on ViewA.

I have similar cases related with going app to the background or re-launch app when you hit Android notification panel (Foreground service) and those cases works.

Internal navigation doesn't worked as expected because of this bug.
Workaround is to use EventAggregator and publish an event when I hit another menu item but I don't want to complicate the app.

Updated sample in the attachment

HamburgerMenu.zip

@brianlagunas
Copy link
Member

Verified. Thanks for submitting this.

@SeRgI1982
Copy link
Author

Super. Big thanks for this fix.
Can you tell me in which pre-release version it will be available ?

@brianlagunas
Copy link
Member

You can get it now in the latest CI builds on MyGet. We have some pretty large efforts going on right now regarding aligning Prism across platforms, so I don't have a timeframe for the next preview.

@SeRgI1982
Copy link
Author

You surprised me with this MyGet. I used to not looking into this 'Packages source'. For most cases, nuget.org is enough. I would love to work with company where they have at least in 50% organized development process like you have for Prism. Congratulations.

@IngweLand
Copy link

Still does not work. Checked with 7.1.0.123-pre (it supposed to be fixed according to it's release notes). Checked on Android only. Here is the sample project.
https://github.com/IngweLand/App1

@brianlagunas
Copy link
Member

It works just fine. You aren't setting the useModalNavigation parameter to true.

@IngweLand
Copy link

Why should I set useModalNavigation parameter to true - I am not creating a modal page.
However, I think my mistake was different. I was changing pages with "absolute" style, like this:
initial set:
NavigationService.NavigateAsync($"{nameof(PrismMasterDetailPage1)}/{nameof(NavigationPage)}/{nameof(ViewA)}");
and to change a page i did:
NavigationService.NavigateAsync($"{nameof(PrismMasterDetailPage1)}/{nameof(NavigationPage)}/{nameof(ViewB)}");

However, when I changed second line to following, OnNavigationFrom started to be called:
NavigationService.NavigateAsync($"{nameof(NavigationPage)}/{nameof(ViewB)}");

@brianlagunas
Copy link
Member

Because you can't set the Detail of a MasterDetail to another MasterDetailPage. Therefore you must push it modally. Looks like you have it figured out.

@anetapetryla
Copy link

anetapetryla commented May 24, 2018

I have similar problem with my app. When I'm on BasePage and I want to navigate from MasterDetailPage to some page (ViewA or ViewB), the OnNavigatedFrom method from BasePage not called. I tried to set useModalNavigation to true, but still doesn't work.

Prism: 7.0.0.396
Xamarin.Forms: 3.0.0.446417

So, I created test app. @brianlagunas , I will be grateful for your help.
https://github.com/aneti9862/XamarinForms

@bwenninger
Copy link

bwenninger commented Feb 6, 2019

@SeRgI1982 I pulled down your HamburgerMenu.zip file and updated the Prism libraries to version 7.1.0.431 and tried it out on iOS. If I switch from ViewA to ViewB the OnNavigatedFrom method is called on the MainPage but not on ViewA. Is this how it should behave or should OnNavigatedFrom be called on ViewA?

@brianlagunas Could you confirm what Prism should be doing? When I navigate from ViewA to ViewB using an menu item on the MainPage, should the OnNavigatedFrom method be called on ViewA? Or on MainPage? Or both? Thanks!

@lock
Copy link

lock bot commented Jan 28, 2020

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 lock bot locked as resolved and limited conversation to collaborators Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants