Skip to content

Commit

Permalink
Merge pull request #18138 from Youssef1313/scp-itemspresenter
Browse files Browse the repository at this point in the history
fix: Adjust ScrollContentPresenter measure to prevent infinite available size when necessary
  • Loading branch information
Youssef1313 authored Sep 7, 2024
2 parents b2be675 + 565dd04 commit 7064342
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1180,5 +1180,23 @@ public async Task When_Footer_Template()
Assert.AreEqual(SUT.FindVisualChildByType<TextBlock>().Text, "updated footer value");
}

[TestMethod]
[RunsOnUIThread]
public async Task When_Inside_ScrollContentPresenter()
{
var lv = new ListView();
ScrollViewer.SetHorizontalScrollBarVisibility(lv, ScrollBarVisibility.Visible);
ScrollViewer.SetHorizontalScrollMode(lv, ScrollMode.Enabled);
lv.Items.Add("1");

await UITestHelper.Load(lv);

var sv = (ScrollViewer)((Border)VisualTreeHelper.GetChild(lv, 0)).Child;
var itemsPresenter = (ItemsPresenter)sv.Content;

var availableSize = LayoutInformation.GetAvailableSize(itemsPresenter);
Assert.AreNotEqual(double.PositiveInfinity, availableSize.Width);
}

public record MyTextModel(string MyText);
}
11 changes: 11 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ private void PropagateLayoutValues()
#endif
}

internal override bool WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation orientation)
{
return WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(orientation, Panel);
}

private bool WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation orientation, _ViewGroup spPanel)
{
return (spPanel as FrameworkElement)?.WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(orientation) ?? true;
}


protected override Size ArrangeOverride(Size finalSize)
{
// Most of this is inspired by StackPanel's ArrangeOverride
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ void IInsertionPanel.GetInsertionIndexes(Point position, out int first, out int
}
}
}

// In WinUI, this is actually for ModernCollectionBasePanel
internal override bool WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation orientation)
{
return Orientation == orientation;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ItemsWrapGrid/ItemsWrapGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ VirtualizingPanelLayout IVirtualizingPanel.GetLayouter()
}
return _layout;
}

// In WinUI, this is actually for ModernCollectionBasePanel
internal override bool WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation orientation)
{
return Orientation == orientation;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ protected override Size MeasureOverride(Size availableSize)

if (CanVerticallyScroll)
{
if (!sizesContentToTemplatedParent)
var childPreventsInfiniteAvailableHeight = !child.WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation.Vertical);
if (!sizesContentToTemplatedParent && !childPreventsInfiniteAvailableHeight)
{
slotSize.Height = double.PositiveInfinity;
}
}
if (CanHorizontallyScroll)
{
if (!sizesContentToTemplatedParent)
var childPreventsInfiniteAvailableWidth = !child.WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation.Horizontal);
if (!sizesContentToTemplatedParent && !childPreventsInfiniteAvailableWidth)
{
slotSize.Width = double.PositiveInfinity;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.UI/UI/Xaml/UIElement.mux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,5 +1929,8 @@ internal virtual void LeaveImpl(LeaveParams @params)

}
#endif

internal virtual bool WantsScrollViewerToObscureAvailableSizeBasedOnScrollBarVisibility(Orientation horizontal)
=> true;
}
}

0 comments on commit 7064342

Please sign in to comment.