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

[Bug] Regression: 5.0.0-pre5 often fails to draw dynamically loaded collection view content #13126

Closed
Tommigun1980 opened this issue Dec 12, 2020 · 15 comments · Fixed by #13640 or #13678 · May be fixed by aleks-ivanov/maui#9
Closed

[Bug] Regression: 5.0.0-pre5 often fails to draw dynamically loaded collection view content #13126

Tommigun1980 opened this issue Dec 12, 2020 · 15 comments · Fixed by #13640 or #13678 · May be fixed by aleks-ivanov/maui#9
Assignees
Labels
a/collectionview i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often i/regression t/bug 🐛

Comments

@Tommigun1980
Copy link

Tommigun1980 commented Dec 12, 2020

Description

After updating to 5.0.0-pre5 some of my collection views don't show up the first time they are loaded.

I often employ the following pattern:

  1. Have content (collection view in this case) where its IsVisible property is set to something like IsVisible="{Binding ChatRooms.Count, Converter={StaticResource IsNotZeroConverter}}", where the same ObservableCollection is used as its content.
  2. Have some text saying "You don't have any xxx yet, please do yyy" where its IsVisible property is true when the collection view's content count is zero.

The intent is to show an informational message if there's no content in the collection view, or else show the collection view's contents.

This has worked flawlessly until updating to pre5. What happens now is that collection views content is never made visible when the content has finished loading (IsVisible goes to true by the ChatRooms collection filling up after loading). The collection view's headers are shown so the view itself does get drawn, but the content inside it does not, it is drawn as if it had zero items.

If I load the page again then it displays fine, but safe to say I can't have an app where the default is to show blank content. On consecutive loads the data is cached on the client so it's instantly available to the content view.

I suspect this is caused #12017, which definitely takes XF to a better direction but I think it has a bug in it.

If I remove the IsVisible=xxx on the collection view it does draw its contents properly, but this I can't do as it breaks the logic of the page. Is this some kind of race condition with drawing the items when IsVisible toggles to true?
Nevertheless this is pretty fatal as most of my pages are now empty.

Thank you.

EDIT: please read my follow up reply

Basic Information

  • Version with issue: XF 5.0.0-pre5
  • Last known good version: XF 5.0.0-pre4
  • Affected Devices: iOS. Didn't test on Android.

Environment

Show/Hide Visual Studio info
=== Visual Studio Community 2019 for Mac (Preview) ===

Version 8.9 Preview (8.9 build 947)
Installation UUID: 2a591afe-0a7f-4f19-8e9f-143b723bd49f
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000107

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.107 (2020-02/a22ed3f094e) (64-bit)
	Package version: 612000107

=== Roslyn (Language Service) ===

3.9.0-2.20573.18+bc20ce579f9b17c9153f3f54a0690d23c482d899

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.100/Sdks
SDK Versions:
	5.0.100
	3.1.404
	3.1.403
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.0
	3.1.10
	3.1.9

=== .NET Core 3.1 SDK ===

SDK: 3.1.404

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 11.1.99.218 (Visual Studio Community)
Commit: xamarin-android/master/9bc0003
Android SDK: /Users/tommikiviniemi/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2

Build Information: 
Mono: ac59637
Java.Interop: xamarin/java.interop/master@99897b2
ProGuard: Guardsquare/proguard/v7.0.0@84e8560
SQLite: xamarin/sqlite/3.32.1@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@ab650f5

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/tommikiviniemi/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.19
Hash: 9771026
Branch: remotes/origin/HEAD
Build date: 2020-11-21 02:03:08 UTC

=== Android Device Manager ===

Version: 16.9.0.13
Hash: bbbb387
Branch: remotes/origin/main
Build date: 2020-11-21 02:03:28 UTC

=== Apple Developer Tools ===

Xcode 12.2 (17535)
Build 12B45b

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 14.9.0.27 (Visual Studio Community)
Hash: f4c9327fa
Branch: main
Build date: 2020-11-19 10:57:31-0500

=== Xamarin Designer ===

Version: 16.9.0.105
Hash: f693266a2
Branch: remotes/origin/main
Build date: 2020-12-02 05:56:40 UTC

=== Build Information ===

Release ID: 809000947
Git revision: 95291d4f910c26f21816bf2bd51937ef46b99c4f
Build date: 2020-12-03 14:19:22-05
Build branch: release-8.9
Xamarin extensions: 95291d4f910c26f21816bf2bd51937ef46b99c4f

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.1.0 Darwin Kernel Version 20.1.0
    Sat Oct 31 00:07:11 PDT 2020
    root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64

Workaround

None. Can't just have it visible at all times as it contains headers and stuff that break the layout.

@Tommigun1980 Tommigun1980 added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 12, 2020
@Tommigun1980
Copy link
Author

Tommigun1980 commented Dec 12, 2020

After running this test tens of more times I unfortunately have to say that just removing the IsVisible property from the collection view does not solve the problem, but merely makes the 'blank content' issue just happen less frequently.

So I suspect there is a race condition in there now, where toggling IsVisible just makes the error happen more often.

I literally just populate the contents of the collection view inside the page's vm like this in an async command:

// load chatRoomsEx list here...

using (this.ChatRooms.BeginMassUpdate())
{
    this.ChatRooms.Clear();
    this.ChatRooms.AddRange(chatRoomsEx);
}

And the collection view displays ChatRooms as such:

<CollectionView
                ItemSizingStrategy="MeasureFirstItem"
                ItemsSource="{Binding ChatRooms}"
                IsVisible="{Binding ChatRooms.Count, Converter={StaticResource IsNotZeroConverter}}">

ChatRooms is an OptimizedObservableCollection, https://github.com/xamarinhq/xamu-infrastructure/wiki/OptimizedObservableCollection.
Sources: https://github.com/xamarinhq/xamu-infrastructure/blob/bb4b000019441384739ff46ca35b145b3cc8fd6d/src/XamU.Core/Collections/OptimizedObservableCollection.cs.

There is no reason why this shouldn't work with pre-5.

This happens in one of the two last collection views I have in the app as unfortunately there's so many problems with them, and I probably have to convert this to a list view now as well :(

@Tommigun1980 Tommigun1980 changed the title [Bug] Regression: 5.0.0-pre5 doesn't draw collection view content when IsVisible toggles to true [Bug] Regression: 5.0.0-pre5 often fails to draw dynamically loaded collection view content Dec 12, 2020
@Tommigun1980
Copy link
Author

I downgraded XF back to 5.0.0-pre4 and now the collection views display their contents again.

@Tommigun1980
Copy link
Author

#11853 seems to share characteristics with this issue (IsVisible toggling affecting result, AddRange manipulation not working etc.), but I failed to see whether any changes were done for 5.0.0 or if those breaking fixes were merely backported to 4.8.0.

@jsuarezruiz @hartez Will this regression get fixed in the next preview release of 5.0.0?

@Tommigun1980
Copy link
Author

Tommigun1980 commented Dec 19, 2020

Here is a video of the issue:
https://drive.google.com/file/d/1ZY2lJ4n7vWh0tTUdxm6on3G7wIdhstcM/view?usp=sharing

The same page with a CollectionView is opened twice:

  1. The data is not cached the first time so it downloads the data, shows a spinner and toggles the CollectionView's IsVisible to true when data has been received.
  2. It is using an OptimizedObservableCollection and AddRange to fill the data.
  3. The contents don't show up in 5.0.0-pre5 but did in 5.0.0-pre4.
  4. The second time the page is loaded it works (the data is cached and readily available).

This worked in 5.0.0-pre4 but not in pre5.

PS. The test users in the test app are random images I found on the net and not real users of any kind.

Thanks.

@hartez
Copy link
Contributor

hartez commented Dec 21, 2020

The intent is to show an informational message if there's no content in the collection view, or else show the collection view's contents.

Have you considered using the EmptyView property for this?

Also, any chance you could provide a small repro project so we can see exactly how your converter and bindings are wired up, and the layout of your page? That would go a long way toward finding out where the bug is.

@rachelkang rachelkang added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Dec 22, 2020
@Tommigun1980
Copy link
Author

Tommigun1980 commented Dec 26, 2020

The intent is to show an informational message if there's no content in the collection view, or else show the collection view's contents.

Have you considered using the EmptyView property for this?

Also, any chance you could provide a small repro project so we can see exactly how your converter and bindings are wired up, and the layout of your page? That would go a long way toward finding out where the bug is.

Thanks for the reply.

Regarding EmptyView - I tried using it but it's a bit too buggy...

  1. When the EmptyView is displayed it also displays the collection view's header ([Bug] CollectionView shows both EmptyView and Footer on iOS #13212).
  2. I still need to make the collection view invisible while it's loading, as I'm displaying a spinner in its place.

Regarding this issue -- it looks to me that pre5 and higher no longer refresh the collection view contents while hidden, and the order in which the refresh and visibility toggling happen seem to be random, exposing this regression.

5.0.0-pre4 was the last version where toggling the IsVisible flag on a collection view worked in conjunction with its data being loaded.

@Tommigun1980
Copy link
Author

Tommigun1980 commented Dec 26, 2020

@hartez Please find enclosed a repro project of the issue: Issue13126.zip

When the repro is first run, the EmptyView will be displayed (which is wrong as the collection view has 20 elements):
Screenshot 2020-12-26 at 4 27 33

Any of these three steps will make the collection view draw its contents and fix the issue:

  1. Downgrade to Xamarin.Forms 5.0.0-pre4 (last working version), or
  2. Press the 'Reload' button in the app, or
  3. Make a trivial change and hot-reload the view.

This is how it should look like:
Screenshot 2020-12-26 at 4 28 04

Do you think this could be fixed quite soon as I can no longer update Xamarin.Forms and I'm stuck with pre-4 until this is fixed? I think this is quite a dangerous bug as it will surely waste many a developer's valuable time, and at least for me makes the CollectionView unfortunately completely unusable.

Thank you.

@Tommigun1980
Copy link
Author

Tommigun1980 commented Dec 26, 2020

@hartez I added a more advanced repro project at #13231 which also reproduces this issue, along with a follow-up NSInternalInconsistencyException error. You might want to use that repro instead of the more limited repro in this bug report.

@Redth Redth removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jan 21, 2021
@Tommigun1980
Copy link
Author

@Redth @hartez I think #13203 is a duplicate of this one. It was closed as fixed, but I have tested with the latest nightly build of Xamarin.Forms (5.0.1.1917-nightly) and this issue still happens.

I have provided a simple repro in this bug report (#13126 (comment)), and also a more involved repro at #13231.

This issue is still keeping me on Xamarin.Forms 5.0.0-pre4 as it's the last working version. I would really need this to be fixed as all my CollectionViews show up as empty atm.

Thank you so much for your help/insights into this!

@Tommigun1980
Copy link
Author

I found a workaround for now that allows me to update to XF5-pre5 and later:

After doing a batch edit/toggling visibility on a CollectionView, force set the ItemsSource to null and back in your code-behind:

var items = this.myCollectionView.ItemsSource;
this.myCollectionView.ItemsSource = null;
this.myCollectionView.ItemsSource = items;

Needless to say this issue that was introduced in 5.0.0-pre5 needs to be fixed, but at least the above should allow your app to function in the interim.

@jsuarezruiz jsuarezruiz added i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often and removed s/unverified New report that has yet to be verified labels Feb 5, 2021
@hartez
Copy link
Contributor

hartez commented Feb 5, 2021

#13640 should address this issue. I built a test package from that branch and applied it to the project from #13231, and the items show up as soon as the loading command finishes.

@hartez hartez reopened this Feb 5, 2021
@hartez
Copy link
Contributor

hartez commented Feb 5, 2021

I spoke too soon - apparently something is different between this case and #13551; with the visibility converter tied to the view model value, the collection is not being displayed. Looking into that now.

hartez added a commit that referenced this issue Feb 5, 2021
CollectionView updates while CollectionView is hidden;
fixes #13126
hartez added a commit that referenced this issue Feb 5, 2021
CollectionView updates while CollectionView is hidden;
fixes #13126
@hartez
Copy link
Contributor

hartez commented Feb 5, 2021

Okay, second time's the charm.

@Tommigun1980
Copy link
Author

Okay, second time's the charm.

Thank you!!!

rmarinho pushed a commit that referenced this issue Feb 9, 2021
…ble (#13678) fixes #13126

* Allow item source updates while CollectionView is hidden; prevent
CollectionView updates while CollectionView is hidden;
fixes #13126

* Fix bug where measurement cell content is applied to the wrong cell
Only force layout on transition from invisible to visible
Move cell size cache to layout and clear cache on size change (e.g., rotation)
Use ItemsView size for constraints when possible;

* Add test for Reset situation; fix bug with Reset before CollectionView is visible;
@mduchev
Copy link

mduchev commented Feb 13, 2021

The fix introduced another regression...
What I have is in the page's ctor I'm loading my data via the NotifyTaskCompletion. As soon as we have data, I'm doing something like this:
Items = new ObservableCollection<T>(listItems)
Pre-5 everything was working fine. After 5 everything was broken and I had to resolve to a workaround (iOS only), which was to wait 500ms (if I wait less than this, the workaround doesn't work) and then to write the same line as the one above. Then I was able to see my items. With the latest service release (incl. this "fix"), I cannot make the items appear at all...
If I have the time, I'll try to create a sample project and create another issue, but it's really annoying to have to create or track new regressions after each "service release".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/collectionview i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often i/regression t/bug 🐛
Projects
None yet
6 participants