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

[Bug] CollectionView iOS draws both EmptyView and Items/ItemTemplate #13794

Closed
RemcoDEV opened this issue Feb 18, 2021 · 16 comments · Fixed by #15122
Closed

[Bug] CollectionView iOS draws both EmptyView and Items/ItemTemplate #13794

RemcoDEV opened this issue Feb 18, 2021 · 16 comments · Fixed by #15122

Comments

@RemcoDEV
Copy link

RemcoDEV commented Feb 18, 2021

Description

CollectionView iOS draws both EmptyView and Items/ItemTemplate. The itemtemplate UI becomes unresponsive, because the emptyview is drawn over it.

Steps to Reproduce

  1. Create a collectionview with an itemtemplate and an emptyview.
  2. Fill the collectionview in the viewmodel and call onpropertychanged on the itemssource binding.
  3. Sometimes (~3 out of 5 times) the collectionview displays both the emptyview and the itemtemplates.

Expected Behavior

Only draw the emptyview when the itemssource is empty.

Actual Behavior

Both the emptyview and the items/itemtemplates are drawn.

Basic Information

  • Version with issue: release-5.0.0-sr3.1
  • Last known good version: release-5.0.0-sr2
  • Platform Target Frameworks:
    • iOS: 14.3
    • Android: Works fine on android
    • UWP: --
  • Android Support Library / AndroidX Version: --
  • NuGet Packages:
  • Affected Devices: tablets, phones

Environment

Visual Studio 2019 / Windows 10

Build Logs

--

Screenshots

'Nothing to display' is the emptyview.
This example is a grouped collectionview, but it also happens to non-grouped collectionviews.
IMG_0060

Reproduction Link

--

Workaround

Reconstructing the page sometimes works.
Refreshing does not work. Something definitely goes wrong when constructing the page.

@RemcoDEV RemcoDEV added s/unverified New report that has yet to be verified t/bug 🐛 labels Feb 18, 2021
@samhouts samhouts added this to New in Triage Feb 18, 2021
@hartez
Copy link
Contributor

hartez commented Feb 18, 2021

@RemcoDEV Can you post a small reproduction project? Or at least paste in an example of your ItemTemplate, EmptyView, and the code you're using to set up your ItemsSource?

@hartez hartez added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Feb 18, 2021
@hartez hartez moved this from New to Needs Info in Triage Feb 18, 2021
@lewinzki
Copy link

@RemcoDEV I encounter the same bug. A possible workaround is to add IsVisible to the content of your EmptyView. E.g. <StackLayout IsVisible="{Binding DocumentGroups, Converter={StaticResource ListIsNullOrEmptyConverter}}">. Here I have used the converter ListIsNullOrEmptyConverter from the XamarinCommunityToolkit. The converter is also easy to implement yourself if you don't want the dependency.

@hartez If it is any help I can report that this bug only occurs when the CollectionView is a child of a TabbedPage.

@decv86
Copy link

decv86 commented Feb 20, 2021

@RemcoDEV I encounter the same bug. A possible workaround is to add IsVisible to the content of your EmptyView. E.g. <StackLayout IsVisible="{Binding DocumentGroups, Converter={StaticResource ListIsNullOrEmptyConverter}}">. Here I have used the converter ListIsNullOrEmptyConverter from the XamarinCommunityToolkit. The converter is also easy to implement yourself if you don't want the dependency.

@hartez If it is any help I can report that this bug only occurs when the CollectionView is a child of a TabbedPage.

Tnx man!

@Deepfreezed
Copy link

Deepfreezed commented Feb 23, 2021

Same issue for me. Draws both Empty and Item View. Not using Tabbed Page. Xamarin test team should really use rest service to test with some async calls. I am sure all this works when you have data hardcoded into the view model.

Just updated to 5.0.0.2012 from 5.0.0.1931. There are other issue in 5.0.0.1931 that breaks CollectionView binding when visibility state is initially false. At least that seems to be fixed in 5.0.0.2012.

@Redth Redth removed the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Mar 4, 2021
@PureWeen PureWeen moved this from Needs Info to New in Triage Mar 5, 2021
@rmarinho
Copy link
Member

rmarinho commented Mar 8, 2021

Hello all, can someone please upload a small reproduction of this issue so we can investigate it further?!

thanks.

@rmarinho rmarinho moved this from New to Needs Info in Triage Mar 8, 2021
@rmarinho rmarinho added the s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. label Mar 8, 2021
@marcojak
Copy link

marcojak commented Apr 4, 2021

Same problem here.

@Redth
Copy link
Member

Redth commented Apr 5, 2021

@marcojak can you please upload a small reproduction of the issue?

@beeradmoore
Copy link
Contributor

@hartez @rmarinho @Redth , I have added a small repro project. There is some gross code incoming so brace yourselves.

Simulator Screen Shot - iPhone 12 mini - 2021-05-07 at 11 30 52

In this particular case I was able to replicate it by doing what I do in my prod app, which took me down a rabbit hold where I found some jank code. Fixing my jank fixes the issue, however I think the underlying issue may still happen in other circumstances.

Problem is only present when for me CollectionView is inside a CarouselView. If I replace the CarouselView with a CollectionView the problem goes away. The other bit of jank in the code is I am creating an ObservableCollection on my MainPage which is populated by loading a local file/web request/etc, and a reference of this is passed to MyCollectionView class.

Within MyCollectionView I keep a reference of the ObservableCollection (Data = data;) AFTER I set the BindingContext.

My workaround is to fix the jank and move this line to before I set the BindingContext and then the problem goes away. Another possible solution I havn't tried would be setting ItemsSource of MyCollectionView from the MainPage.

EmptyCollectionViewBug.zip

So yeah, there is some things here that I shouldn't be doing, but its still putting CollectionView in an odd state where it both has and does not have data.

@Redth Redth removed the s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. label May 11, 2021
@Redth Redth moved this from Needs Info to New in Triage May 11, 2021
@jsuarezruiz jsuarezruiz added this to Review Backlog in CollectionView via automation Jun 14, 2021
@jsuarezruiz jsuarezruiz removed the s/unverified New report that has yet to be verified label Jun 14, 2021
@jsuarezruiz jsuarezruiz moved this from New to Needs Estimate in Triage Jun 14, 2021
@jfversluis
Copy link
Member

@RemcoDEV @beeradmore, a PR for this is open now (#14603), would you be able to grab the NuGet as described here and let us know if this fixes this issue? That will greatly speed up the review process.

Besides verifying if this particular issue is fixed also be sure to check other scenarios in the same area to make sure that this fix doesn't accidentally has side-effects 🙂

Thanks!

@RemcoDEV
Copy link
Author

Hi @jfversluis ,

Just tested. It still does not work on the latest XF 5.0.0.2125 (pull request of Javier is from before that release date). The pull request of Javier does not change any logic, it are just tests. It can be approved without causing any side effects :).

image

Regards,
Remco

@jfversluis
Copy link
Member

Sorry about that Remco! Just noticed a PR and added that message in the hope you could test it :D

Seems we have some work to do here still, thanks!

@jfversluis
Copy link
Member

I suspect something in here has to do with it: #13678

@jfversluis
Copy link
Member

Hey @beeradmoore @RemcoDEV, a PR (#15122) for this is open now, would you be able to grab the NuGet as described here and let us know if this fixes this issue? That will greatly speed up the review process. Make sure to take the exact version as attached to this PR.

Besides verifying if this particular issue is fixed also be sure to check other scenarios in the same area to make sure that this fix doesn't accidentally has side-effects 🙂

Thanks!

@RemcoDEV
Copy link
Author

RemcoDEV commented Feb 4, 2022

Hi @jfversluis . It seems to work as intended. No side effects found. Thank you!

@jfversluis jfversluis moved this from To Fix to PR Needs Review in 5.0.0 SR10 (Planning) - Target Date Feb. 16th Feb 4, 2022
@beeradmoore
Copy link
Contributor

@jfversluis , my above repro is in a weird state where trying to use it (either with the XF it has, updated, or updated to the PR version) where attempting to scroll it crashes it. That repro also has some weird things happening in it so it may be because of that.

I tried it in our production app and I didn't notice any new problems. However in its pre-PR-nuget state we also no longer were experiencing this issue.

I however do still have header/footer showing when CollectionView is empty and displaying the correct EmptyView. I have a feeling that this isn't a bug and instead a design choice. Changing that behaviour will impact anyone using header/footer + EmptyView so its probably best left untouched (unless we want to add some new HideHeaderOnEmpty HideFooterOnEmpty properties to CollectionView in MAUI).

@jfversluis
Copy link
Member

Perfect, thanks so much for taking the time to verify and provide me with this input! Looks like I'll be merging this for now and look at the other mentioned things separately.

Triage automation moved this from Needs Estimate to Closed Feb 9, 2022
CollectionView automation moved this from Review Backlog to Done Feb 9, 2022
5.0.0 SR10 (Planning) - Target Date Feb. 16th automation moved this from PR Needs Review to Done Feb 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.