-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TitleView to VisualChildren list for Shell #14006
Add TitleView to VisualChildren list for Shell #14006
Conversation
src/Controls/src/Core/Shell/Shell.cs
Outdated
newView.Parent = owner; | ||
VisualDiagnostics.OnChildAdded((Page)bindable, newView); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just call AddLogicalChild here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add/RemoveLogicalChild are on Shell (
maui/src/Controls/src/Core/Shell/Shell.cs
Line 707 in 9aa30fc
public void RemoveLogicalChild(Element element) |
Bindable
could be a ContentPage (At least going by the unit tests that failed when I did cast to Shell (fc2775f)).
Seeing that this is in Shell, I could check if Bindable is Shell, and if so, call Add/RemoveLogicalChild, but if it's anything else it would be missed. Is that okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so :-)
There's two places we need to account for the TitleView being added
- On the ContentPage
- On the Shell
If it's added on the ContentPage then we want the titleView
to get added to the LogicalChildren of the PAge not shell. If it's added to Shell we want it to get added to the LogicalChildren of Shell not Page
src/Controls/src/Core/Shell/Shell.cs
Outdated
@@ -1316,10 +1326,16 @@ static void OnTitleViewChanged(BindableObject bindable, object oldValue, object | |||
var newView = (View)newValue; | |||
|
|||
if (oldView != null) | |||
{ | |||
VisualDiagnostics.OnChildRemoved((Page)bindable, oldView, ((IVisualTreeElement)bindable).GetVisualChildren().IndexOf(oldView)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just call RemoveLogicalChild here?
I switched Shell to Add/RemoveLogicalChild and that seems to work fine. Page is proving a bit tougher. It has "LogicalChildren", "InternalLogicalChildren" and "InternalChildren". InternalChildren is public, but if I try and add TitleView to it, it seems to get stomped later on by TemplateUtilities.OnContentChanged, where it gets removed and replaced by the actual page content. I think it's possible to refactor all of this down so that "Add/RemoveLogicalChild" is put into "Page" and out of Shell, so all of them can use it, but it'll take a bit more time. |
@PureWeen I removed the The Shell code is independent of it and switching it to use Remove/AddLogicalChild should have that work with whatever new thing is created, so that feels safe to add it as is right now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Can we add some tests for this inside Controls.Core.UnitTests?
Added with 658d298, is this okay? |
Fixes #13992
This adds TitleView into the Visual Tree list, allowing it to be hot reloaded. For this to work, I added IVisualTreeElement to Page and Shell, then overrode the list to include the TitleView, which is an View and automatically has its own children.
2023-03-17.17.56.10.mov