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

Items inside CollectionView initialized again with every new item (On IOS) [Bug] #13087

Open Jearom opened 3 years ago

Jearom commented 3 years ago

Description

Hi All, I am creating a page like chat application except i need to wait Media Element has to finished before I insert another message to list. When new item added to collectionview with datatemplateselector all visible items initialized again. So another media element started on background. Just put a debug on datatemplateselector , you will see. Ofc this is not releated with media element but it is easy to discover with it.

Steps to Reproduce

  1. Create Xamarin Forms project
  2. Create a page with CollectionView
  3. Create mutliple item template and bind it to Collectionview with datatemplateselector
  4. Insert multiple items to collectionview and one media element inside one of them
  5. Insert new item after video finished.

Expected Behavior

Visible item has to be initialized one time.

Actual Behavior

Initialized multiple times.

Basic Information

Environment

Microsoft Visual Studio Enterprise 2019
Version 16.8.2
VisualStudio.16.Release/16.8.2+30717.126
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Enterprise

Android Logcat Output   1.6.3
Android Logcat Output  -- Visual Studio Extension 

ASP.NET and Web Tools 2019   16.8.553.28003
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.553.28003
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.8.553.28003
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.8.553.28003
Azure Functions and Web Jobs Tools

C# Tools   3.8.0-5.20567.16+53c5d7d3cf13d88978744a32a27c5f8350a8400a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

GitHub.VisualStudio   2.11.106.19330
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

GorillaPlayerPackage Extension   1.0
GorillaPlayerPackage Visual Studio Extension Detailed Info

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.113+g422d40002e.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio   16.8.43 (00471f8)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Progress Telerik UI for Xamarin Extension   2020.3.1117.1
Progress® Telerik® UI for Xamarin Extension

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.62010.06180
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.21016.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.8.0-5.20567.16+53c5d7d3cf13d88978744a32a27c5f8350a8400a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.8.000.255 (d16-8@d002176)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.8.0.507 (remotes/origin/d16-8@e87b24884)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.8.112 (86385a3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.1.0.17 (d16-8/c0e2b8e)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: be2226b
    Java.Interop: xamarin/java.interop/d16-8@79d9533
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

Xamarin.iOS and Xamarin.Mac SDK   14.4.1.3 (e30c41de3)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Reproduction Link

Sample Project mediainsidecollection.zip

Workaround

I will swithch collectionview to Listview

PureWeen commented 3 years ago

@hartez I tested this on pre5 and the attached repro is now throwing an exception

Jearom commented 3 years ago

@hartez Probably, cause of the media element removed from XF on 5.0.0 . You can switch to CommunityToolkit version. It is also exists in test project. But the main problem is not the media element ofc.

Thanks.

Tommigun1980 commented 3 years ago

Doesn't this effectively break virtualisation, making it impossible to make an efficient chat app with the CollectionView? I was planning on adding proper virtualisation next (as I'm currently just loading and adding all messages at once), but should I wait until this is fixed? Ie was this bug ever confirmed, and if so, is there an ETA on a fix? Virtualisation is kinda the main reason to use a CollectionView so if it doesn't work it is imho a very high priority fix.

Thanks.

Edit: Found issue https://github.com/xamarin/Xamarin.Forms/issues/13045 which seems to be this exact same issue, but reported for Android and with a repro project that doesn't require modifications?