Fix activation for nested conductor / screen scenarios #898
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.