[Android] Add null check to prevent crashes when long clicking a text entry in ListVi...
authorPaul DiPietro <pauldipietro@users.noreply.github.com>
Tue, 2 Aug 2016 16:15:35 +0000 (11:15 -0500)
committerSamantha Houts <samantha@teamredwall.com>
Tue, 2 Aug 2016 16:15:35 +0000 (09:15 -0700)
When a text entry control (Entry, Editor, SearchBar, etc.) was being used in the header or
footer of a ListView on Android, a long click/press would cause a crash. This was occurring
in the HandleContextMode method because it expected to be a cell. Adding a null check and
breaking out of the method if the value from GetCellForPosition is null prevents this crash
from occurring.

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40858.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.Android/CellAdapter.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40858.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40858.cs
new file mode 100644 (file)
index 0000000..0bb024c
--- /dev/null
@@ -0,0 +1,55 @@
+using System;
+
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Bugzilla, 40858, "Long clicking a text entry in a ListView header/footer cause a crash", PlatformAffected.Android)]
+       public class Bugzilla40858 : TestContentPage
+       {
+               protected override void Init()
+               {
+                       Content = new StackLayout
+                       {
+                               Children =
+                               {
+                                       new ListView
+                                       {
+                                               Header = new Editor
+                                               {
+                                                       AutomationId = "Header",
+                                                       HeightRequest = 50,
+                                                       Text = "ListView Header -- Editor"
+                                               },
+                                               Footer = new Entry
+                                               {
+                                                       AutomationId = "Footer",
+                                                       HeightRequest = 50,
+                                                       Text = "ListView Footer -- Entry"
+                                               }
+                                       }
+                               }
+                       };
+               }
+
+#if UITEST
+
+#if __ANDROID__
+               [Test]
+               public void ListViewDoesNotCrashOnTextEntryHeaderOrFooterLongClick()
+               {
+                       RunningApp.TouchAndHold(x => x.Marked("Header"));
+                       RunningApp.TouchAndHold(x => x.Marked("Footer"));
+               }
+#endif
+
+#endif
+       }
+}
index 85c287f..6531b47 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40185.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40333.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31806.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40858.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40955.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40998.cs" />
index 4c8ac10..d79df76 100644 (file)
@@ -211,6 +211,9 @@ namespace Xamarin.Forms.Platform.Android
                {
                        Cell cell = GetCellForPosition(position);
 
+                       if (cell == null)
+                               return false;
+
                        if (_actionMode != null || _supportActionMode != null)
                        {
                                if (!cell.HasContextActions)