Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/Controls/src/Core/Handlers/Items2/CollectionViewHandler2.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Foundation;
using Microsoft.Maui.Handlers;
Expand Down Expand Up @@ -203,20 +204,29 @@ void SubscribeToItemsLayoutPropertyChanged(IItemsLayout itemsLayout)
{
if (itemsLayout is not null)
{
itemsLayout.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(ItemsLayout.SnapPointsAlignment) ||
args.PropertyName == nameof(ItemsLayout.SnapPointsType) ||
args.PropertyName == nameof(GridItemsLayout.VerticalItemSpacing) ||
args.PropertyName == nameof(GridItemsLayout.HorizontalItemSpacing) ||
args.PropertyName == nameof(GridItemsLayout.Span) ||
args.PropertyName == nameof(LinearItemsLayout.ItemSpacing))

{
UpdateLayout();
}
};
itemsLayout.PropertyChanged -= ItemsLayoutPropertyChanged;
itemsLayout.PropertyChanged += ItemsLayoutPropertyChanged;
}
}

void ItemsLayoutPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ItemsLayout.SnapPointsAlignment) ||
e.PropertyName == nameof(ItemsLayout.SnapPointsType) ||
e.PropertyName == nameof(GridItemsLayout.VerticalItemSpacing) ||
e.PropertyName == nameof(GridItemsLayout.HorizontalItemSpacing) ||
e.PropertyName == nameof(GridItemsLayout.Span) ||
e.PropertyName == nameof(LinearItemsLayout.ItemSpacing))

{
UpdateLayout();
}
}

protected override void DisconnectHandler(UIView platformView)
{
ItemsView.ItemsLayout.PropertyChanged -= ItemsLayoutPropertyChanged;
base.DisconnectHandler(platformView);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ virtual Microsoft.Maui.Controls.BindableProperty.CreateDefaultValueDelegate<TDec
~virtual Microsoft.Maui.Controls.BindableProperty.ValidateValueDelegate<TPropertyType>.Invoke(Microsoft.Maui.Controls.BindableObject bindable, TPropertyType value) -> bool
~virtual Microsoft.Maui.Controls.CollectionSynchronizationCallback.Invoke(System.Collections.IEnumerable collection, object context, System.Action accessMethod, bool writeAccess) -> void
~virtual Microsoft.Maui.Controls.Internals.EvaluateJavaScriptDelegate.Invoke(string script) -> System.Threading.Tasks.Task<string>
~virtual Microsoft.Maui.Controls.PropertyChangingEventHandler.Invoke(object sender, Microsoft.Maui.Controls.PropertyChangingEventArgs e) -> void
~virtual Microsoft.Maui.Controls.PropertyChangingEventHandler.Invoke(object sender, Microsoft.Maui.Controls.PropertyChangingEventArgs e) -> void
~override Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2.DisconnectHandler(UIKit.UIView platformView) -> void
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

The introduction of a new override for DisconnectHandler in the public API could constitute a breaking change. Please ensure that the public documentation is updated accordingly and that consumers are aware of this update.

Copilot uses AI. Check for mistakes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ virtual Microsoft.Maui.Controls.BindableProperty.CreateDefaultValueDelegate<TDec
~virtual Microsoft.Maui.Controls.BindableProperty.ValidateValueDelegate<TPropertyType>.Invoke(Microsoft.Maui.Controls.BindableObject bindable, TPropertyType value) -> bool
~virtual Microsoft.Maui.Controls.CollectionSynchronizationCallback.Invoke(System.Collections.IEnumerable collection, object context, System.Action accessMethod, bool writeAccess) -> void
~virtual Microsoft.Maui.Controls.Internals.EvaluateJavaScriptDelegate.Invoke(string script) -> System.Threading.Tasks.Task<string>
~virtual Microsoft.Maui.Controls.PropertyChangingEventHandler.Invoke(object sender, Microsoft.Maui.Controls.PropertyChangingEventArgs e) -> void
~virtual Microsoft.Maui.Controls.PropertyChangingEventHandler.Invoke(object sender, Microsoft.Maui.Controls.PropertyChangingEventArgs e) -> void
~override Microsoft.Maui.Controls.Handlers.Items2.CollectionViewHandler2.DisconnectHandler(UIKit.UIView platformView) -> void
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

The introduction of a new override for DisconnectHandler in the public API could constitute a breaking change. Please ensure that the public documentation is updated accordingly and that consumers are aware of this update.

Copilot uses AI. Check for mistakes.
56 changes: 56 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27666.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 27666, "Vertical list and Vertical grid pages have different abnormal behaviors when clicking Update after changing the spacing value", PlatformAffected.iOS | PlatformAffected.macOS)]

public class Issue27666_NavigationPage : TestNavigationPage
{
protected override void Init()
{
var root = CreateRootContentPage();
PushAsync(root);
}

ContentPage CreateRootContentPage()
{
ContentPage ContentPage = new ContentPage();

VerticalStackLayout rootLayout = new VerticalStackLayout
{
Spacing = 10,
Padding = new Thickness(10),
};

Button collectionViewButton = new Button
{
Text = "Navigate to VerticalList CollectionView",
AutomationId = "NavigationButton"
};
collectionViewButton.Clicked += (s, e) => Navigation.PushAsync(new Issue27666());

rootLayout.Add(collectionViewButton);
ContentPage.Content = rootLayout;
return ContentPage;
}
}

public partial class Issue27666 : ContentPage
{
ObservableCollection<string> items;

public Issue27666()
{
InitializeComponent();
items = new ObservableCollection<string>(Enumerable.Range(1, 30).Select(i => $"Item {i}"));
collectionView.ItemsSource = items;
}

private void OnItemSpacingButtonClicked(object sender, EventArgs e)
{
if (collectionView.ItemsLayout is LinearItemsLayout layout)
{
layout.ItemSpacing = layout.ItemSpacing == 0 ? 50 : 20;
}
}
}
32 changes: 32 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27666.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue27666">

<Grid RowSpacing="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Button Grid.Row="0"
Text="Update ItemSpacing"
AutomationId="UpdateItemSpacingButton"
Clicked="OnItemSpacingButtonClicked"/>

<CollectionView x:Name="collectionView"
Grid.Row="1"
AutomationId="ItemsLayoutCollectionView"
ItemsLayout="HorizontalList">
<CollectionView.ItemTemplate>
<DataTemplate>
<Border Padding="10"
Margin="5"
BackgroundColor="LightGray">
<Label Text="{Binding .}"/>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue27666 : _IssuesUITest
{
public override string Issue => "Vertical list and Vertical grid pages have different abnormal behaviors when clicking Update after changing the spacing value";
const string UpdateItemSpacingButton = "UpdateItemSpacingButton";
const string ItemsLayoutCollectionView = "ItemsLayoutCollectionView";
const string NavigationButton = "NavigationButton";
public Issue27666(TestDevice device) : base(device) { }

[Test]
[Category(UITestCategories.CollectionView)]
public void VerifySpacingUpdateInItemsLayout()
{
App.WaitForElement(NavigationButton);
App.Tap(NavigationButton);
App.WaitForElement(ItemsLayoutCollectionView);
App.Tap(UpdateItemSpacingButton);
App.TapBackArrow();
App.WaitForElement(NavigationButton);
App.Tap(NavigationButton);
App.WaitForElement(ItemsLayoutCollectionView);
App.Tap(UpdateItemSpacingButton);
App.WaitForElement(ItemsLayoutCollectionView);
}
}