Skip to content

Commit

Permalink
Backport of #13137 to net7.0 (#15250)
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed May 28, 2023
1 parent 1206048 commit 7c1f069
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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 @@ -16,6 +18,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 is not null)
Layout.PropertyChanged += LayoutPropertyChanged;
}

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

if (Layout is not null)
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();
}

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

return style;
}

void UpdateItemsLayoutSpan()
{
if (ListViewBase is FormsGridView formsGridView)
{
formsGridView.Span = ((GridItemsLayout)Layout).Span;
}
}

void UpdateItemsLayoutItemSpacing()
{
if (ListViewBase is FormsGridView formsGridView && Layout is GridItemsLayout gridLayout)
{
formsGridView.ItemContainerStyle = GetItemContainerStyle(gridLayout);
}

if (Layout is LinearItemsLayout linearItemsLayout)
{
switch (ListViewBase)
{
case FormsListView formsListView:
formsListView.ItemContainerStyle = GetVerticalItemContainerStyle(linearItemsLayout);
break;
case WListView listView:
listView.ItemContainerStyle = GetHorizontalItemContainerStyle(linearItemsLayout);
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable
*REMOVED*override Microsoft.Maui.Controls.RefreshView.MeasureOverride(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Controls.View.ChangeVisualState() -> 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

0 comments on commit 7c1f069

Please sign in to comment.