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
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 @@
_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 Expand Up @@ -562,7 +581,7 @@
{
// Get the viewport of the UICollectionView at the current content offset
var contentOffset = CollectionView.ContentOffset;
var viewport = new CGRect(contentOffset, CollectionView.Bounds.Size);

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Pack .NET MAUI Pack macOS)

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Pack .NET MAUI Pack macOS)

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Pack .NET MAUI Pack macOS)

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Pack .NET MAUI Pack macOS)

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Release))

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

Check failure on line 584 in src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

View check run for this annotation

Azure Pipelines / maui-pr (Build .NET MAUI Build macOS (Debug))

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs#L584

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs(584,26): error CS0102: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'LayoutFactory2.CustomUICollectionViewCompositionalLayout' already contains a definition for 'CollectionViewContentSize'

// Find the spot in the viewport we're trying to align with
var alignmentTarget = Items.SnapHelpers.FindAlignmentTarget(alignment, contentOffset, CollectionView, Configuration.ScrollDirection);
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 | PlatformAffected.macOS)]
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,31 @@
#if ANDROID || IOS // ScrollRight with ScrollStrategy.Gesture is not supported on Windows and MacCatalyst
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).Within(1),
$"EmptyViewLabel X position changed from {rectBefore.X} to {rectAfter.X}. " +
"CollectionView must NOT scroll horizontally when empty inside a RefreshView.");
}
}
#endif
Loading