Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionView ItemSpacing cannot be set below an arbitrary value #4520

Closed
IndianaGary opened this issue Feb 5, 2022 · 8 comments · Fixed by #12811
Closed

CollectionView ItemSpacing cannot be set below an arbitrary value #4520

IndianaGary opened this issue Feb 5, 2022 · 8 comments · Fixed by #12811
Assignees
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-7.0.96 Look for this fix in 7.0.96! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Milestone

Comments

@IndianaGary
Copy link

IndianaGary commented Feb 5, 2022

Description

I am using a CollectionView to present a list of Text items (Labels) in a "green-bar" or "gray-bar" list. Unfortunately, the items cannot be set to abut one another; i.e. the items are always separated by a minimum size gap. Research has shown that this gap size is a function of a hard coded minimum size which was inherited from ListView and, likely from Xamarin Forms.

It is not possible to implement my application with this limitation in place. My application is for Windows Desktop application but the affliction is likely multi-platform since it is found in shared code.

My biggest objection is that setting ItemSpacing to zero does not reduce the gap between items to 0, but to some internally predetermined, non-overridable, minimum. ItemSpacing=0 should mean just that; no gap between items.

A sample application is attached

CollectionViewItemSpacingBug.zip

Steps to Reproduce

  1. Unzip the sample application on a Windows Desktop and open in VS 2022 17.1 Preview 5.0
  2. Build and launch the application.
  3. Observe the gap between the CollectionView rows.

Version with bug

Preview 12 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows SDK 10.0.18362 and later

Did you find any workaround?

No

Relevant log output

I was able to locate the likely culprit. Note that the following is the CollectionView inheritance
hierarchy (code is from the Preview 12 branch):

CollectionView -> GroupableItemsView -> SelectableItemsView -> StructuredItemsView -> ItemsView

ItemsView implements OnMeasure as follows:

protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
{
	// TODO hartez 2018-05-22 05:04 PM This 40,40 is what LV1 does; can we come up with something less arbitrary?
	var minimumSize = new Size(40, 40);

	var scaled = DeviceDisplay.MainDisplayInfo.GetScaledScreenSize();
	var maxWidth = Math.Min(scaled.Width, widthConstraint);
	var maxHeight = Math.Min(scaled.Height, heightConstraint);

	Size request = new Size(maxWidth, maxHeight);

	return new SizeRequest(request, minimumSize);
}

Note hartez comment from 2018 that the minimum size is arbitrarily set to 40, 40, meaning that the item can never be smaller.

@IndianaGary IndianaGary added the t/bug Something isn't working label Feb 5, 2022
@jsuarezruiz jsuarezruiz added this to New in Triage via automation Feb 7, 2022
@jsuarezruiz jsuarezruiz added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Feb 7, 2022
@IndianaGary
Copy link
Author

IndianaGary commented Feb 8, 2022

I did some additional testing using the sample app and confirmed that the fixed minimum row height is indeed the culprit.

  1. Setting HeightRequest on the label to 40 and above increased the height of each item as HeightRequest increased.
  2. Reducing HeightRequest below 40 resulted in the item assuming the specified height, with the difference between that height and 40 remaining as a gap between items. The item is never less than 40 units high.

I am attaching a slightly updated version of the sample code.

CollectionViewItemSpacingBug.zip

@IndianaGary
Copy link
Author

IndianaGary commented Feb 11, 2022

I was able to test the issue on the Android emulator today and can confirm that the issue does not affect Android. I was able to set the item height to 20 with the following result:

AndroidSample

I am unable to test Apple devices...

@shimingsg shimingsg added the s/verified Verified / Reproducible Issue ready for Engineering Triage label Feb 16, 2022
@shimingsg
Copy link
Collaborator

Verified Repro with windows and the above project.

@hartez
Copy link
Contributor

hartez commented Feb 23, 2022

Note hartez comment from 2018 that the minimum size is arbitrarily set to 40, 40, meaning that the item can never be smaller.

That's the OnMeasure for ItemsView, not for individual items - the entire CollectionView can't be less than 40x40. It doesn't have anything to do with the height of individual rows.

Also, it's there to support legacy renderer shims; I don't believe it ever gets called if you're using a vanilla CollectionView with Maui.Controls.

Since you're only seeing this behavior on Windows, it's unlikely that the culprit is any of the cross-platform code. I don't have time to dig into it during this iteration, but my best guess is that you're seeing an issue with the underlying WinUI ListView's individual row height. Or that the ItemContentControl class which acts as a container for CollectionView items in Windows is measuring something incorrectly; you might look at the MeasureOverride in that class.

@Redth Redth added this to the 6.0.300-servicing milestone Mar 22, 2022
@VSadov VSadov assigned VSadov and unassigned VSadov May 6, 2022
@boarder2
Copy link

boarder2 commented Jul 4, 2022

By no means am I an expert in MAUI but it looks like this may be due to inferring styles from their default styles.

var style = new WStyle(typeof(ListViewItem));

IIRC, the default UWP ListViewItem style sets a MinHeight of 40. This would also explain the platform specific behavior.

Since there doesn't seem to be a way to set the ItemContainerStyle via MAUI, we're kind of stuck here. This is negatively impacting my project as well.

This behavior doesn't occur if you use a ListView control instead of a CollectionView and I didn't dig into why, but since CollectionView seems to be the preferred control going forward, it seems like something that should be addressed.

@hbraasch
Copy link

Can confirm it is working correctly under iOS.

image

I am also interested in getting this fixed for Windows. Thanks

@IndianaGary
Copy link
Author

IndianaGary commented Aug 30, 2022 via email

@Redth Redth modified the milestones: 6.0-servicing, Backlog Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView fixed-in-7.0.96 Look for this fix in 7.0.96! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! platform/windows 🪟 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

9 participants