FreshMvvm icon indicating copy to clipboard operation
FreshMvvm copied to clipboard

How given sample works for ReverseInit?

Open EmilAlipiev opened this issue 9 years ago • 9 comments

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);
        }
    }

EmilAlipiev avatar Feb 22 '17 22:02 EmilAlipiev

I'm not sure what this questions is asking?

rid00z avatar Feb 22 '17 22:02 rid00z

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.

EmilAlipiev avatar Feb 25 '17 18:02 EmilAlipiev

fwiw, I wouldn't mind knowing this as well.

bassfan avatar Feb 27 '17 03:02 bassfan

ReverseInit is only called when data is present.

Do you think it should always be called? There's always the appearing methods?

rid00z avatar Feb 27 '17 04:02 rid00z

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.

bassfan avatar Mar 01 '17 04:03 bassfan

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.

EmilAlipiev avatar Mar 01 '17 10:03 EmilAlipiev

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.

stevechadbourne avatar Feb 25 '20 03:02 stevechadbourne

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).

djunod avatar Dec 31 '20 03:12 djunod

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);
    }
}

djunod avatar Dec 31 '20 03:12 djunod