Allow renderers to specify whether native controls should be eagerly disposed (#129)
This commit is contained in:
Родитель
3b589b7f2a
Коммит
462d132f6f
|
@ -57,5 +57,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
if (!handled)
|
||||
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
protected override bool ManageNativeControlLifetime => false;
|
||||
}
|
||||
}
|
|
@ -69,7 +69,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
{
|
||||
if (disposing && !_disposed)
|
||||
{
|
||||
if (Control != null)
|
||||
if (Control != null && ManageNativeControlLifetime)
|
||||
{
|
||||
Control.RemoveFromParent();
|
||||
Control.Dispose();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче