Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

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

Open
themronion opened this issue Jan 7, 2021 · 19 comments
Labels
e/5 🕔 5 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 t/bug 🐛

Comments

@themronion
Copy link

themronion commented Jan 7, 2021

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 themronion added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 7, 2021
@samhouts samhouts added this to New in Triage Jan 7, 2021
@hartez hartez added a/collectionview p/iOS 🍎 and removed s/unverified New report that has yet to be verified labels Jan 7, 2021
@hartez hartez self-assigned this Jan 7, 2021
@hartez hartez added this to Backlog in CollectionView via automation Jan 7, 2021
@hartez hartez removed this from New in Triage Jan 7, 2021
@hartez hartez added i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often e/5 🕔 5 and removed a/collectionview labels Jan 7, 2021
@themronion
Copy link
Author

@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
Copy link
Author

themronion commented Jan 22, 2021

@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

@ZacharyInDallas
Copy link

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

@themronion
Copy link
Author

@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
Copy link
Contributor

hartez commented Feb 8, 2021

@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 hartez moved this from Review Backlog to Backlog in CollectionView Feb 8, 2021
@themronion
Copy link
Author

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!

@ZacharyInDallas
Copy link

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.

@themronion
Copy link
Author

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

@hartez
Copy link
Contributor

hartez commented Feb 11, 2021

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

@themronion
Copy link
Author

Ok! Thanks!

@ricardoromaobr
Copy link

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

@nodoid
Copy link

nodoid commented Dec 1, 2021

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

@mcblacksea
Copy link

mcblacksea commented Jan 29, 2022

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)

@slprog1
Copy link

slprog1 commented Feb 1, 2022

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)

@vhugogarcia
Copy link

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

@Waaheeda
Copy link

Waaheeda commented Dec 1, 2022

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

@MitchBomcanhao
Copy link

MitchBomcanhao commented Jan 25, 2023

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.

@muak
Copy link

muak commented Feb 1, 2023

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

@UnreachableCode
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
e/5 🕔 5 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 t/bug 🐛
Development

No branches or pull requests