Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 19 additions & 0 deletions src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,25 @@ public CustomUICollectionViewCompositionalLayout(LayoutSnapInfo snapInfo, UIColl
_itemsUpdatingScrollMode = itemsUpdatingScrollMode;
}

// UICollectionViewCompositionalLayout can report a content width larger than the viewport
// after a bounds change (e.g. when inside a RefreshView). This causes UIScrollView to
// enable horizontal scrolling on a vertical layout. Clamp the width to the actual bounds. (#34165)
public override CGSize CollectionViewContentSize
{
get
{
var size = base.CollectionViewContentSize;
if (Configuration.ScrollDirection == UICollectionViewScrollDirection.Vertical
&& CollectionView is not null
&& size.Width > CollectionView.Bounds.Width
&& CollectionView.Bounds.Width > 0)
{
return new CGSize(CollectionView.Bounds.Width, size.Height);
}
return size;
}
}

public override void FinalizeCollectionViewUpdates()
{
base.FinalizeCollectionViewUpdates();
Expand Down
39 changes: 39 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue34165.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 34165, "CollectionView is scrolling left/right when the collection is empty and inside a RefreshView", PlatformAffected.iOS)]
Comment thread
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
public class Issue34165 : ContentPage
{
public const string CollectionViewId = "CollectionView";
public const string EmptyViewLabelId = "EmptyViewLabel";
public const string RefreshViewId = "RefreshView";

public Issue34165()
{
var emptyViewLabel = new Label
{
Text = "No items — swipe left/right here to test",
AutomationId = EmptyViewLabelId,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
};

var collectionView = new CollectionView
{
AutomationId = CollectionViewId,
EmptyView = emptyViewLabel,
};

var refreshView = new RefreshView
{
AutomationId = RefreshViewId,
Content = collectionView,
};

refreshView.Refreshing += (s, e) =>
{
((RefreshView)s!).IsRefreshing = false;
};

Content = refreshView;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

[Category(UITestCategories.RefreshView)]
public class Issue34165 : _IssuesUITest
Comment thread
praveenkumarkarunanithi marked this conversation as resolved.
{
public Issue34165(TestDevice testDevice) : base(testDevice) { }

public override string Issue => "CollectionView is scrolling left/right when the collection is empty and inside a RefreshView";

[Test]
public void EmptyCollectionViewInsideRefreshViewShouldNotScrollHorizontally()
{
App.WaitForElement("CollectionView");

var rectBefore = App.WaitForElement("EmptyViewLabel").GetRect();

App.ScrollRight("CollectionView", ScrollStrategy.Gesture, swipePercentage: 0.8, swipeSpeed: 300);

var rectAfter = App.WaitForElement("EmptyViewLabel").GetRect();

Assert.That(rectAfter.X, Is.EqualTo(rectBefore.X),
Comment thread
praveenkumarkarunanithi marked this conversation as resolved.
Outdated
$"EmptyViewLabel X position changed from {rectBefore.X} to {rectAfter.X}. " +
"CollectionView must NOT scroll horizontally when empty inside a RefreshView.");
}
}
Loading