Skip to content

Commit

Permalink
Make Add/Remove Logical public (#16046)
Browse files Browse the repository at this point in the history
* Make Add/Remove Logical public

* -fix xaml unit test errors

* - remove workarounds and fix up tests

* - apply style sheets to visual children

* - fix issues

* - fix test paths that don't use Element

* - fix merge conflicts

* - add public APIs

* - add comments

* - add additional tests

* - additional cleanup

* - fix loaded/loaded timings

* - add longer wait for android

* - fix usage of LogicalChildren

* - if no index is specifiied add items at the end

* - fix added event to properly set _watchingPlatformLoaded

* - cleanup

* - ensure that loaded/unloaded have time to fire

* - change name to index

* - remove collection changed comment

* - remove shadowed methods and add docs
  • Loading branch information
PureWeen committed Jul 18, 2023
1 parent cd7a0e0 commit 6136a8a
Show file tree
Hide file tree
Showing 48 changed files with 349 additions and 446 deletions.
44 changes: 0 additions & 44 deletions src/Controls/docs/Microsoft.Maui.Controls/ItemsView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,6 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="AddLogicalChild">
<MemberSignature Language="C#" Value="public void AddLogicalChild (Microsoft.Maui.Controls.Element element);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void AddLogicalChild(class Microsoft.Maui.Controls.Element element) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Maui.Controls.ItemsView.AddLogicalChild(Microsoft.Maui.Controls.Element)" />
<MemberSignature Language="F#" Value="member this.AddLogicalChild : Microsoft.Maui.Controls.Element -&gt; unit" Usage="itemsView.AddLogicalChild element" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Maui.Controls.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="element" Type="Microsoft.Maui.Controls.Element" />
</Parameters>
<Docs>
<param name="element">To be added.</param>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="EmptyView">
<MemberSignature Language="C#" Value="public object EmptyView { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance object EmptyView" />
Expand Down Expand Up @@ -530,28 +508,6 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="RemoveLogicalChild">
<MemberSignature Language="C#" Value="public void RemoveLogicalChild (Microsoft.Maui.Controls.Element element);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void RemoveLogicalChild(class Microsoft.Maui.Controls.Element element) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Maui.Controls.ItemsView.RemoveLogicalChild(Microsoft.Maui.Controls.Element)" />
<MemberSignature Language="F#" Value="member this.RemoveLogicalChild : Microsoft.Maui.Controls.Element -&gt; unit" Usage="itemsView.RemoveLogicalChild element" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Maui.Controls.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="element" Type="Microsoft.Maui.Controls.Element" />
</Parameters>
<Docs>
<param name="element">To be added.</param>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Scrolled">
<MemberSignature Language="C#" Value="public event EventHandler&lt;Microsoft.Maui.Controls.ItemsViewScrolledEventArgs&gt; Scrolled;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler`1&lt;class Microsoft.Maui.Controls.ItemsViewScrolledEventArgs&gt; Scrolled" />
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/src/Core/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ internal void RemoveWindow(Window window)

if (window is Element windowElement)
{
RemoveLogicalChildInternal(windowElement);
RemoveLogicalChild(windowElement);
}

_windows.Remove(window);
Expand Down Expand Up @@ -518,7 +518,7 @@ void AddWindow(Window window)

if (window is Element windowElement)
{
AddLogicalChildInternal(windowElement);
AddLogicalChild(windowElement);
}

if (window is NavigableElement ne)
Expand Down
7 changes: 1 addition & 6 deletions src/Controls/src/Core/BindableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,12 @@ public static void SetInheritedBindingContext(BindableObject bindable, object va
protected virtual void OnBindingContextChanged()
{
BindingContextChanged?.Invoke(this, EventArgs.Empty);

if (Shell.GetBackButtonBehavior(this) is BackButtonBehavior buttonBehavior)
SetInheritedBindingContext(buttonBehavior, BindingContext);

if (Shell.GetSearchHandler(this) is SearchHandler searchHandler)
SetInheritedBindingContext(searchHandler, BindingContext);

if (Shell.GetTitleView(this) is View titleView)
SetInheritedBindingContext(titleView, BindingContext);

if (FlyoutBase.GetContextFlyout(this) is BindableObject contextFlyout)
SetInheritedBindingContext(contextFlyout, BindingContext);
}

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
Expand Down
12 changes: 12 additions & 0 deletions src/Controls/src/Core/BindableObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public static T GetPropertyIfSet<T>(this BindableObject bindableObject, Bindable
return false;
}

internal static void AddRemoveLogicalChildren(this BindableObject bindable, object oldValue, object newValue)
{
if (!(bindable is Element owner))
return;

if (oldValue is Element oldView)
owner.RemoveLogicalChild(oldView);

if (newValue is Element newView)
owner.AddLogicalChild(newView);
}

internal static bool TrySetAppTheme(
this BindableObject self,
string lightResourceKey,
Expand Down
10 changes: 4 additions & 6 deletions src/Controls/src/Core/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ void NotifyStrokeShapeChanges()

if (strokeShape is VisualElement visualElement)
{
SetInheritedBindingContext(visualElement, BindingContext);
visualElement.Parent = this;
AddLogicalChild(visualElement);
_strokeShapeChanged ??= (sender, e) => OnPropertyChanged(nameof(StrokeShape));
_strokeShapeProxy ??= new();
_strokeShapeProxy.Subscribe(visualElement, _strokeShapeChanged);
Expand All @@ -78,8 +77,7 @@ void StopNotifyingStrokeShapeChanges()

if (strokeShape is VisualElement visualElement)
{
SetInheritedBindingContext(visualElement, null);
visualElement.Parent = null;
RemoveLogicalChild(visualElement);
_strokeShapeProxy?.Unsubscribe();
}
}
Expand Down Expand Up @@ -268,12 +266,12 @@ public static void ContentChanged(BindableObject bindable, object oldValue, obje
{
if (oldValue is Element oldElement)
{
border.RemoveLogicalChildInternal(oldElement);
border.RemoveLogicalChild(oldElement);
}

if (newValue is Element newElement)
{
border.AddLogicalChildInternal(newElement);
border.AddLogicalChild(newElement);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Cells/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public void SendDisappearing()

void IPropertyPropagationController.PropagatePropertyChanged(string propertyName)
{
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, ((IElementController)this).LogicalChildren);
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, ((IVisualTreeElement)this).GetVisualChildren());
}

void OnContextActionsChanged(object sender, NotifyCollectionChangedEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/src/Core/Cells/ViewCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public View View

if (_view != null)
{
RemoveLogicalChildInternal(_view);
RemoveLogicalChild(_view);
_view.ComputedConstraint = LayoutConstraint.None;
}

Expand All @@ -32,7 +32,7 @@ public View View
if (_view != null)
{
_view.ComputedConstraint = LayoutConstraint.Fixed;
AddLogicalChildInternal(_view);
AddLogicalChild(_view);
}

ForceUpdateSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ void Reset()
void SetControllers()
{
var list = new List<UIViewController>();
var logicalChildren = ((IElementController)Element).LogicalChildren;
for (var i = 0; i < logicalChildren.Count; i++)
var pages = Tabbed.InternalChildren;
for (var i = 0; i < pages.Count; i++)
{
var child = logicalChildren[i];
var child = pages[i];
var v = child as Page;
if (v == null)
continue;
Expand Down

0 comments on commit 6136a8a

Please sign in to comment.