Caliburn-Micro / Caliburn.Micro

A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
http://caliburnmicro.com/
MIT License
2.79k stars 775 forks source link

Fix activation for nested conductor / screen scenarios #898

Open Yinimi opened 4 months ago

Yinimi commented 4 months ago

There have been some discussions and changes related to when OnActivate() is called.

593 He wanted to use IsInitialized / IsActive to control the visibility of some loading indicator. If the property is set to true before the OnActivate / OnInitialize call it will obviously not be able to use it for determining if the loading has finished.

I can understand the reason for this request but I think a method called OnActivate() should be called after the IsActive is set to true, otherwise Activating or BeforeActivate are better names in my opinion.

Since some devs (like me) want to use OnActivate() to trigger the initializing of the ViewModel there are scenarios where it is problematic if the IsActive is not set yet. I created the ActivateWhileActivateOneLevel() test method to demonstrate it. To provide such a method @erik-hooper added with #859 a OnActivated() method which is called after the property has been set. If I use this method with another test ActivatedWhileActivatedOneLevel() The issue is resolved.

I have a more complicated and nested scenario. example Test

In my app the inner conductor handles the navigation depending on some configuration. The outer conductor handles basic stuff and also the display of the user preferences ("some Page"). If the View 1 now wants automatically to continue after the user preferences have been shown (think of auto login was just enabled) then in this nested scenario the View 2 will not be initialized because all this is triggered by the OnActivate() method of the inner conductor.

With this change the behavior should be like before the changes of #593 where the active item(s) are activated after the conductor has IsActive enabled.

In #789 it was also discussed to add something like BeforeActivate and AfterActivate. I added a OnInitializedAsync() to adress this as well. I didn't touch the OnViewLoaded (it was wished to make this async), this looks more complicated.

Yinimi commented 4 months ago

If the next release is 5 then it would also be ok to rename the methods. (OnActivate and OnInitialize) Eventually OnActivate => BeforeActivate, OnActivated => OnActivate (to make things as complicated as possible)

vb2ae commented 4 months ago

Yes the next release is version 5

Yinimi commented 4 months ago

I added the obsolete messages

Yinimi commented 4 months ago

I think #764 Is also resolved with this change

a44281071 commented 4 months ago

asp.net Blazor use void OnAfterRender() and Task OnAfterRenderAsync() for view update. And use void OnInitialized() and Task OnInitializedAsync() for init load.

ASP.NET Core Razor component lifecycle:

Component initialization

Yinimi commented 4 months ago

If I read the build pipeline log correct the android 28 sdk is missing? Is the pipeline running on a specific machine with a build agent? Then it would probably be required to install it there manually

vb2ae commented 3 months ago

Working on a fix for android version in another branch