question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FRESHMVVM is super slow because It EXECUTES PAGEMODELS ON MASTERDETAIL

See original GitHub issue

I already created ticket here but this ticket was closed by owner. I cant reopen it. that is why I am creating a new ticket and I believe this is a serious issue. Old issue https://github.com/rid00z/FreshMvvm/issues/44

when you have FreshMasterDetailNavigationContainer as below, it will execute through each PageModel (ViewModel) init and constructor and if you have some initial data loading your view, this will be very expensive on Start of the App. Is there a way to prevent this?

 var masterDetailNav = new FreshMasterDetailNavigationContainer();
        masterDetailNav.Init("Menu", "Menu.png");
        masterDetailNav.AddPage<page1PageModel>("page1", null);
        masterDetailNav.AddPage<page2PageModel>("page2", null);
         masterDetailNav.AddPage<page3PageModel>("page3", null);
        masterDetailNav.AddPage<page4PageModel>("page4", null);
        masterDetailNav.AddPage<page5PageModel>("page5", null);

At the moment i have moved my getData functions on ViewAppering but this is not a good solution. We cant consider Appearing event as a solution, it has totally different purpose. It makes app quite inefficient if we load the data every time navigating back and forth. even it loads when switching between apps, as the name said whenever screen appears. It will be even executed when you lock your phone screen and unlock when app is on frontground. We seriously need a solution for this.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
fgiacomellicommented, Aug 16, 2018

There’s any news on this?

2reactions
Ebsancommented, May 18, 2017

You’re right and I don’t think there’s any other event we can wire up to. Per Xamarin documentation there are 3 events for a page’s lifetime:

  1. Appearing
  2. Dissappearing
  3. LayoutChanged

And Appearing “…indicates that the Page is about to appear.” It calls the OnAppearing() method which “allows application developers to customize behavior immediately prior to the Page becoming visible.” The FreshBasePageModel (lines 66-70) class wires the ‘Appearing’ event to ViewIsAppearing().

To answer your question I think this is the right place because this method is called right before the page is even shown. The added bonus to this is that the DataContext for binding is set by this point as well. I think this is the best place to call data fetching methods because you can also show the user a loading icon to let them know that there is a long running operation in progress.

To alleviate the issue where the method gets called during different navigation scenarios I check the data before populating it again. @EmilAlipiev solution works but this method will also take care of cases where the app gets rehydrated from a state that no longer has that data populated. You can even place a time-elapsed check so you can always be sure the data presented is as fresh as possible.

public class SamplePageModel : FreshBasePageModel 
{
  private ObservableCollection<string> _projects = new ObservableCollection<string>();

  public override void Init(object initData)
  {
      base.Init(initData);
      Log.Information("Initializing the SelectProjectPage ViewModel.");
  }

  protected override async void ViewIsAppearing(object sender, EventArgs e)
  {
      if (!_projects.Any())
      {
          await PopulateProjectsWithLongRunningTask();
      }
  }
  .........
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

A brand new website interface for an even better experience!
FRESHMVVM is super slow because It EXECUTES PAGEMODELS ON MASTERDETAIL. ... Coming soon: A brand new website interface for an even better experience!...
Read more >
Michael Ridland - RSSing.com
In past posts I've already introduced the FreshMvvm framework for Xamarin. ... In this example I'm using a MasterDetail for the Phone and...
Read more >
Xamarin Archives - Page 5 of 6 - Michael Ridland
FreshMvvm is designed to be easy and simple. So getting started is also fairly simple. Step 1. Start new project. Start a new...
Read more >
Xamarin.Forms MVVM Made Easy with FreshMvvm Framework
In this video we will see FreshMvvm, the MVVM framework that I love using in my ... #XamarinForms # FreshMvvm #MVVM #MVVMFramework #...
Read more >
Recently Active 'xamarin.forms' Questions - Page 40
My project (Xamarin.Forms with FreshMVVM) contains multiple pages and I need property isBusy. My PageModels inherit from FreshBasePageModel class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found