Skip to content

Commit

Permalink
fixed getting desired size for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Dobrynin committed Sep 1, 2024
1 parent b9e97d2 commit e736ac6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
35 changes: 13 additions & 22 deletions MPowerKit.VirtualizeListView/Layouts/VirtualizeItemsLayoutManger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,13 @@ protected virtual void DrawItem(IReadOnlyList<VirtualizeListViewItem> items, Vir

protected virtual bool TriggerResizeLayout()
{
Size desiredSize = new();
if (IsOrientation(ScrollOrientation.Vertical))
{
desiredSize = GetDesiredLayoutSize(AvailableSpace.Width, double.PositiveInfinity);
}
if (IsOrientation(ScrollOrientation.Both)) return false;

var availableSpace = AvailableSpace;

var desiredSize = IsOrientation(ScrollOrientation.Vertical)
? GetDesiredLayoutSize(AvailableSpace.Width, double.PositiveInfinity, availableSpace)
: GetDesiredLayoutSize(double.PositiveInfinity, AvailableSpace.Height, availableSpace);

if (PrevContentSize == desiredSize) return false;

Expand Down Expand Up @@ -710,24 +712,13 @@ protected virtual bool IsOrientation(ScrollOrientation orientation)
|| (ListView.Orientation == ScrollOrientation.Neither && ListView.PrevScrollOrientation == orientation);
}

protected virtual Size GetDesiredLayoutSize(double widthConstraint, double heightConstraint)
protected virtual Size GetDesiredLayoutSize(double widthConstraint, double heightConstraint, Size availableSpace)
{
if (IsOrientation(ScrollOrientation.Both) || LaidOutItems.Count == 0) return new();

#if IOS
if (IsOrientation(ScrollOrientation.Vertical))
{
widthConstraint = Math.Min(widthConstraint, AvailableSpace.Width - ListView.Padding.HorizontalThickness);
}
else
{
heightConstraint = Math.Min(heightConstraint, AvailableSpace.Height - ListView.Padding.VerticalThickness);
}
#endif

return IsOrientation(ScrollOrientation.Vertical)
? new(widthConstraint, LaidOutItems[^1].RightBottomWithMargin.Y)
: new(LaidOutItems[^1].RightBottomWithMargin.X, heightConstraint);
? new(Math.Min(widthConstraint, availableSpace.Width), LaidOutItems[^1].RightBottomWithMargin.Y)
: new(LaidOutItems[^1].RightBottomWithMargin.X, Math.Min(heightConstraint, availableSpace.Height));
}

protected abstract void RepositionItemsFromIndex(IReadOnlyList<VirtualizeListViewItem> items, int index);
Expand Down Expand Up @@ -768,11 +759,11 @@ public virtual Size Measure(double widthConstraint, double heightConstraint)
}
else
#endif
// this triggers item size change when needed
MeasureItem(LaidOutItems, view.Item!, availableSpace);
// this triggers item size change when needed
MeasureItem(LaidOutItems, view.Item!, availableSpace);
}

return GetDesiredLayoutSize(widthConstraint, heightConstraint);
return GetDesiredLayoutSize(widthConstraint, heightConstraint, availableSpace);
}

public virtual Size ArrangeChildren(Rect bounds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>MPowerKit.VirtualizeListView</Title>
<Version>2.0.0</Version>
<Version>2.0.1</Version>
<Authors>MPowerKit,Alex Dobrynin</Authors>
<Description>MAUI Virtualize ListView with smooth scrolling and without platform-specific code</Description>
<Copyright>MPowerKit</Copyright>
Expand Down

0 comments on commit e736ac6

Please sign in to comment.