[iOS/Android] Handle item selection highlight when ListView cell is tapped erratically (#520)

* Fix multi tap selection highlight

* added sample code

* add ios fix
This commit is contained in:
adrianknight89 2017-02-06 05:59:11 -06:00 коммит произвёл Rui Marinho
Родитель c29403ac31
Коммит 28237b7b27
4 изменённых файлов: 53 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,48 @@
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Threading.Tasks;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 32956, "Setting ListView.SelectedItem to null does not remove list item highlight when list item is tapped multiple times quickly", PlatformAffected.Android | PlatformAffected.iOS)]
public class Bugzilla32956 : TestNavigationPage
{
protected override void Init()
{
var list = new List<int>();
for(var i=0; i<10; i++)
list.Add(i);
var listView = new ListView
{
ItemsSource = list
};
listView.ItemSelected += async (sender, args) =>
{
if (args.SelectedItem == null)
return;
await Task.Delay(1000);
await Navigation.PushAsync(new ContentPage());
};
var contentPage = new ContentPage
{
Content = listView
};
contentPage.Appearing += (sender, args) =>
{
listView.SelectedItem = null;
};
PushAsync(contentPage);
}
}
}

Просмотреть файл

@ -58,6 +58,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla32847.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla32956.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla33248.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla33268.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla33612.cs" />

Просмотреть файл

@ -371,8 +371,9 @@ namespace Xamarin.Forms.Platform.Android
if (position < 0 || position >= Count)
return;
if(_lastSelected != view)
_fromNative = true;
Select(position, view);
_fromNative = true;
Controller.NotifyRowTapped(position, cell);
}

Просмотреть файл

@ -914,7 +914,8 @@ namespace Xamarin.Forms.Platform.iOS
SetCellBackgroundColor(cell, UIColor.Clear);
_selectionFromNative = true;
if (!cell.Selected)
_selectionFromNative = true;
tableView.EndEditing(true);
Controller.NotifyRowTapped(indexPath.Section, indexPath.Row, formsCell);