Xamarin.forms: [Bug] First item in the CollectionView is bound twice on iOS

Created on 29 Dec 2019  路  6Comments  路  Source: xamarin/Xamarin.Forms

Description

The first item in a CollectionView is bound twice on iOS.
This causes unexpected behaviour if you rely on knowing when the view is bound to it's binding context.

Note: Normal behaviour occurs at all other parts of the lifecycle, including recycling.
This issue does not affect Android or UWP.

Steps to Reproduce

  1. Run the attached sample app.
  2. View the log output in the Output window.
  3. Notice the first item is bound twice:

Screenshot

_First bind on item 1:_
Screenshot 2019-12-30 at 9 06 02 am

_Second bind on item 1:_
Screenshot 2019-12-30 at 9 06 15 am

  • Bind originates from view bound to view model.
  • GetCell --> UpdateTemplatedCell.
  • Correct - No change is required to this behavior.

Expected Behavior

The first item should only be bound once during initial load and later when the view is recycled.

Actual Behavior

The first item is bound _twice_ during initial load.
Note: All other items in the list are bound _once_ during initial load.

Recommended Changes

Prevent bind from occurring during initial cell size determination.

Basic Information

  • Version with issue: 4.4.0 (vLatest)
  • Last known good version: N/A
  • IDE: Microsoft Visual Studio 2019 Enterprise
  • Platform Target Frameworks:

    • iOS: Xamarin.iOS 13.6.0.12

Reproduction Link

Created a sample based on the CollectionView code samples found here.
DuplicateItemBindingSample.zip

collectionview 6 high impact iOS 馃崕 bug

Most helpful comment

@bmacombe @hartez @jfversluis @samhouts Hi XF Team, This is on our critical list. It was reported in Dec. 2019. We have multiple workarounds in place because we cannot rely on binding events to give us the right number of messages. It also causes issues with view recycling, especially when we have many items in the list.

All 6 comments

Thanks for reporting! I noticed this little note

As a side note, view recycling is not working on UWP.

Please check if there is already an issue for this and if not open a separate one. That makes it easier to track the individual progress. Thanks!

Thanks @jfversluis. I have reported the issue with UWP view recycling here.

The iOS renderer is using the first cell as a prototype to estimate the sizes for the remaining cells. So the item is bound once for the prototype cell, then again when the "real" cell is created. We can probably add some logic to retain and use the prototype cell rather than throwing it away (which would remove the unexpected second binding, and saves us a few cycles and allocations).

@hartez Just wondering if you possibly have any update on this issue? Unfortunately, this is a bit of a pain point for us right now when integrating with ReactiveUI.

@hartez , This is important. I came upon this when debuging an issue where I use a CollectionView that contains 2 RadioButton controls that belong to the same radio group. Because of this bug, on iOS the radio group check logic is completely broken.

@bmacombe @hartez @jfversluis @samhouts Hi XF Team, This is on our critical list. It was reported in Dec. 2019. We have multiple workarounds in place because we cannot rely on binding events to give us the right number of messages. It also causes issues with view recycling, especially when we have many items in the list.

Was this page helpful?
0 / 5 - 0 ratings