Skip to content
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

[Windows] Notify changes in CollectionView Layouts #13137

Merged
merged 9 commits into from
Mar 15, 2023
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#nullable disable
using System;
using System.ComponentModel;
using Microsoft.Maui.Controls.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using WASDKApp = Microsoft.UI.Xaml.Application;
using WListView = Microsoft.UI.Xaml.Controls.ListView;
using WScrollMode = Microsoft.UI.Xaml.Controls.ScrollMode;
using WSetter = Microsoft.UI.Xaml.Setter;
using WStyle = Microsoft.UI.Xaml.Style;
Expand All @@ -17,6 +19,32 @@ public partial class StructuredItemsViewHandler<TItemsView> : ItemsViewHandler<T

protected override IItemsLayout Layout { get => ItemsView?.ItemsLayout; }

protected override void ConnectHandler(ListViewBase platformView)
{
base.ConnectHandler(platformView);

if (Layout != null)
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
Layout.PropertyChanged += LayoutPropertyChanged;
}

protected override void DisconnectHandler(ListViewBase platformView)
{
base.DisconnectHandler(platformView);

if (Layout != null)
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
Layout.PropertyChanged -= LayoutPropertyChanged;
}

void LayoutPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == GridItemsLayout.SpanProperty.PropertyName)
UpdateItemsLayoutSpan();
else if (e.PropertyName == GridItemsLayout.HorizontalItemSpacingProperty.PropertyName || e.PropertyName == GridItemsLayout.VerticalItemSpacingProperty.PropertyName)
UpdateItemsLayoutItemSpacing();
else if (e.PropertyName == LinearItemsLayout.ItemSpacingProperty.PropertyName)
UpdateItemsLayoutItemSpacing();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would look a lot nicer with a switch expression and the removal of the else clauses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with that. In this case, just continued following the if-else approach used so far in Xamarin. https://github.com/xamarin/Xamarin.Forms/blob/caab66bcf9614aca0c0805d560a34e176d196e17/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs#L140

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that was an old code and did not have switch statements, since we are dealing with new code, lets try to update or code base, right?

}

public static void MapHeaderTemplate(StructuredItemsViewHandler<TItemsView> handler, StructuredItemsView itemsView)
{
handler.UpdateHeader();
Expand Down Expand Up @@ -229,5 +257,33 @@ static WStyle GetHorizontalItemContainerStyle(LinearItemsLayout layout)

return style;
}

void UpdateItemsLayoutSpan()
{
if (ListViewBase is FormsGridView formsGridView)
{
formsGridView.Span = ((GridItemsLayout)Layout).Span;
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
}
}

void UpdateItemsLayoutItemSpacing()
{
if (ListViewBase is FormsGridView formsGridView)
{
formsGridView.ItemContainerStyle = GetItemContainerStyle((GridItemsLayout)Layout);
}
else
{
switch (ListViewBase)
{
case FormsListView formsListView:
formsListView.ItemContainerStyle = GetVerticalItemContainerStyle((LinearItemsLayout)Layout);
break;
case WListView listView:
listView.ItemContainerStyle = GetHorizontalItemContainerStyle((LinearItemsLayout)Layout);
break;
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ override Microsoft.Maui.Controls.ImageButton.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.SearchBar.IsEnabledCore.get -> bool
~Microsoft.Maui.Controls.WebView.UserAgent.get -> string
~Microsoft.Maui.Controls.WebView.UserAgent.set -> void
~override Microsoft.Maui.Controls.Handlers.Items.StructuredItemsViewHandler<TItemsView>.ConnectHandler(Microsoft.UI.Xaml.Controls.ListViewBase platformView) -> void
~override Microsoft.Maui.Controls.Handlers.Items.StructuredItemsViewHandler<TItemsView>.DisconnectHandler(Microsoft.UI.Xaml.Controls.ListViewBase platformView) -> void
~static readonly Microsoft.Maui.Controls.WebView.UserAgentProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send<TSender, TArgs>(TSender sender, string message, TArgs args) -> void
*REMOVED*~static Microsoft.Maui.Controls.MessagingCenter.Send<TSender>(TSender sender, string message) -> void
Expand Down