-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Enhancement] Add better life cycle events #2210
Comments
Does this also cover life cycle events for ContentView? or should I create a new Issue? |
Yea @danielmeza we're looking at adding a loaded/unloaded and thinking of attaching those to when a renderer is assigned to a control like Stonis has here https://www.ston.is/xamarin-forms-secrets-renderer-property/ This was one of the things we didn't quite get right with the first implementation of life cycle events. There are a lot of different life cycle points and we're still figuring out what to expose when The link you have there exposes an event when a control is attached and detached to the visual tree which doesn't really map to our currently logical concept for Appearing because there are cases where something might be part of the visual tree but still "Disappeared" I'm curious how different the timing on the events is with https://www.ston.is/xamarin-forms-secrets-renderer-property/ vs https://www.pshul.com/2018/03/27/xamarin-forms-add-views-lifecycle-events/ |
@PureWeen you have right! The link only cover the Loaded/Unloaded from the visual tree, and is only a work around not a solution. |
@PureWeen thanks for sharing Stonis approach for listening when an element is attached to the VisaulTree. This is really helpful for something I am working on 🎉 Is there another issue logged to track work or expectations for the missing event of when a page is fully rendererd aka OnPageLoaded (or first paint)? I couldn't find one when I was searching. |
I think we made nice progress with this in .NET MAUI, unfortunately this won't happen for Xamarin.Forms anymore. If there is anything you'd still like to see, please open an issue on the .NET MAUI repo, thanks everyone for your input here! |
Rationale
Some lifecycle events are currently unavailable, and others are inconsistently supported across platforms Xamarin.Forms supported. To get to them today developers need to write custom page renderers in the platform projects and surface them in Xamarin.Forms. It's a pain, and we can do better!
Example or Ordering Issue
Currently, where MainPage is a TabbedPage you get this:
iOS:
Android:
Implementation
The comment here I think most closely indicates what we want
https://forums.xamarin.com/discussion/comment/240051/#Comment_240051
https://forums.xamarin.com/discussion/comment/240314/#Comment_240314
I've defined these all on VisualElement as they will now just be symmetrical for View and Page
Things to consider
Expected Result
User can subscribe to additional Page and View life cycle events.
Events are consistently fired across all platforms.
Developer rejoicing is heard in the streets. 😃 🎉
Backward Compatibility
Related
https://forums.xamarin.com/discussion/84510/improved-life-cycle-support
The text was updated successfully, but these errors were encountered: