Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] CollectionView items are not being displayed with a corresponding error messsage in the output (XF 5.0)

Open themronion opened this issue 4 years ago • 19 comments

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

  1. Launch the reproduction project
  2. Click the button
  3. 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 2021-01-22_02-28-40- 2021-01-22_02-28-47-

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

themronion avatar Jan 07 '21 14:01 themronion

@hartez Do you have any workarounds? Maybe like setting height request somewhere or i dont know. Or should i stay on the prerelease version?

themronion avatar Jan 12 '21 11:01 themronion

@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

themronion avatar Jan 22 '21 13:01 themronion

I have the same problem that happened after the same update.

ZacharyInDallas avatar Jan 28 '21 19:01 ZacharyInDallas

@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

themronion avatar Jan 28 '21 19:01 themronion

@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.

hartez avatar Feb 08 '21 21:02 hartez

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!

themronion avatar Feb 08 '21 22:02 themronion

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.

ZacharyInDallas avatar Feb 09 '21 22:02 ZacharyInDallas

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 avatar Feb 10 '21 08:02 themronion

@themronion No, we'll definitely keep this open so we can fix it.

hartez avatar Feb 11 '21 19:02 hartez

Ok! Thanks!

themronion avatar Feb 11 '21 21:02 themronion

@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

Where it is placed to solved the problem in some event?

ricardoromaobr avatar Oct 06 '21 14:10 ricardoromaobr

Has there been any update on this bug? It's still showing in the latest release version for the CarouselView

nodoid avatar Dec 01 '21 12:12 nodoid

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)

mcblacksea avatar Jan 29 '22 01:01 mcblacksea

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)

slprog1 avatar Feb 01 '22 23:02 slprog1

@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.

vhugogarcia avatar Apr 05 '22 01:04 vhugogarcia

Setting ItemSizingStrategy to MeasureFirstItem and adding delay before setting item source resolved issue, many thanks to the community for these workaround 👍 👍 👍 👍 👍

Waaheeda avatar Dec 01 '22 10:12 Waaheeda

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.

MitchBomcanhao avatar Jan 25 '23 12:01 MitchBomcanhao

This issue still occurs with CarouselView in 5.0.0.2545. The workaround for delay is effective.

muak avatar Feb 01 '23 06:02 muak

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?

UnreachableCode avatar Nov 08 '23 13:11 UnreachableCode