summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.Android
diff options
context:
space:
mode:
authorSamantha Houts <samhouts@users.noreply.github.com>2017-08-15 11:18:57 -0700
committerRui Marinho <me@ruimarinho.net>2017-08-15 19:18:57 +0100
commit2747cdc7a6b34dd336d1a017f4653a6b43c58699 (patch)
tree412a488c1de9434482cadbf5c17b2ad7dd1c0f61 /Xamarin.Forms.ControlGallery.Android
parent71f08bf48a91e3c7f107d5c34c4e3d9d9f5ccd30 (diff)
downloadxamarin-forms-2747cdc7a6b34dd336d1a017f4653a6b43c58699.tar.gz
xamarin-forms-2747cdc7a6b34dd336d1a017f4653a6b43c58699.tar.bz2
xamarin-forms-2747cdc7a6b34dd336d1a017f4653a6b43c58699.zip
[Android] Eagerly dispose children of ListViews to prevent ObjectDisposed exception (#1063)
* Add repro for 57910 * [Android] Dispose cells explicitly * [Android] Add default constructors to prevent crash on dispose * [Android] Don't try to dispose headers and footers
Diffstat (limited to 'Xamarin.Forms.ControlGallery.Android')
-rw-r--r--Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs55
1 files changed, 53 insertions, 2 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
index 33310332..e219b82c 100644
--- a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
+++ b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
@@ -31,6 +31,8 @@ using Xamarin.Forms.Controls.Issues;
[assembly: ExportRenderer(typeof(Bugzilla42000._42000NumericEntryNoDecimal), typeof(EntryRendererNoDecimal))]
[assembly: ExportRenderer(typeof(Bugzilla42000._42000NumericEntryNoNegative), typeof(EntryRendererNoNegative))]
//[assembly: ExportRenderer(typeof(AndroidHelpText.HintLabel), typeof(HintLabel))]
+[assembly: ExportRenderer(typeof(Bugzilla57910QuickCollectNavigationPage), typeof(QuickCollectNavigationPage))]
+
[assembly: ExportRenderer(typeof(Xamarin.Forms.Controls.Issues.NoFlashTestNavigationPage), typeof(Xamarin.Forms.ControlGallery.Android.NoFlashTestNavigationPage))]
@@ -523,7 +525,6 @@ namespace Xamarin.Forms.ControlGallery.Android
}
}
-
//public class HintLabel : Xamarin.Forms.Platform.Android.AppCompat.LabelRenderer
//{
// public HintLabel()
@@ -531,7 +532,7 @@ namespace Xamarin.Forms.ControlGallery.Android
// Hint = AndroidHelpText.HintLabel.Success;
// }
// }
-
+
public class NoFlashTestNavigationPage : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
{
protected override void SetupPageTransition(global::Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
@@ -539,5 +540,55 @@ namespace Xamarin.Forms.ControlGallery.Android
transaction.SetTransition((int)FragmentTransit.None);
}
}
+
+ public class QuickCollectNavigationPage : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
+ {
+ bool _disposed;
+ NavigationPage _page;
+
+ protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.NewElement == null)
+ {
+ if (e.OldElement != null)
+ {
+ ((IPageController)e.OldElement).InternalChildren.CollectionChanged -= OnInternalPageCollectionChanged;
+ }
+
+ return;
+ }
+
+ ((IPageController)e.NewElement).InternalChildren.CollectionChanged += OnInternalPageCollectionChanged;
+ }
+
+ private void OnInternalPageCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
+ {
+ if (e.OldItems != null)
+ {
+ // Force a collection on popped to simulate the problem.
+ GC.Collect();
+ }
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ _disposed = true;
+
+ if (disposing && _page != null)
+ {
+ _page.InternalChildren.CollectionChanged -= OnInternalPageCollectionChanged;
+ _page = null;
+ }
+
+ base.Dispose(disposing);
+ }
+ }
}