summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-01-24 11:48:36 (GMT)
committerSamantha Houts <samantha.houts@xamarin.com>2017-02-24 18:09:37 (GMT)
commitfa12ae1bae967b75f49d0e2643524c45c6a788ed (patch)
treec1f77a22e354ca7ae1277123953c37914a4eda87
parent5775743a297272cf58902f036f56c08dba07b517 (diff)
downloadxamarin-forms-release-2.3.3-hf1.zip
xamarin-forms-release-2.3.3-hf1.tar.gz
xamarin-forms-release-2.3.3-hf1.tar.bz2
Add check for disposed gesture detector on VisualElementRenderer (#706)release-2.3.3-hf1
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45330.cs119
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems3
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementRenderer.cs6
3 files changed, 127 insertions, 1 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45330.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45330.cs
new file mode 100644
index 0000000..d3a05fd
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45330.cs
@@ -0,0 +1,119 @@
+´╗┐using System;
+using System.Collections.ObjectModel;
+using System.Linq;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 45330, "System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Views.GestureDetector'.", PlatformAffected.Android)]
+ public class Bugzilla45330 : TestContentPage
+ {
+ ObservableCollection<_45330Notification> _feed;
+
+ [Preserve(AllMembers = true)]
+ public class _45330Dto
+ {
+ public _45330Dto()
+ {
+ Notifications = new ObservableCollection<_45330Notification>();
+ }
+
+ public ObservableCollection<_45330Notification> Notifications { get; set; }
+ }
+
+ [Preserve(AllMembers = true)]
+ public class _45330Notification
+ {
+ public string UniqueId { get; set; }
+ public DateTime DisplayDate { get; set; }
+ }
+
+ [Preserve(AllMembers = true)]
+ public class _45330ListCell : ViewCell
+ {
+ protected override void OnBindingContextChanged()
+ {
+ base.OnBindingContextChanged();
+
+ var item = BindingContext as _45330Notification;
+ if (item == null) return;
+
+ View = new StackLayout()
+ {
+ BackgroundColor = Color.Transparent,
+ Padding = new Thickness(0, 1, 0, 1),
+ Children = { new Label { Text = item.UniqueId } }
+ };
+ }
+ }
+
+ public ObservableCollection<_45330Notification> Feed
+ {
+ get { return _feed; }
+ set
+ {
+ _feed = value;
+ OnPropertyChanged();
+ }
+ }
+
+ protected override void Init()
+ {
+ BindingContext = this;
+ Feed = MakeNotifications();
+
+ var listview = new ListView();
+ listview.SetBinding(ListView.ItemsSourceProperty, "Feed");
+ listview.ItemTemplate = new DataTemplate(typeof(_45330ListCell));
+ listview.IsPullToRefreshEnabled = true;
+ listview.RefreshCommand = new Command(() =>
+ {
+ listview.IsRefreshing = false;
+ Feed = MakeNotifications();
+ });
+
+ listview.ItemAppearing += (sender, e) =>
+ {
+ var currentItem = e.Item as _45330Notification;
+ if (currentItem == null) return;
+ var item = Feed.Last();
+ if (currentItem.UniqueId == item.UniqueId)
+ {
+ Feed = MakeNotifications();
+ }
+ };
+
+ var layout = new StackLayout();
+
+ var instructions = new Label { Text = @"The bug can be intermittently reproduced by pulling the list down to refresh it and immediately tapping one of the cells.
+Leaving this test page in for reference purposes, and possibly as a base for a future UI test if we get a way to accurately/consistently simulate the events which cause the crash."};
+
+ layout.Children.Add(instructions);
+ layout.Children.Add(listview);
+
+ Content = layout;
+ }
+
+ ObservableCollection<_45330Notification> MakeNotifications()
+ {
+ var list = new _45330Dto();
+ for (int i = 0; i < 1000; i++)
+ {
+ list.Notifications.Add(new _45330Notification()
+ {
+ UniqueId = i.ToString(),
+ DisplayDate = DateTime.UtcNow
+ });
+ }
+ return list.Notifications;
+ }
+
+ protected override void OnAppearing()
+ {
+ base.OnAppearing();
+ Feed = MakeNotifications();
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 5979f04..368cbda 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -126,6 +126,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44166.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44338.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla45330.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla47971.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
@@ -584,4 +585,4 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
-</Project>
+</Project> \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
index 404dd23..0898018 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
@@ -101,6 +101,12 @@ namespace Xamarin.Forms.Platform.Android
_gestureListener?.OnTouchEvent(e);
+ if (_gestureDetector.IsValueCreated && _gestureDetector.Value.Handle == IntPtr.Zero)
+ {
+ // This gesture detector has already been disposed, probably because it's on a cell which is going away
+ return handled;
+ }
+
return _gestureDetector.Value.OnTouchEvent(e) || handled;
}