Bug 52700 - Can't disable cell SelectionStyle using ViewCellRenderer for cells when using recycling
Summary: Can't disable cell SelectionStyle using ViewCellRenderer for cells when using...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.4
Hardware: PC Windows
: High normal
Target Milestone: ---
Assignee: David Ortinau [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-02-23 09:48 UTC by Johan
Modified: 2017-06-20 18:15 UTC (History)
8 users (show)

Tags: bug, ios, listview, cell, ac, pending_pr
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (144.04 KB, application/x-zip-compressed)
2017-02-28 23:05 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Johan 2017-02-23 09:48:37 UTC
When using a ListView with CachingStrategy "RecycleElement" I can't set the native cells selectionstyle to none using a ViewCellRenderer.

So for example I do this:

[assembly: ExportRenderer(typeof(ViewCell), typeof(ExtViewCellRenderer))]
namespace ABetterListView.iOS.Renderers
{
    public class ExtViewCellRenderer : ViewCellRenderer
    {
        public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
        {
            var cell = base.GetCell(item, reusableCell, tv);

            cell.SelectionStyle = UITableViewCellSelectionStyle.None;

            return cell;
        }

    }
}

Now it will still display the gray selection box when selecting it.

After looking through the Xamarin.Forms source code I found the following code in file:
Xamarin.Forms/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs


internal static UITableViewCell GetNativeCell(UITableView tableView, Cell cell, bool recycleCells = false, string templateId = "")
		{
			var id = cell.GetType().FullName;

			var renderer = (CellRenderer)Registrar.Registered.GetHandler(cell.GetType());

			ContextActionsCell contextCell = null;
			UITableViewCell reusableCell = null;
			if (cell.HasContextActions || recycleCells)
			{
// Code...

In this method a new cell, a "context action cell" is created if recycle cells is enabled. This will basically create a new native cell which will use the default cell selection value, this makes my change in the ViewCellRenderer have no effect since that is not the actual cell used. Instead my original cell is used inside this context cell which probably causes this bug. So we need a way of the context cell to copy properties form it's containing native cell.
Comment 1 Jimmy [MSFT] 2017-02-23 17:53:59 UTC
Let me run the code in comment 0 to try confirming this issue. In the meantime, can you let me know what version of Forms this previously worked on? Thanks!
Comment 2 Johan 2017-02-23 21:08:35 UTC
Hi Jimmy!

Hmm I wish I knew, I think it might have been like this for a long time... probably since context cells was introduced?

Thanks!
/Johan
Comment 3 Jimmy [MSFT] 2017-02-28 23:05:39 UTC
Created attachment 20047 [details]
repro project

I was able to reproduce the issue with the attached repro project. I tested with the following versions:

Forms 2.3.4-pre2 - BAD
Forms 2.3.3.180 - BAD
Forms 2.3.2.127 - BAD

As mentioned in the description, the issue does seem to be that the SelectionStyle set in the custom ViewCell renderer is overridden later inside CellTableViewCell.GetNativeCell: https://github.com/xamarin/Xamarin.Forms/blob/2.3.3/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs#L89 


### Steps to Reproduce
1. Run the attached project
2. Select a cell


#### Expected Results
The cell will _not_ be highlighted


### Actual Results
The cell is highlighted with a grey color
Comment 4 David Ortinau [MSFT] 2017-06-17 22:53:47 UTC
Confirmed this is still the case on 2.3.6.111-nightly. Also confirmed Xamarin.iOS behaves correctly.

Seems to work with RetainElement only.

Elevating the priority.
Comment 5 David Ortinau [MSFT] 2017-06-20 00:59:54 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1002
Comment 6 Rui Marinho 2017-06-20 18:15:36 UTC
Should be fixed on 2.3.6.-pre1