xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

ListView loops calling DataTemplateSelector.OnSelectTemplate indefinitely on Android, iOS if RecycleElement #14069

Open chrisgull opened 3 years ago

chrisgull commented 3 years ago

When using a DataTemplateSelector for ListView ItemTemplate on Android or iOS, Forms repeatedly calls the selector indefinitely. On UWP it works as expected, with only one or a few calls per item.

This occurs if CachingStrategy="RecycleElement", otherwise not.

Environment Visual Studio 16.9.2 on Windows 10 Pro 20H2 19042.868 64-bit. Xamarin Forms 5.0.2012 Android Emulator for Android Pie 9.0 iOS Simulator for iPhone 12, iOS 14.4

Steps to reproduce See attached simple example. Observe debug output.

Expected A few printfs from calls to the DataTemplateSelector.

Actual (Android and iOS) Calls to the DataTemplateSelector are repeated infinitely. CPU load for the Android emulator is pegged.

XF 4.8.0.1821 works as expected. XF 5.0.0.1874 works as expected. XF 5.0.0.1905 works as expected. XF 5.0.0.2012 introduces the problem.

Workaround Roll back XF to 5.0.0.1905 or earlier.

DataTemplateSelectorIssue.zip

TechGuyGeek commented 3 years ago

Thankyou for your hard work a temp solution i have been working on this issue for a month now on and off and was not able to find where the issue was so many thanks

sk1llsh0t commented 3 years ago

I believe I'm having the same problem.

I'm running XF 5.0.0.2012. When a page loads with a listview, the app freezes and is unresponsive. I actually only see this freezing behavior when debugging.

Running the app outside of VS, it is fine.

If i wind back XF to 5.0.0.1931, everything works fine w/ debugger and without.

It looks like XF 5.0.0.2012 has some issues with the ListView

chrisgull commented 3 years ago

I believe I'm having the same problem.

I'm running XF 5.0.0.2012. When a page loads with a listview, the app freezes and is unresponsive. I actually only see this freezing behavior when debugging.

Running the app outside of VS, it is fine.

If i wind back XF to 5.0.0.1931, everything works fine w/ debugger and without.

It looks like XF 5.0.0.2012 has some issues with the ListView

I'm staying on 1931, works fine for me for now.

rachelkang commented 3 years ago

Related to https://github.com/xamarin/Xamarin.Forms/issues/14218, https://github.com/xamarin/Xamarin.Forms/issues/14190, https://github.com/xamarin/Xamarin.Forms/issues/11344

I recommend checking out CollectionView if you haven't already!

chrisgull commented 3 years ago

Related to #14218, #14190, #11344

I recommend checking out CollectionView if you haven't already!

Not implemented enough on UWP, and there are performance issues on Android. As it is now, CollectionView is a no-go for portable code.

Sebastian1989101 commented 3 years ago

@jfversluis @davidortinau any chance this will get fixed? This is a major issue because many apps uses lists. There are even PR's that focus on this problem. The quality of Xamarin is utterly bad lately... I would even say it's unuseable at this point with all this bugs open and even critical ones like this one keept open for months...