Skip to content

Commit ce2cc4b

Browse files
committed
Fix endless loop
1 parent e861dc4 commit ce2cc4b

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,35 @@ protected bool IsIndexPathValid(NSIndexPath indexPath)
175175
return true;
176176
}
177177

178+
public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
179+
{
180+
var size = base.GetDesiredSize(widthConstraint, heightConstraint);
181+
182+
var potentialContentSize = Controller.GetSize();
183+
184+
// If contentSize comes back null, it means none of the content has been realized yet;
185+
// we need to return the expansive size the collection view wants by default to get
186+
// it to start measuring its content
187+
if (potentialContentSize == null)
188+
{
189+
return size;
190+
}
191+
192+
var contentSize = potentialContentSize.Value;
193+
194+
// If contentSize does have a value, our target size is the smaller of it and the constraints
195+
196+
size.Width = contentSize.Width <= widthConstraint ? contentSize.Width : widthConstraint;
197+
size.Height = contentSize.Height <= heightConstraint ? contentSize.Height : heightConstraint;
198+
199+
var virtualView = this.VirtualView as IView;
200+
201+
size.Width = ViewHandlerExtensions.ResolveConstraints(size.Width, virtualView.Width, virtualView.MinimumWidth, virtualView.MaximumWidth);
202+
size.Height = ViewHandlerExtensions.ResolveConstraints(size.Height, virtualView.Height, virtualView.MinimumHeight, virtualView.MaximumHeight);
203+
204+
return size;
205+
}
206+
178207
// public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
179208
// {
180209
// var size = base.GetDesiredSize(widthConstraint, heightConstraint);

src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ internal void DisposeItemsSource()
211211
CollectionView.ReloadData();
212212
}
213213

214+
internal Size? GetSize()
215+
{
216+
if (_emptyViewDisplayed)
217+
{
218+
return _emptyUIView.Frame.Size.ToSize();
219+
}
220+
221+
return CollectionView.CollectionViewLayout.CollectionViewContentSize.ToSize();
222+
}
223+
214224
void EnsureLayoutInitialized()
215225
{
216226
if (_initialized)

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nullable enable
22
Microsoft.Maui.Controls.StyleableElement.Style.get -> Microsoft.Maui.Controls.Style?
33
override Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<TElement>.MovedToWindow() -> void
4+
override Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
45
~abstract Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.CreateController(TItemsView newElement, UIKit.UICollectionViewLayout layout) -> Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2<TItemsView>
56
~abstract Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.SelectLayout() -> UIKit.UICollectionViewLayout
67
*REMOVED*~Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker.ShellScrollViewTracker(Microsoft.Maui.IPlatformViewHandler renderer) -> void

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#nullable enable
22
Microsoft.Maui.Controls.StyleableElement.Style.get -> Microsoft.Maui.Controls.Style?
33
override Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<TElement>.MovedToWindow() -> void
4+
override Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
45
~abstract Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.CreateController(TItemsView newElement, UIKit.UICollectionViewLayout layout) -> Microsoft.Maui.Controls.Handlers.Items2.ItemsViewController2<TItemsView>
56
~abstract Microsoft.Maui.Controls.Handlers.Items2.ItemsViewHandler2<TItemsView>.SelectLayout() -> UIKit.UICollectionViewLayout
67
*REMOVED*~Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker.ShellScrollViewTracker(Microsoft.Maui.IPlatformViewHandler renderer) -> void

src/Controls/tests/TestCases.HostApp/Issues/Issue14557.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@ class Issue14557 : TestContentPage
55
{
66
protected override void Init()
77
{
8-
var scrollView = new ScrollView();
8+
var scrollView = new ScrollView
9+
{
10+
BackgroundColor = Colors.Coral,
11+
Padding = 24
12+
};
913

1014
var headerLabel = new Label { AutomationId = "headerLabel", Text = "Foo", };
1115
var footerLabel = new Label { AutomationId = "footerLabel", Text = "Bar" };
1216

13-
var collectionView = new CollectionView { Header = headerLabel, Footer = footerLabel, AutomationId = "collectionView" };
17+
var collectionView = new CollectionView
18+
{
19+
Header = headerLabel,
20+
Footer = footerLabel,
21+
AutomationId = "collectionView",
22+
BackgroundColor = Colors.Beige,
23+
};
1424

1525
scrollView.Content = collectionView;
1626

17-
Content = scrollView;
27+
Content = new Grid
28+
{
29+
scrollView
30+
};
1831
}
1932
}
2033
}

0 commit comments

Comments
 (0)