FreshMvvm icon indicating copy to clipboard operation
FreshMvvm copied to clipboard

Back Button Doesn't Cause PageModel events

Open mathewgrabau opened this issue 10 years ago • 12 comments

Pushing a PageModel using the CoreMethods.PushPageModel<>(object, true); interface does not result in any events being raised if the Android Back button is pushed.

mathewgrabau avatar Aug 15 '15 23:08 mathewgrabau

I'm finding the same thing. In my case I have a secondary page of comments. After a user adds a comment to the initial object, I'd like to pass that back to the initial page in the ReverseInit method. Is this the proper way to do this or should my secondary screen be modal with a close toolbar item that I could use to pop it?

richard-edwards avatar Oct 25 '15 21:10 richard-edwards

This needs fixed.

ghost avatar Nov 23 '15 22:11 ghost

@mathewgrabau @robertbaker @redwards1966 What would you like to happen when the Android back button is pressed?

rid00z avatar Nov 23 '15 22:11 rid00z

Hi Michael, I'd like to see it call the ReverseInit function on the previous model.

richard-edwards avatar Nov 24 '15 11:11 richard-edwards

Has anyone picked this issue up? As a note, I think this issue will likely be tied to the result of this issue: https://github.com/rid00z/FreshMvvm/issues/24 in that the ReverseInit will likely need a similar change.

BNoohi avatar Dec 02 '15 01:12 BNoohi

I haven't picked this up. If you're already there feel free to take a look.

rid00z avatar Dec 02 '15 03:12 rid00z

@redwards1966, In order to make ReverseInit work we need to pass some data to PopPageModel. When user tap on hardware back button we just have no information which data should be passed. The most obvious (and dirty) solution would be to override OnBackPressed in your secondary page and call ReverseInit by hand the same way it is called in the framework source code.

As an alternative (if you don’t want to mess with Pages) you may use ViewIsDisappearing method from FreshBasePageModel, but in that case ReverseInit will be invoked twice in case if user tap on non-hardware back.

@rid00z, not a solution of the current problem, but just to simplify such scenarios I propose to create a FreshBasePage that will fire OnBackPressed and Appearing/Disappearing events to its FreshBasePageModel. Honestly current WireEvents method makes me think about memory leaks. Maybe I’m wrong and everything is fine there, but when I see event subscriptions and do not see unsubscriptions I feel not comfortable. Those changes should not break backward compatibility with current framework. Will you approve that?

olexale avatar Jan 23 '16 22:01 olexale

Is someone working on this? I ran into this today. :)

allenmoatallen avatar Jan 26 '16 22:01 allenmoatallen

ReverseInit was designed to collect data when returning pushed page. It's seems it's being used for more purposes than intended. We can definately add the ability if everyone would like like it.

On the FreshBasePageModel there's appearing and disappearing events, why wouldn't those events work?

rid00z avatar Jan 27 '16 02:01 rid00z

The problem is, that pressing the hardware backbutton does not fire these Events but the virtual Method Page.OnBackButtonPressed is called.

escamoteur avatar Feb 16 '16 20:02 escamoteur

Couldn't it be good to know, in the ViewModel when the Page is dissappearing (could be removed, or Another page could be put on top of it), AND when the page is really popped from the stack?Perhaps some kind of Clean-up should be done when popped from the stack. And it really doesn't matter if it's popped because of some code saying Pop()… or if the user presses a hardware back button.

Or am I missing something here?

Brosten avatar Feb 20 '20 18:02 Brosten

@rid00z Do you mean to say that ReverseInit() is not invoked on the page that was popped? But instead on the page beneath it? (that pushed it)

tele-bird avatar Sep 26 '22 15:09 tele-bird