Xamarin.Forms
Xamarin.Forms copied to clipboard
[Bug] CollectionView items are not being displayed with a corresponding error messsage in the output (XF 5.0)
Description
This happens only on xf 5.0 - the latest stable release (ios platform). Downgrading to prerelease 6 fixes the issue, so my guess something happened in between there. Attaching a reproduction link. Just press the button and observe a message in the output window stating something like this:
2021-01-07 15:52:36.499741+0200 App1.iOS[5590:50622] The behavior of the UICollectionViewFlowLayout is not defined because:
2021-01-07 15:52:36.499960+0200 App1.iOS[5590:50622] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2021-01-07 15:52:36.500151+0200 App1.iOS[5590:50622] Please check the values returned by the delegate.
2021-01-07 15:52:36.500914+0200 App1.iOS[5590:50622] The relevant UICollectionViewFlowLayout instance is <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7fe2fb5698e0>, and it is attached to <UICollectionView: 0x7fe2fbdbc200; frame = (0 0; 375 200); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000144ed0>; layer = <CALayer: 0x6000008ff380>; contentOffset: {0, 0}; contentSize: {195.5, 201}; adjustedContentInset: {0, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7fe2fb5698e0>; dataSource: <Xamarin_Forms_Platform_iOS_GroupableItemsViewController_1: 0x7fe2fb440670>>.
2021-01-07 15:52:36.501196+0200 App1.iOS[5590:50622] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
Note that hiding and clicking the button again will show my items - in the reproduction case. In my real world project the items are still not being drawn no matter how many times i click the button to show the sheet and hide it again.
Steps to Reproduce
- Launch the reproduction project
- Click the button
- Observe the message
Expected Behavior
Collectionview items are being shown
Actual Behavior
Collectionview items aren't being shown on first click, on second - are being shown
Basic Information
- Version with issue: 5.0
- Last known good version: 5.0 pre6
- Platform Target Frameworks:
- iOS: latest
Environment
Visual Studio latest
Reproduction Link
Adding as a zip file App1.zip
Workaround
Downgrade to prerelease, or set ItemSizingStrategy to MeasureFirstItem
@hartez Do you have any workarounds? Maybe like setting height request somewhere or i dont know. Or should i stay on the prerelease version?
@hartez i have an update for you, maybe it will help. When setting the ItemSizingStrategy to MeasureFirstItem the problem dissapears. But unfortunately in most work cases the cells must be different sizes, so it is not a workaround
I have the same problem that happened after the same update.
@ZacharyInDallas as a workaround for now you can try changing the ItemSizingStrategy
or if u need different cell size then try adding an
await Task.Delay(50)
before showing ur items. It solved the issue in my situation
@hartez i have an update for you, maybe it will help. When setting the ItemSizingStrategy to MeasureFirstItem the problem dissapears. But unfortunately in most work cases the cells must be different sizes, so it is not a workaround
That makes sense - the errors you're seeing are coming from AutoLayout, and MeasureFirstItem disables AutoLayout.
Another workaround that's not great but will prevent the errors is to populate the data after the animation has completed.
The reason this worked before the last version of 5.0 was that the actual item animations and layout used to happen in a PerformBatchUpdates call which we removed because it was causing all kinds of other problems. (That's also why the Task.Delay workaround is helping - this is partly a timing bug.)
All of the autolayout errors seem to point to the height of the content being 1 greater than the UICollectionView's frame, which is making me wonder if this is some sort of measurement or rounding issue between CollectionView and ContentView.
Well, i am comfortable with Task.Delay) so, if this is not an issue, it may be closed, i guess. Thank u for ur time and explanation!
MeasureFirstItem may work for me, but CarouselView was also broken in this release so I have addition problems. Some of my CollectionViews are in CarouselViews.
MeasureFirstItem may work for me, but CarouselView was also broken in this release so I have addition problems. Some of my CollectionViews are in CarouselViews.
Try the Task.Delay workaround
@themronion No, we'll definitely keep this open so we can fix it.
Ok! Thanks!
@ZacharyInDallas as a workaround for now you can try changing the
ItemSizingStrategy
or if u need different cell size then try adding anawait Task.Delay(50)
before showing ur items. It solved the issue in my situation
Where it is placed to solved the problem in some event?
Has there been any update on this bug? It's still showing in the latest release version for the CarouselView
Issue is still here. I can see URI images in collection view on Android, but I can't see the same images in collection view on iOS. (For instance, I've used images from Xanimals MS example app)
Same thing with my iOS part of the project. I an reproduce it with the latest version installed on my laptop
Visual Studio Enterprise 2019 for Mac Version 8.10.17 (build 2)
Xamarin.iOS Version: 15.4.0.0 (Visual Studio Enterprise)
@hartez i have an update for you, maybe it will help. When setting the ItemSizingStrategy to MeasureFirstItem the problem dissapears. But unfortunately in most work cases the cells must be different sizes, so it is not a workaround
That makes sense - the errors you're seeing are coming from AutoLayout, and MeasureFirstItem disables AutoLayout.
Another workaround that's not great but will prevent the errors is to populate the data after the animation has completed.
The reason this worked before the last version of 5.0 was that the actual item animations and layout used to happen in a PerformBatchUpdates call which we removed because it was causing all kinds of other problems. (That's also why the Task.Delay workaround is helping - this is partly a timing bug.)
All of the autolayout errors seem to point to the height of the content being 1 greater than the UICollectionView's frame, which is making me wonder if this is some sort of measurement or rounding issue between CollectionView and ContentView.
you are totally 1000% correct. The issue is due to a timing issue. Y fixed this by adding a quick activity indicator to display a loading event animation, which shows and hide while returning the data, so that fixed the issue.
thanks for sharing this information. It was very helpful.
Setting ItemSizingStrategy to MeasureFirstItem and adding delay before setting item source resolved issue, many thanks to the community for these workaround 👍 👍 👍 👍 👍
Still running into this issue with xamarin forms 5.0 sr13 (latest). using MeasureFirstItem isn't an option for us, so we will try the task delay, but it'd be nice to have a proper fix.
This issue still occurs with CarouselView in 5.0.0.2545. The workaround for delay is effective.
I take it that has been fixed in MAUI? What about in Xamarin Forms? MeasureFirstItem did not work for me, but Task.Delay has. Is there a better workaround to this? How would one go about populating the data after the animation - a custom renderer event maybe?