Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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"
Title="Issue 20294"
x:Class="Maui.Controls.Sample.Issues.Issue20294">
<CollectionView SelectionMode="Single" Margin="10.0" AutomationId="theCollectionView">
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>ONE</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>asdf</x:String>
<x:String>LAST</x:String>
</x:Array>
</CollectionView.ItemsSource>
<CollectionView.ItemsLayout>
<LinearItemsLayout
Orientation="Vertical"
ItemSpacing="15"/>
</CollectionView.ItemsLayout>
<CollectionView.Footer>
<Label HeightRequest="45" Text="FOOTER" AutomationId="FOOTER"/>
</CollectionView.Footer>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<Border AutomationId="{Binding}" StrokeThickness="0.2">
<Label Text="{Binding}" FontSize="20"/>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 20294, "CollectionView containing a Footer and a Border with StrokeThickness set to decimal value crashes on scroll", PlatformAffected.iOS)]
public partial class Issue20294 : ContentPage
{
public Issue20294()
{
InitializeComponent();
}
}
}
11 changes: 5 additions & 6 deletions src/Controls/src/Core/Handlers/Items/iOS/ItemsViewLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ protected virtual void HandlePropertyChanged(PropertyChangedEventArgs propertyCh
}
}

internal virtual void UpdateConstraints(CGSize size)
internal virtual bool UpdateConstraints(CGSize size)
{
if (size.IsCloseTo(_currentSize))
{
return;
return false;
}

ClearCellSizeCache();
Expand All @@ -119,6 +119,7 @@ internal virtual void UpdateConstraints(CGSize size)
ConstrainTo(newSize);

UpdateCellConstraints();
return true;
}

internal void SetInitialConstraints(CGSize size)
Expand Down Expand Up @@ -573,14 +574,12 @@ static void ForceScrollToLastItem(UICollectionView collectionView, ItemsLayout i

public override bool ShouldInvalidateLayoutForBoundsChange(CGRect newBounds)
{
if (newBounds.Size == _currentSize)
if (newBounds.Size.IsCloseTo(_currentSize))
{
return base.ShouldInvalidateLayoutForBoundsChange(newBounds);
}

UpdateConstraints(CollectionView.AdjustedContentInset.InsetRect(newBounds).Size);

return true;
return UpdateConstraints(CollectionView.AdjustedContentInset.InsetRect(newBounds).Size);
}

internal bool TryGetCachedCellSize(object item, out CGSize size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,18 @@ internal void UpdateSubview(object view, DataTemplate viewTemplate, nint viewTag
}

if (formsElement != null)
{
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These changes on this file is just small cleanup and seems we need braces now :)

ItemsView.AddLogicalChild(formsElement);
}

if (formsElement != null)
{
RemeasureLayout(formsElement);
formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated;
}
else if (uiView != null)
else
{
uiView.SizeToFit();
uiView?.SizeToFit();
}
}

Expand All @@ -159,7 +161,9 @@ void UpdateHeaderFooterPosition()
nfloat emptyWidth = emptyView?.Frame.Width ?? 0f;

if (_headerUIView != null && _headerUIView.Frame.X != headerWidth)
{
_headerUIView.Frame = new CoreGraphics.CGRect(-headerWidth, 0, headerWidth, CollectionView.Frame.Height);
}

if (_footerUIView != null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || emptyWidth > 0))
_footerUIView.Frame = new CoreGraphics.CGRect(ItemsViewLayout.CollectionViewContentSize.Width + emptyWidth, 0, footerWidth, CollectionView.Frame.Height);
Expand Down
26 changes: 26 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue20294.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Drawing;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues;

public class Issue20294 : _IssuesUITest
{
public Issue20294(TestDevice device) : base(device) { }

public override string Issue => "CollectionView containing a Footer and a Border with StrokeThickness set to decimal value crashes on scroll";

[Test]
public void ScrollToEndDoesntCrash()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.Windows });

App.ScrollTo("FOOTER");
App.ScrollUp("theCollectionView", ScrollStrategy.Gesture, 0.5);
App.ScrollDown("theCollectionView", ScrollStrategy.Gesture, 0.5);
App.ScrollDown("theCollectionView", ScrollStrategy.Gesture, 0.5);
App.ScrollUp("theCollectionView", ScrollStrategy.Gesture, 0.5);
App.ScrollDown("theCollectionView", ScrollStrategy.Gesture, 0.5);
}
}