Skip to content

Commit

Permalink
fixed listview measuring for mac and ios
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Dobrynin committed Oct 14, 2024
1 parent 07a36a7 commit 0daf45b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,14 @@ protected virtual bool TriggerResizeLayout()

PrevContentSize = desiredSize;

(this as IView).InvalidateMeasure();
View? view =
#if MACIOS
ListView;
#else
this;
#endif

(view as IView)?.InvalidateMeasure();

return true;
}
Expand All @@ -708,8 +715,7 @@ protected virtual VirtualizeListViewItem CreateDummyItem(DataTemplate template,

protected virtual bool IsOrientation(ScrollOrientation orientation)
{
return ListView!.Orientation == orientation
|| (ListView.Orientation == ScrollOrientation.Neither && ListView.PrevScrollOrientation == orientation);
return ListView!.IsOrientation(orientation);
}

protected virtual Size GetDesiredLayoutSize(double widthConstraint, double heightConstraint, Size availableSpace)
Expand Down Expand Up @@ -763,7 +769,8 @@ public virtual Size Measure(double widthConstraint, double heightConstraint)
MeasureItem(LaidOutItems, view.Item!, availableSpace);
}

return GetDesiredLayoutSize(widthConstraint, heightConstraint, availableSpace);
var desiredSize = GetDesiredLayoutSize(widthConstraint, heightConstraint, availableSpace);
return desiredSize;
}

public virtual Size ArrangeChildren(Rect bounds)
Expand Down
32 changes: 32 additions & 0 deletions MPowerKit.VirtualizeListView/VirtualizeListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,38 @@ public virtual void AdjustScroll(double dx, double dy)
#endif
}

public virtual bool IsOrientation(ScrollOrientation orientation)
{
return Orientation == orientation
|| (Orientation == ScrollOrientation.Neither && PrevScrollOrientation == orientation);
}

protected override Size MeasureOverride(double widthConstraint, double heightConstraint)
{
var size = base.MeasureOverride(widthConstraint, heightConstraint);

var orientation = ScrollOrientation.Neither;
if (IsOrientation(ScrollOrientation.Both)) orientation = ScrollOrientation.Both;
else if (IsOrientation(ScrollOrientation.Vertical)) orientation = ScrollOrientation.Vertical;
else if (IsOrientation(ScrollOrientation.Horizontal)) orientation = ScrollOrientation.Horizontal;

var desiredWidth = size.Width;
if (orientation is ScrollOrientation.Both or ScrollOrientation.Horizontal && HorizontalOptions != LayoutOptions.Fill)
{
desiredWidth = Padding.HorizontalThickness + Margin.HorizontalThickness
+ (Content?.DesiredSize.Width ?? 0d);
}

var desiredHeight = size.Height;
if (orientation is ScrollOrientation.Both or ScrollOrientation.Vertical && VerticalOptions != LayoutOptions.Fill)
{
desiredHeight = Padding.VerticalThickness + Margin.VerticalThickness
+ (Content?.DesiredSize.Height ?? 0d);
}

return new Size(Math.Min(desiredWidth, widthConstraint), Math.Min(desiredHeight, heightConstraint));
}

#region Adapter
public DataAdapter Adapter
{
Expand Down

0 comments on commit 0daf45b

Please sign in to comment.