New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
ViewDestroy lifecycle method is broken #3158
Comments
Hi, ViewDestroy method is very important in view lifecycle (releasing resources, unsubscribing, etc) and fact that is called whenever view disappears is really critical bug. |
I think ViewDestroy was not being called before, since obviously classes like I'm not sure removing the call to |
@nmilcoff As I good understood changes made by author of commit 32b6868 was aimed at fix of lack of call to ViewDestroy by adding it to ViewDisappearing. From my perspective this is not a fix beacuse we cannot differentiate between view destruction and hiding. As @arkadiuszokon said the ideal fix would be when:
|
@piotrekbigu please don't ask when it is going to be fixed. Instead, if it is such a pressing matter for you, open a PR fixing this and it will most likely get out next time we release. |
Since In the past |
This could be fixed by creating custom renderers for all of the MvvmCross pages in each platform and making to call to
I'm not setup to build/develop on the mvvmcross solution on my machine (i don't have a windows vm). Otherwise I'd look at submitting a PR for this. |
@keannan5390 although that approach works, it's not ideal from a design perspective. If a developer wants to write a custom renderer for a page (and of course is using MvvmCross), our custom renderer will needs to be the base class for it - otherwise ViewDestroy won't be called. |
@nmilcoff Understandable from a design perspective that it doesn't make sense. Forcing the mvx renderers wouldn't work in all situations. However, as the OP calls out, I believe this is a broken implementation currently -- especially if you are using the Right now, ViewDestroy is called from ViewDisappearing in the forms page, this can be problematic as it will result in a navigation task being cancelled. Say we have the following navigation: ViewModelB returns a value to ViewModel A, and ViewModelC returns a result to ViewModelB. When you navigate to C from B, ViewDestroy will be called from PageB->ViewModelB and will cancel the task navigation return task from that ViewModelA created. Alternatively, if you were to background the app (as the OP mentioned) while on ViewModelB that same navigation task between A & B will be cancelled/completed without returning a result to A. I have not upgraded my applications to 6.2 as a result of this. I have one app especially that uses the |
I understand your concern. An idea would be to avoid calling ViewDestroy when navigating forwards, but I don't think Xamarin.Forms exposes that |
A Temporary workaround for this issue for me was to implement a base view-model from
now in xamarin forms i listened to
now when a page popped i send a call to
also dont forget to call |
I added a comment for this on the attached PR, but i'll post here for clarity as well I think i found a more reliable way to properly call the OnDestroy lifecycle of the view models that doesn't rely on developers extending from the MvxFormsApplication or an MvxRenderer. Some variation of the following code should work. Whenever a renderer is disposed at the platform layer, the attached The following could be added to each of the Mvx page implementations:
And the implementation for GetRendererProperty is this:
EDIT: edited to be not android specific |
@MysterDru can you make a PR with your proposal? |
Any news about this issue? |
How can I fix this issue ? I've hit this issue when "waiting" for a result from a modal page. I've tried cloning this repo and making the changes the suggested myself as it looks like the PR is still waiting on approval and it was created back in Feb, however I can't get it to build on my machine. |
馃敊 Regression
commit which breaks this: 32b6868
How we should use ViewDestroy now? It's pointless - it's called every time when application goes to background with "viewFinishing" flag set by default to true.
Old (and correct) behavior
ViewDestroy was called with corresponding native methods of view lifecycle
Current behavior
ViewDestroy is called with OnDisappearing method in mvx view classes.
Reproduction steps
Configuration
Version: 6.2
Platform:
The text was updated successfully, but these errors were encountered: