How given sample works for ReverseInit?
In the sample page there is reverseInit as below. as far as I know reverseInit is only called when we use poppagemodel with data. Should we do poppage everytime when back button is clicked? How can this be handled sofware backbutton?
//This is called when a pushed Page returns to this Page
public override void ReverseInit (object value)
{
var newContact = value as Quote;
if (!Quotes.Contains (newContact)) {
Quotes.Add (newContact);
}
}
I'm not sure what this questions is asking?
according to your sample on the wiki page, you suggest to load ObservableCollection<Quote> inside Init function on QuoteListPageModel .
public override void Init (object initData)
{
Quotes = new ObservableCollection<Quote> (_databaseService.GetQuotes ());
}
Once you Navigate to QuotePageModel fromQuoteListPageModel . Any changes happening there should be updated in QuoteListPageModel once you navigate back. Based on your sample, you use ReverseInit as you described shown below.
//This is called when a pushed Page returns to this Page
public override void ReverseInit (object value)
{
var newContact = value as Quote;
if (!Quotes.Contains (newContact)) {
Quotes.Add (newContact);
}
}
How do you get into ReverseInit ? as I know only way is you need to poppagemodel with data like below,
await CoreMethods.PopPageModel(data: newContact as Quote , modal:true);
this is the only way to get ReverseInit executed in returned page. Is that correct? If yes, that means we must call poppagemodel with data on ViewIsDisappearing or BackButtonPressed functions every time. BackButtonPressed will fail on software back button in Android indeed.
fwiw, I wouldn't mind knowing this as well.
ReverseInit is only called when data is present.
Do you think it should always be called? There's always the appearing methods?
I'm not sure I would go that far. I was just originally confused by the reverseinit vs the viewisappearing method and which one to use. I am indeed using the appearing method just fine and don't have a need to use reverseinit. For a beginner however, it's confusing for something called "init" that it wouldn't be called all the time.
I only wanted to point out that sample on the page is incomplete and misleading. This is not only FreshMvvm problem but general XF problem to get updated from popped out page. viewisappearing is not a good approach indeed when you have a heavy listview with images etc. everytime entire UI is regenerated. you dont even need to navigate but just lock your phone screen and unlock again, it will call viewisappearing.
I think it should always be called. I have been caught out by this twice now (shame on me!) and had to find this issue to realise why it was not being called.
You say that "ReverseInit is only called when data is present." so how do we get there to be "data present" when the back button is pressed? How do we get ReverseInit to be called with data present when the back button is pressed (which causes ViewIsDisappearing to be called).
Figured it out after looking at your source...
protected override async void ViewIsDisappearing(object sender, EventArgs e)
{
base.ViewIsDisappearing(sender, e);
if (PreviousPageModel != null)
{
var dict = new Dictionary<string, string>
{
["Project"] = Settings.SelectedProjectName,
["App"] = Constants.AppAsphalt,
["Lot"] = Lot.AsphaltLotID,
["Action"] = "Add",
};
PreviousPageModel.ReverseInit(dict);
}
}