summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-04-24 00:13:27 -0600
committerRui Marinho <me@ruimarinho.net>2016-04-24 02:13:27 -0400
commit462d132f6f5f42871716cdbd455fba70e711541c (patch)
treec838afa67871ad12722e2c11328d444f66cb843f
parent3b589b7f2a02c7b2d70f78abb6b476c8cc9bf950 (diff)
downloadxamarin-forms-462d132f6f5f42871716cdbd455fba70e711541c.tar.gz
xamarin-forms-462d132f6f5f42871716cdbd455fba70e711541c.tar.bz2
xamarin-forms-462d132f6f5f42871716cdbd455fba70e711541c.zip
Allow renderers to specify whether native controls should be eagerly disposed (#129)
-rw-r--r--Xamarin.Forms.Platform.Android/NativeViewWrapperRenderer.cs2
-rw-r--r--Xamarin.Forms.Platform.Android/ViewRenderer.cs2
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementRenderer.cs17
-rw-r--r--Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs5
-rw-r--r--Xamarin.Forms.Platform.iOS/ViewRenderer.cs8
5 files changed, 28 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.Android/NativeViewWrapperRenderer.cs b/Xamarin.Forms.Platform.Android/NativeViewWrapperRenderer.cs
index 933f436f..49abc02a 100644
--- a/Xamarin.Forms.Platform.Android/NativeViewWrapperRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/NativeViewWrapperRenderer.cs
@@ -57,5 +57,7 @@ namespace Xamarin.Forms.Platform.Android
if (!handled)
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}
+
+ protected override bool ManageNativeControlLifetime => false;
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/ViewRenderer.cs b/Xamarin.Forms.Platform.Android/ViewRenderer.cs
index 0415ce93..143e6a7f 100644
--- a/Xamarin.Forms.Platform.Android/ViewRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/ViewRenderer.cs
@@ -69,7 +69,7 @@ namespace Xamarin.Forms.Platform.Android
{
if (disposing && !_disposed)
{
- if (Control != null)
+ if (Control != null && ManageNativeControlLifetime)
{
Control.RemoveFromParent();
Control.Dispose();
diff --git a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
index 5abb809f..d44714be 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
@@ -212,6 +212,12 @@ namespace Xamarin.Forms.Platform.Android
Performance.Stop();
}
+ /// <summary>
+ /// Determines whether the native control is disposed of when this renderer is disposed
+ /// Can be overridden in deriving classes
+ /// </summary>
+ protected virtual bool ManageNativeControlLifetime => true;
+
protected override void Dispose(bool disposing)
{
if ((_flags & VisualElementRendererFlags.Disposed) != 0)
@@ -244,11 +250,14 @@ namespace Xamarin.Forms.Platform.Android
_gestureListener = null;
}
- int count = ChildCount;
- for (var i = 0; i < count; i++)
+ if (ManageNativeControlLifetime)
{
- AView child = GetChildAt(i);
- child.Dispose();
+ int count = ChildCount;
+ for (var i = 0; i < count; i++)
+ {
+ AView child = GetChildAt(i);
+ child.Dispose();
+ }
}
RemoveAllViews();
diff --git a/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs b/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
index 3d3e6868..b21c8593 100644
--- a/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs
@@ -68,5 +68,10 @@ namespace Xamarin.Forms.Platform.iOS
if (e.OldElement == null)
SetNativeControl(Element.NativeView);
}
+
+ /// <summary>
+ /// The native control we're wrapping isn't ours to dispose of
+ /// </summary>
+ protected override bool ManageNativeControlLifetime => false;
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
index 5b3be1c3..1186fb4c 100644
--- a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
@@ -41,11 +41,17 @@ namespace Xamarin.Forms.Platform.iOS
return Control.SizeThatFits(size);
}
+ /// <summary>
+ /// Determines whether the native control is disposed of when this renderer is disposed
+ /// Can be overridden in deriving classes
+ /// </summary>
+ protected virtual bool ManageNativeControlLifetime => true;
+
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
- if (disposing && Control != null)
+ if (disposing && Control != null && ManageNativeControlLifetime)
{
Control.Dispose();
Control = null;