I've got an app with a page xml definition that has a grid-layout with no children. During the page 'loaded' event, I create a bunch of child elements and add them to the grid-layout dynamically.
I navigate to another page and then call frameModule.topmost().goBack() to go back to the previous page.
On that main page, the 'loaded' event gets called again - BUT has the children I already added in the previous navigation - so looks like the page wasn't created again.
Interestingly, if from the same main page, I navigate to another page and then navigate back (i.e. w/o calling goBack()), then the 'loaded' event gets called but the page doesn't have the children I added - so looks like the page was freshly created.
My questions are:
When one calls goBack(), why is 'loaded' called on the previous page - even though it looks like the previously loaded page was being used.
Is this a bug?
Any way to determine in the 'loaded' function - whether this is truly a fresh page loaded or all elements have been created.
The major difference between goBack and Navigate is that goback just goes back up the navigation history stack, and acts the same as if the person hits the "back" button(android) or swipes to the right (iOS). Navigate goes forward and adds a new stack entry that you can goBack on.
Lets look at two examples:
So if I started on Page1 and Navigated to Page2, then Navigated to Page3 then the user hit my "< Back" button and in the code I then Navigated To Page1, my Navigation Stack would look like this:
Page1
Page2
Page3
Page1
If I then use the hardware back button (which triggers) goBack it will be Page3, then Page2, then Page1. The user would probably not expect being on Page1 and hitting the back button to put them on Page3 rather than exiting. So unless you are wanting a weird navigation; this would be normally considered unexpected/broken behavior.
Under proper navigation I might do this:
Page1
Page2 (Not stored in History: used "backstackVisible: false")
Page3
Then a Back from Page3 would actually put me in Page1, and a Back from Page 1 would exit the application. This would be the expected behavior.
Now as to the events.
The events for this page are NavigatingTo, Loaded, NavigatedTo -- they fire in that order.
The loaded event being called is not a bug; it is by design; when the page component is loaded -- it allows you to be able to set up the page element. All components have a "loaded" event. So this is a component level event not a page navigation type event. So for example; I've done this before:
<Switch android:loaded="fixAndroidSwitch"/> and then my fixAndroidSwitch routine fixed up something on the switch.
The NavigatingTo and NavigatedTo are actual Navigation events, and they do have a value passed as part of the argument:
function onNavigatingTo(context) {
if (context.isBackNavigation) { /* Do whatever */ }
}
For more information on page events; you can read my Blog post http://fluentreports.com/blog/?p=191 and it explains more
Related
I've three pages first showing List of my items on tap I'm redirecting it to a History Page with Object defined with static property with
await Shell.Current.GoToAsync($"/{nameof(DeviceHistoryPage)}");
then from this page i'm again redirecting user to show more details of each history item to next page with data as static property
await Shell.Current.GoToAsync($"/{nameof(DeviceHistoryDetailsPage)}");
I'm able to achieve this navigation and able to move back and forth from first page to second page but from second page once redirected to third page and i'm not able return back to previous page with back button present in navbar
Also I've tried registering routes as independent as well as a child in AppShell as follows
Routing.RegisterRoute($"{nameof(ListPage)}/{nameof(HistoryPage)}", typeof(HistoryPage));
Routing.RegisterRoute($"{nameof(HistoryPage)}/{nameof(HistoryDetailsPage)}", typeof(HistoryDetailsPage));
I saw some examples where people had placed them in the page constructor. They then unsubscribe in the OnDisappearing().
I have my pages ViewModel send messages and these are then picked up in the back end page C#. But the problem for me is that my page gets constructed once, I then do this to go to other pages:
Navigation.PushAsync(new VersionPage())
and my subscriptions are lost.
Would appreciate some advice on how to handle this.
I assume you are subscribed on Page1 and you want to navigate to Page2 then, in Page2 you want to call send messaging?
What I would do in this case, I would have boolean value that can be set so that on ondisappearing of Page1, it does not unsubscribe.
I personally dont like using messaging center..
What I would do instead because Page 1 or Page1's viewmodel would be responsible for creation of the Page 2, while creation, I would bind an event to disappearing of Page2 to do something for Page1 when Page2 have finished with something or if it required to do something while Page2 still the mainpage, then create a custom event and bind event to that, so that in Page2, you can invoke that event when you needed..
You can unbind all the event on disappearing of page2 for cleaning up memory loss which is I think its much cleaner in a way of managing and garbaging when not needed.
History of my pages / activities is:
Home page (page0).
List of issues (page1).
Detail card of issue (page2).
Popup for confirmation to delete issue (not a page because of JQM popup isn't a page).
When I confirm deletion of issue and delete it, there is no reason to return back to page2 (it's content dropped). The only valid transition here - from popup to list of issues (back twice).
BUT.
When I jump from popup to page1 by $.mobile.changePage, history saves page2 as previous page (because jump was started at page2' popup).
So, when I press back on page1 I expect to return on page0 (rewind history), but returns to page2 which is invalid.
Guess valid behaviour here is:
Jump from popup to page1.
Erase page2 and popup from history at all - or something similar.
How to do it?
I have one issue in my program, i have three pages in my program, Main page, first page and second page. I'm able to navigate from the main page to the first page and from the first page to the second page. I have a stack panel in the first page. It consists of children which are dynamically created from the db. This page contains a OnNavigateTo method, for bringing the elements from the main page and displaying it, And i wrote my codings in this method to add dynamically children to the stackpanel. when navigating back from the second page to the first page, the compiler will goes to the OnNavigateTo method and regenerate the children of the stackpanel once again.
My problem is:
i want to show the previously displayed first page with all the data, when the back button is pressed. I doesn't want the page to regenerate again. I want the static page which i have previously when i go back from the second page to the first page.
How to do it? please help me with some piece of code... Thank You..
Do the logic in the constructor, because it doesn't get called when navigating back (unless the app has been tombstoned). OnNavigatedTo gets called every time no matter how you navigate to the page.
Read this for more info:
WP7 Development Tip of the Day: Page Startup: The Constructor
In my program I have the main window in the background which has a smaller, UIScrollView on it. I have buttons on each page of the scroll view which I want to bring up a modal view that can be dissmissed. It works fine for the first page, however, when I click the button on the second page of the scroll view the modal view that is brought up is on top of the first page instead of the second and the second page is completely blank. When I close the modal view, the first page has been replaced with the second page and the second page is still left blank... The code I am using is:
MVC = new NewsModalViewController(this);
MVC.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
MVC.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
I've been trying to play around with the frames but having no luck...
Any insights?
Cheers
I would rewrite the subpages to fire an event that the parent view listens to. Then, display the modal from the parent view (you can actually create the modal in the child view and pass it up on the event). This eliminates any problems with the modal being applied to the wrong context.
There may be another explanation, but this is the method I've implemented on a couple applications and has served me well. It appears that modals are best displayed only from the highest level view in the stack.