[Android] Prevent ObjectDisposed exceptions on Fast Renderers (#1033)
* Add repro for object disposed exception * [Android] Clear Renderer property from Element on dispose
This commit is contained in:
Родитель
b12f0b3bb7
Коммит
60db754eb7
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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.None, 0, "Object Disposed Exception in ScrollViewContainer", PlatformAffected.Android)]
|
||||
public class ScrollViewObjectDisposed : TestContentPage
|
||||
{
|
||||
const string Instructions = "Tap the button. If the app does not crash and the red label displays \"Success\", this test has passed.";
|
||||
const string Success = "Success";
|
||||
const string TestButtonId = "TestButtonId";
|
||||
|
||||
Label _status = new Label() { Text = "Test is running...", BackgroundColor = Color.Red, TextColor = Color.White };
|
||||
|
||||
ScrollView _scroll = new ScrollView();
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
_scroll.Content = _status;
|
||||
|
||||
InitTest();
|
||||
}
|
||||
|
||||
void InitTest()
|
||||
{
|
||||
|
||||
Button nextButton = new Button { Text = "Next", AutomationId = TestButtonId };
|
||||
nextButton.Clicked += NextButton_Clicked;
|
||||
|
||||
StackLayout stack = new StackLayout
|
||||
{
|
||||
Children = { new Label { Text = Instructions }, _scroll, nextButton }
|
||||
};
|
||||
|
||||
Content = stack;
|
||||
}
|
||||
|
||||
void NextButton_Clicked(object sender, EventArgs e)
|
||||
{
|
||||
_status.Text = "";
|
||||
|
||||
InitTest();
|
||||
|
||||
_status.Text = Success;
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
[Test]
|
||||
public void ScrollViewObjectDisposedTest ()
|
||||
{
|
||||
RunningApp.Tap(q => q.Marked(TestButtonId));
|
||||
RunningApp.WaitForElement(q => q.Marked(Success));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -309,6 +309,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla56896.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40161.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzila57749.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ScrollViewObjectDisposed.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
|
||||
|
|
|
@ -189,6 +189,9 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
|
|||
if (Element != null)
|
||||
{
|
||||
Element.PropertyChanged -= OnElementPropertyChanged;
|
||||
|
||||
if (Platform.GetRenderer(Element) == this)
|
||||
Element.ClearValue(Platform.RendererProperty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,6 +127,9 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
|
|||
if (Element != null)
|
||||
{
|
||||
Element.PropertyChanged -= OnElementPropertyChanged;
|
||||
|
||||
if (Platform.GetRenderer(Element) == this)
|
||||
Element.ClearValue(Platform.RendererProperty);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
|
|||
if (_element != null)
|
||||
{
|
||||
_element.PropertyChanged -= OnElementPropertyChanged;
|
||||
|
||||
if (Platform.GetRenderer(_element) == this)
|
||||
_element.ClearValue(Platform.RendererProperty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,6 +152,9 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
|
|||
if (Element != null)
|
||||
{
|
||||
Element.PropertyChanged -= OnElementPropertyChanged;
|
||||
|
||||
if (Platform.GetRenderer(Element) == this)
|
||||
Element.ClearValue(Platform.RendererProperty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче